Class: ShadowsocksRuby::Connections::ServerConnection
- Inherits:
-
Connection
- Object
- EventMachine::Connection
- Connection
- ShadowsocksRuby::Connections::ServerConnection
- Defined in:
- lib/shadowsocks_ruby/connections/server_connection.rb
Overview
A ServerConnection is a connection whose peer is a downstream peer, like a Client or a LocalBackend.
Direct Known Subclasses
TCP::ClientConnection, TCP::LocalBackendConnection, UDP::ClientConnection, UDP::LocalBackendConnection
Constant Summary
Constants inherited from Connection
Instance Attribute Summary collapse
-
#packet_protocol ⇒ ShadowsocksRuby::Protocols::SomePacketProtocol
Packet Protocol.
-
#params ⇒ Hash
readonly
Params.
Attributes inherited from Connection
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
constructor
If clild class override initialize, make sure to call super.
- #post_init ⇒ Object
- #unbind ⇒ Object
Methods inherited from Connection
#async_recv, #async_recv_until, #peer, #send_data
Constructor Details
#initialize(protocol_stack, params, backend_protocol_stack, backend_params) ⇒ Connection_Object
If clild class override initialize, make sure to call super
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 33 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 self.comm_inactivity_timeout = @params[:timeout] if @params[:timeout] && @params[:timeout] != 0 end |
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
18 19 20 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 18 def packet_protocol @packet_protocol end |
#params ⇒ Hash (readonly)
Params
22 23 24 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 22 def params @params end |
Instance Method Details
#create_plexer(host, port, backend_klass) ⇒ Connection_Object
Create a plexer – a backend connection
55 56 57 58 59 60 61 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 55 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 |
#post_init ⇒ Object
45 46 47 48 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 45 def post_init App.instance.incr super() end |
#unbind ⇒ Object
63 64 65 66 |
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 63 def unbind App.instance.decr super() end |