Class: ShadowsocksRuby::Connections::UDP::ClientConnection

Inherits:
ServerConnection show all
Defined in:
lib/shadowsocks_ruby/connections/udp/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

Parameters:

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



9
10
11
# File 'lib/shadowsocks_ruby/connections/udp/client_connection.rb', line 9

def initialize protocol_stack, params, backend_protocol_stack, backend_params
  super
end

Instance Method Details

#process_first_packetObject Also known as: process_hook



13
14
15
16
17
18
19
20
# File 'lib/shadowsocks_ruby/connections/udp/client_connection.rb', line 13

def process_first_packet
  address_bin = packet_protocol.udp_receive_from_client(-1)
  create_plexer(@params[:host], @params[:port], RemoteServerConnection)
  plexer.packet_protocol.udp_send_to_remoteserver address_bin
  class << self
    alias process_hook process_other_packet
  end
end

#process_other_packetObject



25
26
27
28
# File 'lib/shadowsocks_ruby/connections/udp/client_connection.rb', line 25

def process_other_packet
  data = packet_protocol.udp_receive_from_client(-1)
  plexer.packet_protocol.udp_send_to_remoteserver(data)
end