Class: ShadowsocksRuby::Connections::TCP::ClientConnection

Inherits:
ServerConnection show all
Defined in:
lib/shadowsocks_ruby/connections/tcp/client_connection.rb

Overview

A ClientConnection's job is relay data from client to remoteserver.

Constant Summary

Constants inherited from Connection

Connection::PressureLevel

Instance Attribute Summary

Attributes inherited from ServerConnection

#packet_protocol, #params

Attributes inherited from Connection

#logger, #plexer

Instance Method Summary collapse

Methods inherited from ServerConnection

#create_plexer, #post_init, #unbind

Methods inherited from Connection

#async_recv, #async_recv_until, #peer, #send_data, #unbind

Constructor Details

#initialize(protocol_stack, params, backend_protocol_stack, backend_params) ⇒ Connection_Object

If clild class override initialize, make sure to call super

Options Hash (params):

  • :timeout (Integer)

    set comm_inactivity_timeout

  • :host (String)

    shadowsocks server address, required

  • :port (Integer)

    shadowsocks server port, required

Options Hash (backend_params):

  • :timeout (Integer)

    set comm_inactivity_timeout


10
11
12
# File 'lib/shadowsocks_ruby/connections/tcp/client_connection.rb', line 10

def initialize protocol_stack, params, backend_protocol_stack, backend_params
  super
end

Instance Method Details

#process_first_packetObject Also known as: process_hook


14
15
16
17
18
19
20
21
22
23
# File 'lib/shadowsocks_ruby/connections/tcp/client_connection.rb', line 14

def process_first_packet
  address_bin = packet_protocol.tcp_receive_from_client(-1)
  host, port = Util::parse_address_bin(address_bin)
  logger.info('connection') { "connecting #{host}:#{port} from #{peer}" }
  create_plexer(@params[:host], @params[:port], RemoteServerConnection)
  plexer.packet_protocol.tcp_send_to_remoteserver address_bin
  class << self
    alias process_hook process_other_packet
  end
end

#process_other_packetObject


28
29
30
31
# File 'lib/shadowsocks_ruby/connections/tcp/client_connection.rb', line 28

def process_other_packet
  data = packet_protocol.tcp_receive_from_client(-1)
  plexer.packet_protocol.tcp_send_to_remoteserver(data)
end