Module: ShadowsocksRuby::Connections::ServerConnection
- Included in:
- TCP::ClientConnection, TCP::LocalBackendConnection, UDP::ClientConnection, UDP::LocalBackendConnection
- Defined in:
- lib/shadowsocks_ruby/connections/server_connection.rb
Overview
Mixed-in code to provide functionality to a ServerConnection ,whose peer is a downstream peer, like a Client or a LocalBackend.
Instance Attribute Summary collapse
-
#packet_protocol ⇒ ShadowsocksRuby::Protocols::SomePacketProtocol
Packet Protocol.
-
#params ⇒ Hash
readonly
Params.
Instance Method Summary collapse
-
#create_plexer(host, port, backend_klass) ⇒ Connection_Object
Create a plexer – a backend connection.
-
#initialize(protocol_stack, params, backend_protocol_stack, backend_params) ⇒ Connection_Object
If clild class override initialize, make sure to call super.
- #post_init ⇒ Object
Instance Attribute Details
#packet_protocol ⇒ ShadowsocksRuby::Protocols::SomePacketProtocol
Packet Protocol
A Strategy Pattern for replacing protocol algorithm
the first read from ShadowsocksRuby::Connections::ServerConnection‘s #packet_protocol is an address_bin, other read from #packet_protocol is just data
all send to #packet_protocol should be just data
19 20 21 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 19 def packet_protocol @packet_protocol end |
#params ⇒ Hash (readonly)
Params
23 24 25 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 23 def params @params end |
Instance Method Details
#create_plexer(host, port, backend_klass) ⇒ Connection_Object
Create a plexer – a backend connection
53 54 55 56 57 58 59 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 53 def create_plexer(host, port, backend_klass) @plexer = EventMachine.connect host, port, backend_klass, @backend_protocol_stack, @backend_params @plexer.plexer = self @plexer rescue EventMachine::ConnectionError => e raise ConnectionError, e. + " when connect to #{host}:#{port}" end |
#initialize(protocol_stack, params, backend_protocol_stack, backend_params) ⇒ Connection_Object
If clild class override initialize, make sure to call super
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 32 def initialize protocol_stack, params, backend_protocol_stack, backend_params super() @packet_protocol = protocol_stack.build!(self) @params = params @backend_protocol_stack = backend_protocol_stack @backend_params = backend_params end |
#post_init ⇒ Object
43 44 45 46 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 43 def post_init logger.info {"Accepted #{peer}"} super() end |