Class: ShadowsocksRuby::Connections::ServerConnection

Inherits:
Connection
  • Object
show all
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.

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, #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

Parameters:

Options Hash (params):

  • :timeout (Integer)

    set comm_inactivity_timeout

Options Hash (backend_params):

  • :timeout (Integer)

    set comm_inactivity_timeout



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_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:



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

def packet_protocol
  @packet_protocol
end

#paramsHash (readonly)

Params

Returns:

  • (Hash)


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

Parameters:

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

Returns:

  • (Connection_Object)


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.message + " when connect to #{host}:#{port}"
end

#post_initObject



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

def post_init
  App.instance.incr
  super()
end

#unbindObject



63
64
65
66
# File 'lib/shadowsocks_ruby/connections/server_connection.rb', line 63

def unbind
  App.instance.decr
  super()
end