Module: RTunnel

Included in:
Client, Client::ServerConnection, Client::TunnelConnection, Server, Server::ControlConnection, Server::TunnelConnection
Defined in:
lib/rtunnel.rb,
lib/rtunnel/core.rb,
lib/rtunnel/core.rb,
lib/rtunnel/rtunnel_client_cmd.rb,
lib/rtunnel/rtunnel_server_cmd.rb

Defined Under Namespace

Modules: CommandProcessor, CommandProtocol, ConnectionId, Crypto, FrameProtocol, IOExtensions, Logging, SocketFactory Classes: AbortProgramException, Client, CloseConnectionCommand, Command, ConnectionCommand, CreateConnectionCommand, GenerateSessionKeyCommand, KeepAliveCommand, LeakTracker, RemoteListenCommand, SendDataCommand, Server, SetSessionKeyCommand, TruncatedDataError

Constant Summary collapse

DEFAULT_CONTROL_PORT =
19050
TUNNEL_TIMEOUT =
10
KEEP_ALIVE_INTERVAL =
2

Class Method Summary collapse

Class Method Details

.resolve_address(address, timeout_sec = 5) ⇒ Object

Resolve the given address to an IP. The address can have the following formats: host; host:port; ip; ip:port;



51
52
53
54
55
56
57
# File 'lib/rtunnel/core.rb', line 51

def self.resolve_address(address, timeout_sec = 5)
  host, rest = address.split(':', 2)
  ip = timeout(timeout_sec) { Resolv.getaddress(host) }
  rest ? "#{ip}:#{rest}" : ip
rescue Exception
  raise AbortProgramException, "Error resolving #{host}" 
end

.run_clientObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rtunnel/rtunnel_client_cmd.rb', line 8

def self.run_client
  options = {}
  
  (opts = OptionParser.new do |o|
    o.on("-c", "--control-address ADDRESS") do |a|
      options[:control_address] = a
    end
    o.on("-f", "--remote-listen-port ADDRESS") do |a|
      options[:remote_listen_address] = a
    end
    o.on("-t", "--tunnel-to ADDRESS") do |a|
      options[:tunnel_to_address] = a
    end
    o.on("-k", "--private-key KEYFILE") do |f|
      options[:private_key] = f
    end
    o.on("-l", "--log-level LEVEL") do |l|
      options[:log_level] = l
    end
    o.on("-o", "--timeout TIMEOUT_IN_SECONDS") do |t|
      options[:tunnel_timeout] = t.to_f
    end
  end).parse!  rescue (puts opts; return)
  
  mandatory_keys = [:control_address, :remote_listen_address,
                    :tunnel_to_address]
                    
  (puts opts; return) unless mandatory_keys.all? { |key| options[key] }
  
  EventMachine::run do
    RTunnel::Client.new(options).start
  end
end

.run_serverObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rtunnel/rtunnel_server_cmd.rb', line 8

def self.run_server    
  options = {}
  
  (opts = OptionParser.new do |o|
    o.on("-c", "--control ADDRESS") { |a| options[:control_address] = a }
    o.on("-a", "--authorized-keys KEYSFILE") do |f|
      options[:authorized_keys] = f
    end
    o.on("-l", "--log-level LEVEL") { |l| options[:log_level] = l }
    o.on("-k", "--keep-alive KEEP_ALIVE_INTERVAL") do |t|
      options[:keep_alive_interval] = t.to_f
    end
    o.on("-p", "--lowest-listen-port PORT") do |p|
      options[:lowest_listen_port] = p.to_i
    end
    o.on("-P", "--highest-listen-port PORT") do |p|
      options[:highest_listen_port] = p.to_i
    end
  end).parse!  rescue (puts opts; return)

  EventMachine::run do
    RTunnel::Server.new(options).start
  end
end