Sha256: edc8d7d367a034ce26709075d11b23015a7c4506344701584039c5122645116c

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

module ShadowsocksRuby
  module Connections
    # Provides various functionality code of a TCP Connection.
    #
    # @example
    #     class DummyConnection < EventMachine::Connection
    #       include ShadowsocksRuby::Connections::TCP::ClientConnection
    #     end
    #     # some how get a DummyConnection object
    #     # dummy_connection = ...
    #     # dummy_connection.plexer_protocol.tcp_process_client will be called looply
    module TCP
      # Mixed-in with an EventMachine::Connection Object to use this.
      module ClientConnection
        include ShadowsocksRuby::Connections::Connection
        include ShadowsocksRuby::Connections::ServerConnection
        # (see ServerConnection#initialize)
        # @option params [String]                :host  shadowsocks server address, required
        # @option params [Integer]                :port  shadowsocks server port, required
        def initialize protocol_stack, params, backend_protocol_stack, backend_params
          super
        end

        def process_first_packet
          address_bin = packet_protocol.tcp_receive_from_client(-1)
          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

        # This is Called by process loop 
        alias process_hook process_first_packet

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shadowsocks_ruby-0.1.2 lib/shadowsocks_ruby/connections/tcp/client_connection.rb
shadowsocks_ruby-0.1.1 lib/shadowsocks_ruby/connections/tcp/client_connection.rb
shadowsocks_ruby-0.1.0 lib/shadowsocks_ruby/connections/tcp/client_connection.rb