Class: RTunnel::Client
- Inherits:
-
Object
- Object
- RTunnel::Client
- Defined in:
- lib/rtunnel/client.rb
Defined Under Namespace
Classes: ServerConnection, TunnelConnection
Constant Summary
Constants included from RTunnel
DEFAULT_CONTROL_PORT, KEEP_ALIVE_INTERVAL, TUNNEL_TIMEOUT
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#control_address ⇒ Object
readonly
Returns the value of attribute control_address.
-
#control_host ⇒ Object
readonly
Returns the value of attribute control_host.
-
#control_port ⇒ Object
readonly
Returns the value of attribute control_port.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#remote_listen_address ⇒ Object
readonly
Returns the value of attribute remote_listen_address.
-
#server_connection ⇒ Object
readonly
Returns the value of attribute server_connection.
-
#tunnel_timeout ⇒ Object
readonly
Returns the value of attribute tunnel_timeout.
-
#tunnel_to_address ⇒ Object
readonly
Returns the value of attribute tunnel_to_address.
Class Method Summary collapse
- .extract_control_address(address) ⇒ Object
- .extract_private_key(key_file) ⇒ Object
- .extract_remote_listen_address(address) ⇒ Object
- .extract_tunnel_timeout(timeout) ⇒ Object
- .extract_tunnel_to_address(address) ⇒ Object
Instance Method Summary collapse
- #connect_to_server ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#process_options(options) ⇒ Object
option processing.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Logging
Methods included from RTunnel
resolve_address, run_client, run_server
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 |
# File 'lib/rtunnel/client.rb', line 17 def initialize( = {}) @connections = {} @server_connection = nil end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
15 16 17 |
# File 'lib/rtunnel/client.rb', line 15 def connections @connections end |
#control_address ⇒ Object (readonly)
Returns the value of attribute control_address.
11 12 13 |
# File 'lib/rtunnel/client.rb', line 11 def control_address @control_address end |
#control_host ⇒ Object (readonly)
Returns the value of attribute control_host.
11 12 13 |
# File 'lib/rtunnel/client.rb', line 11 def control_host @control_host end |
#control_port ⇒ Object (readonly)
Returns the value of attribute control_port.
11 12 13 |
# File 'lib/rtunnel/client.rb', line 11 def control_port @control_port end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/rtunnel/client.rb', line 14 def logger @logger end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
13 14 15 |
# File 'lib/rtunnel/client.rb', line 13 def private_key @private_key end |
#remote_listen_address ⇒ Object (readonly)
Returns the value of attribute remote_listen_address.
12 13 14 |
# File 'lib/rtunnel/client.rb', line 12 def remote_listen_address @remote_listen_address end |
#server_connection ⇒ Object (readonly)
Returns the value of attribute server_connection.
15 16 17 |
# File 'lib/rtunnel/client.rb', line 15 def server_connection @server_connection end |
#tunnel_timeout ⇒ Object (readonly)
Returns the value of attribute tunnel_timeout.
13 14 15 |
# File 'lib/rtunnel/client.rb', line 13 def tunnel_timeout @tunnel_timeout end |
#tunnel_to_address ⇒ Object (readonly)
Returns the value of attribute tunnel_to_address.
12 13 14 |
# File 'lib/rtunnel/client.rb', line 12 def tunnel_to_address @tunnel_to_address end |
Class Method Details
.extract_control_address(address) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/rtunnel/client.rb', line 58 def self.extract_control_address(address) unless SocketFactory.port_from_address address address = "#{address}:#{RTunnel::DEFAULT_CONTROL_PORT}" end RTunnel.resolve_address address end |
.extract_private_key(key_file) ⇒ Object
81 82 83 |
# File 'lib/rtunnel/client.rb', line 81 def self.extract_private_key(key_file) key_file and Crypto.read_private_key key_file end |
.extract_remote_listen_address(address) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/rtunnel/client.rb', line 65 def self.extract_remote_listen_address(address) unless SocketFactory.port_from_address address address = "0.0.0.0:#{address}" end RTunnel.resolve_address address end |
.extract_tunnel_timeout(timeout) ⇒ Object
77 78 79 |
# File 'lib/rtunnel/client.rb', line 77 def self.extract_tunnel_timeout(timeout) timeout || RTunnel::TUNNEL_TIMEOUT end |
.extract_tunnel_to_address(address) ⇒ Object
72 73 74 75 |
# File 'lib/rtunnel/client.rb', line 72 def self.extract_tunnel_to_address(address) address = "localhost:#{address}" if address =~ /^\d+$/ RTunnel.resolve_address address end |
Instance Method Details
#connect_to_server ⇒ Object
31 32 33 34 35 |
# File 'lib/rtunnel/client.rb', line 31 def connect_to_server D "Connecting to #{@control_host} port #{@control_port}" @server_connection = EventMachine.bind_connect @control_bind_host, nil, @control_host, @control_port, Client::ServerConnection, self end |
#process_options(options) ⇒ Object
option processing
48 49 50 51 52 53 54 55 56 |
# File 'lib/rtunnel/client.rb', line 48 def () [:control_address, :remote_listen_address, :tunnel_to_address, :tunnel_timeout, :private_key].each do |opt| instance_variable_set "@#{opt}".to_sym, RTunnel::Client.send("extract_#{opt}".to_sym, [opt]) end init_log :level => [:log_level] end |
#start ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rtunnel/client.rb', line 23 def start return if @server_connection @control_host = SocketFactory.host_from_address @control_address @control_bind_host = SocketFactory.bind_host_from_address @control_address @control_port = SocketFactory.port_from_address @control_address connect_to_server end |
#stop ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rtunnel/client.rb', line 37 def stop @connections.each { |connection| connection.close_connection_after_writing } return unless @server_connection @server_connection.close_connection_after_writing @server_connection.disable_tunnel_timeouts @server_connection = nil end |