Module: NetD

Defined in:
lib/netd_core/netop.rb,
lib/netd_core/request.rb

Overview

parse requests from a pipe delimited line

Defined Under Namespace

Classes: LocalPortForward, NetworkOperation, OperationRequest, RemotePortForward

Instance Method Summary collapse

Instance Method Details

#testObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/netd_core/netop.rb', line 87

def test
  puts 'testing forwards'
  # setup the ssh-agent connector
  Net::SSH::Authentication::Agent.connect(nil, nil, '/home/shellspawn/.1password/agent.sock')
  # create the port forwards
  lpfwd, rpfwd = test_setup_port_forwards
  puts lpfwd, rpfwd
  # send some data through the tunnel
  test_forward
  # close both forwards
  [lpfwd, rpfwd].map(&:close)
  puts 'all cleaned up'
end

#test_forwardObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/netd_core/netop.rb', line 57

def test_forward
  data = 'HELLO'
  # create the server
  TCPServer.open('127.0.0.1', 2224) do |svr|
    # create the client
    TCPSocket.open('127.0.0.1', 2222) do |c|
      # accept the connection
      s = svr.accept
      # send a hello
      c.puts data
      # validate the data sent through
      raise 'Forward test failed!!!' unless s.readline(chomp: true) == data
    end
  end
  sleep(1) # let the threads complete
end

#test_setup_port_forwardsObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/netd_core/netop.rb', line 74

def test_setup_port_forwards
  lpfwd = LocalPortForward.new({  'request': 'lpfwd',
                                  'host': 'localhost',
                                  'bind_port': 2222, 'bind_addr': 'localhost',
                                  'remote_port': 2223, 'remote_addr': 'localhost' })
  rpfwd = RemotePortForward.new({ 'request': 'rpfwd',
                                  'host': 'localhost',
                                  'bind_port': 2224, 'bind_addr': 'localhost',
                                  'local_port': 2223, 'local_addr': 'localhost' })
  sleep(1) # let the threads finish setting up
  [lpfwd, rpfwd]
end