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
-
.resolve_address(address, timeout_sec = 5) ⇒ Object
Resolve the given address to an IP.
- .run_client ⇒ Object
- .run_server ⇒ Object
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_client ⇒ Object
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 = {} (opts = OptionParser.new do |o| o.on("-c", "--control-address ADDRESS") do |a| [:control_address] = a end o.on("-f", "--remote-listen-port ADDRESS") do |a| [:remote_listen_address] = a end o.on("-t", "--tunnel-to ADDRESS") do |a| [:tunnel_to_address] = a end o.on("-k", "--private-key KEYFILE") do |f| [:private_key] = f end o.on("-l", "--log-level LEVEL") do |l| [:log_level] = l end o.on("-o", "--timeout TIMEOUT_IN_SECONDS") do |t| [: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| [key] } EventMachine::run do RTunnel::Client.new().start end end |
.run_server ⇒ Object
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 = {} (opts = OptionParser.new do |o| o.on("-c", "--control ADDRESS") { |a| [:control_address] = a } o.on("-a", "--authorized-keys KEYSFILE") do |f| [:authorized_keys] = f end o.on("-l", "--log-level LEVEL") { |l| [:log_level] = l } o.on("-k", "--keep-alive KEEP_ALIVE_INTERVAL") do |t| [:keep_alive_interval] = t.to_f end o.on("-p", "--lowest-listen-port PORT") do |p| [:lowest_listen_port] = p.to_i end o.on("-P", "--highest-listen-port PORT") do |p| [:highest_listen_port] = p.to_i end end).parse! rescue (puts opts; return) EventMachine::run do RTunnel::Server.new().start end end |