Sha256: 443104a95ac2a5d1fb24a83929ca65cb1186f6a228c3f64becf98263e8235ccb

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module ShadowsocksRuby
  module Connections
    # Mixed-in code to provide functionality to a BackendConnection
    # ,whose peer is a upstream peer, like a Destinatiion or a RemoteServer.
    module BackendConnection
      
      # Packet Protocol
      #
      # A Strategy Pattern for replacing protocol algorithm
      #
      # all read from {BackendConnection}'s {packet_protocol} is just data,
      # 
      # the first send to {packet_protocol} chould be address_bin (for a {RemoteServerConnection}) 
      # or data (for a {DestinationConnection}),
      # other send to {packet_protocol} should be just data
      #
      # @return [ShadowsocksRuby::Protocols::SomePacketProtocol]
      # @see ShadowsocksRuby::Protocols
      attr_accessor :packet_protocol

      # (see ServerConnection#params)
      attr_reader :params

      # If clild class override initialize, make sure to call super
      #
      # @param [Protocols::ProtocolStack] protocol_stack
      # @param [Hash] params
      # @return [Connection_Object]
      def initialize protocol_stack, params
        super()

        @packet_protocol = protocol_stack.build!(self)    

        @params = params
        @connected = EM::DefaultDeferrable.new
      end


      def connection_completed
        @connected.succeed
      end

      # Buffer data until the connection to the backend server
      # is established and is ready for use
      def send_data data
        @connected.callback { super data }
      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/backend_connection.rb
shadowsocks_ruby-0.1.1 lib/shadowsocks_ruby/connections/backend_connection.rb
shadowsocks_ruby-0.1.0 lib/shadowsocks_ruby/connections/backend_connection.rb