Class: TunnelClient::TunnelConnection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/lds-cf-plugin/tunnel/tunnelclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(listener) ⇒ TunnelConnection

Returns a new instance of TunnelConnection.



46
47
48
# File 'lib/lds-cf-plugin/tunnel/tunnelclient.rb', line 46

def initialize(listener)
  @listener = listener
end

Instance Method Details

#post_initObject



50
51
52
53
54
55
56
57
# File 'lib/lds-cf-plugin/tunnel/tunnelclient.rb', line 50

def post_init
  puts "Connection opened"
  if @listener.use_tls
    start_tls
  else
    send_initialization
  end
end

#receive_data(data) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lds-cf-plugin/tunnel/tunnelclient.rb', line 63

def receive_data(data)
  (@buf ||= '') << data

  while @buf.bytesize >= FRAME_HEADER_LENGTH
    frame_type, frame_length = @buf.unpack("A1N")
    if @buf.bytesize >= FRAME_HEADER_LENGTH + frame_length
      @buf.slice!(0,FRAME_HEADER_LENGTH)
      frame_body = @buf.slice!(0,frame_length)
      case frame_type
        when 'E', 'e'
          # Error
          close_connection
          raise frame_body
        when 'R', 'r'
          @listener.resume
          proxy_incoming_to @listener
          @listener.proxy_incoming_to self
        else
          close_connection
          raise "Received invalid frame type '#{frame_type}' from Tunnel Server"
      end
    end
  end
end

#ssl_handshake_completedObject



59
60
61
# File 'lib/lds-cf-plugin/tunnel/tunnelclient.rb', line 59

def ssl_handshake_completed
  send_initialization
end

#unbindObject



88
89
90
# File 'lib/lds-cf-plugin/tunnel/tunnelclient.rb', line 88

def unbind
  @listener.close_connection_after_writing
end