Class: ShadowsocksRuby::Connections::BackendConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/shadowsocks_ruby/connections/backend_connection.rb

Overview

A BackendConnection is a connection whose peer is a upstream peer, like a Destinatiion or a RemoteServer.

Constant Summary

Constants inherited from Connection

Connection::PressureLevel

Instance Attribute Summary collapse

Attributes inherited from Connection

#logger, #plexer

Instance Method Summary collapse

Methods inherited from Connection

#async_recv, #async_recv_until, #peer, #unbind

Constructor Details

#initialize(protocol_stack, params) ⇒ Connection_Object

If clild class override initialize, make sure to call super

Parameters:

Options Hash (params):

  • :timeout (Integer)

    set comm_inactivity_timeout


28
29
30
31
32
33
34
35
36
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 28

def initialize protocol_stack, params
  super()

  @packet_protocol = protocol_stack.build!(self)

  @params = params
  self.comm_inactivity_timeout = @params[:timeout] if @params[:timeout] && @params[:timeout] != 0
  @connected = EM::DefaultDeferrable.new
end

Instance Attribute Details

#packet_protocolShadowsocksRuby::Protocols::SomePacketProtocol

A Strategy Pattern for replacing protocol algorithm

All read packet returned from a #packet_protocol (TCP::RemoteServerConnection and TCP::DestinationConnection etc. ) is just data.

The first packet send to #packet_protocol must be address_bin for a TCP::RemoteServerConnection and data for a TCP::DestinationConnection, The second and other send to #packet_protocol must be data

Returns:

  • (ShadowsocksRuby::Protocols::SomePacketProtocol)

See Also:


17
18
19
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 17

def packet_protocol
  @packet_protocol
end

#paramsHash (readonly)

Params

Returns:

  • (Hash)

20
21
22
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 20

def params
  @params
end

Instance Method Details

#connection_completedObject


39
40
41
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 39

def connection_completed
  @connected.succeed
end

#send_data(data) ⇒ Object

Buffer data until the connection to the backend server is established and is ready for use


45
46
47
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 45

def send_data data
  @connected.callback { super data }
end