Class: Net::SSH::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/localtunnel/net_ssh_gateway_patch.rb

Overview

Instance Method Summary collapse

Instance Method Details

#close_remote(port, host = "127.0.0.1") ⇒ Object

Cancels port-forwarding over an open port that was previously opened via #open_remote.



32
33
34
35
36
37
38
# File 'lib/localtunnel/net_ssh_gateway_patch.rb', line 32

def close_remote(port, host = "127.0.0.1")
  ensure_open!

  @session_mutex.synchronize do
    @session.forward.cancel_remote(port, host)
  end
end

#open_remote(port, host, remote_port, remote_host = "127.0.0.1") ⇒ Object

Opens a SSH tunnel from a port on a remote host to a given host and port on the local side (equivalent to openssh -R parameter)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/localtunnel/net_ssh_gateway_patch.rb', line 10

def open_remote(port, host, remote_port, remote_host = "127.0.0.1")
  ensure_open!

  @session_mutex.synchronize do
    @session.forward.remote(port, host, remote_port, remote_host)
  end

  if block_given?
    begin
      yield [remote_port, remote_host]
    ensure
      close_remote(remote_port, remote_host)
    end
  else
    return [remote_port, remote_host]
  end
rescue Errno::EADDRINUSE
  retry
end