Class: NetD::RemotePortForward

Inherits:
NetworkOperation show all
Defined in:
lib/netd_core/netop.rb

Overview

encapsulates a remote port_forward

Instance Attribute Summary

Attributes inherited from NetworkOperation

#request, #thread

Instance Method Summary collapse

Methods inherited from NetworkOperation

#close, #to_s

Constructor Details

#initialize(request) ⇒ RemotePortForward

Returns a new instance of RemotePortForward.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/netd_core/netop.rb', line 43

def initialize(request)
  super
  @request = request
  @thread = Thread.new(request) do |req|
    stop = false
    Net::SSH.start(req[:host], nil, keys_only: true) do |ssh|
      ssh.forward.remote(req[:bind_port], req[:bind_addr], req[:local_port], req[:local_addr])
      ssh.loop(0.1) { true unless stop }
      ssh.forward.cancel_remote(req[:bind_port], req[:bind_addr])
    end
  end
end