Class: ShadowsocksRuby::Connections::BackendConnection
- Inherits:
-
Connection
- Object
- EventMachine::Connection
- Connection
- ShadowsocksRuby::Connections::BackendConnection
- 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.
Direct Known Subclasses
TCP::DestinationConnection, TCP::RemoteServerConnection, UDP::DestinationConnection, UDP::RemoteServerConnection
Constant Summary
Constants inherited from Connection
Instance Attribute Summary collapse
-
#packet_protocol ⇒ ShadowsocksRuby::Protocols::SomePacketProtocol
A Strategy Pattern for replacing protocol algorithm.
-
#params ⇒ Hash
readonly
Params.
Attributes inherited from Connection
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(protocol_stack, params) ⇒ Connection_Object
constructor
If clild class override initialize, make sure to call super.
-
#send_data(data) ⇒ Object
Buffer data until the connection to the backend server is established and is ready for use.
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
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_protocol ⇒ ShadowsocksRuby::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
17 18 19 |
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 17 def packet_protocol @packet_protocol end |
#params ⇒ Hash (readonly)
Params
20 21 22 |
# File 'lib/shadowsocks_ruby/connections/backend_connection.rb', line 20 def params @params end |
Instance Method Details
#connection_completed ⇒ Object
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 |