Class: ReverseTunnel::Client::LocalConnection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/reverse-tunnel/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tunnel, session_id) ⇒ LocalConnection

Returns a new instance of LocalConnection.



235
236
237
238
# File 'lib/reverse-tunnel/client.rb', line 235

def initialize(tunnel, session_id)
  @tunnel, @session_id = tunnel, session_id
  @received_size = @send_size = 0
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



233
234
235
# File 'lib/reverse-tunnel/client.rb', line 233

def created_at
  @created_at
end

#received_sizeObject (readonly)

Returns the value of attribute received_size.



233
234
235
# File 'lib/reverse-tunnel/client.rb', line 233

def received_size
  @received_size
end

#send_sizeObject (readonly)

Returns the value of attribute send_size.



233
234
235
# File 'lib/reverse-tunnel/client.rb', line 233

def send_size
  @send_size
end

#session_idObject

Returns the value of attribute session_id.



231
232
233
# File 'lib/reverse-tunnel/client.rb', line 231

def session_id
  @session_id
end

#tunnelObject

Returns the value of attribute tunnel.



231
232
233
# File 'lib/reverse-tunnel/client.rb', line 231

def tunnel
  @tunnel
end

Instance Method Details

#as_jsonObject



263
264
265
# File 'lib/reverse-tunnel/client.rb', line 263

def as_json
  { :session_id => session_id, :created_at => created_at, :received_size => received_size, :send_size => send_size }
end

#post_initObject



240
241
242
243
244
# File 'lib/reverse-tunnel/client.rb', line 240

def post_init
  ReverseTunnel.logger.debug { "New local connection" }
  @created_at = Time.now
  tunnel.local_connections << self
end

#receive_data(data) ⇒ Object



246
247
248
249
250
# File 'lib/reverse-tunnel/client.rb', line 246

def receive_data(data)
  ReverseTunnel.logger.debug { "Received data in local connection #{session_id}" }
  @received_size += data.size
  tunnel.send_data session_id, data
end

#send_data(data) ⇒ Object



257
258
259
260
261
# File 'lib/reverse-tunnel/client.rb', line 257

def send_data(data)
  ReverseTunnel.logger.debug { "Send data '#{data.unpack('H*').join}'" }
  @send_size += data.size
  super
end

#unbindObject



252
253
254
255
# File 'lib/reverse-tunnel/client.rb', line 252

def unbind
  ReverseTunnel.logger.debug { "Close local connection #{session_id}" }
  tunnel.local_connections.delete self
end