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

Instance Method Summary collapse

Instance Attribute Details

#packet_protocolShadowsocksRuby::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

Returns:

  • (ShadowsocksRuby::Protocols::SomePacketProtocol)

See Also:



19
20
21
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 19

def packet_protocol
  @packet_protocol
end

#paramsHash (readonly)

Params

Returns:

  • (Hash)


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

Parameters:

  • host (String)
  • port (Integer)
  • backend_klass (Class)

Returns:

  • (Connection_Object)


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.message + " 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

Parameters:

Returns:

  • (Connection_Object)


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_initObject



43
44
45
46
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 43

def post_init
  logger.info {"Accepted #{peer}"}
  super()
end