Module: ShadowsocksRuby::Connections::UDP::ClientConnection

Includes:
Connection, ServerConnection
Defined in:
lib/shadowsocks_ruby/connections/udp/client_connection.rb

Overview

Mixed-in with an EventMachine::Connection Object to use this.

Constant Summary

Constants included from Connection

Connection::PressureLevel

Instance Attribute Summary

Attributes included from ServerConnection

#packet_protocol, #params

Attributes included from Connection

#logger, #plexer

Instance Method Summary collapse

Methods included from ServerConnection

#create_plexer, #post_init

Methods included from Connection

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

Instance Method 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):

  • :host (String)

    shadowsocks server address, required

  • :port (Integer)

    shadowsocks server port, required

Returns:

  • (Connection_Object)


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

def initialize protocol_stack, params, backend_protocol_stack, backend_params
  super
end

#process_first_packetObject Also known as: process_hook



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

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



35
36
37
38
# File 'lib/shadowsocks_ruby/connections/udp/client_connection.rb', line 35

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