Class: NetD::LocalPortForward

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

Overview

encapsulates a local 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) ⇒ LocalPortForward

Returns a new instance of LocalPortForward.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/netd_core/netop.rb', line 27

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.local(req[:bind_addr], req[:bind_port], req[:remote_addr], req[:remote_port])
      ssh.loop(0.1) { true unless stop }
      ssh.forward.cancel_local(req[:bind_port], req[:bind_addr])
    end
  end
end