class ShadowsocksRuby::Protocols::ShadowsocksProtocol

Shadowsocks packet protocol for both origin shadowsocks protocol and OTA shadowsocks protocol.

specification:

This is a packet protocol, so no need to implement @buffer

Constants

ATYP_DOMAIN
ATYP_IPV4
ATYP_IPV6

Attributes

next_protocol[RW]

Public Class Methods

new(params = {}) click to toggle source

@param [Hash] configuration parameters

# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 20
def initialize params = {}
end

Public Instance Methods

tcp_receive_from_localbackend(n)
tcp_receive_from_localbackend_first_packet(n) click to toggle source
# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 23
def tcp_receive_from_localbackend_first_packet n
  buf = ""
  s = async_recv(1)
  buf << s
  address_type = s.unpack("C").first
  case address_type
  when ATYP_IPV4
    buf << async_recv(4)
  when ATYP_IPV6
    buf << async_recv(16)
  when ATYP_DOMAIN
    buf << (s = async_recv(1))
    domain_len = s.unpack("C").first
    buf << async_recv(domain_len)
    buf << async_recv(2) # port
  else
    raise PharseError, "unknown address_type: #{address_type}"
  end 

  class << self
    alias tcp_receive_from_localbackend tcp_receive_from_localbackend_other_packet
  end
  # first packet is special:
  # ATYP + Destination Address + Destination Port
  buf
end
tcp_receive_from_localbackend_other_packet(n) click to toggle source
# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 52
def tcp_receive_from_localbackend_other_packet n
  async_recv(n)
end
tcp_receive_from_remoteserver(n) click to toggle source
# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 60
def tcp_receive_from_remoteserver n
  async_recv(n)
end
tcp_send_to_localbackend(data) click to toggle source
# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 56
def tcp_send_to_localbackend data
  send_data data
end
tcp_send_to_remoteserver(data) click to toggle source
# File lib/shadowsocks_ruby/protocols/packet/shadowsocks.rb, line 64
def tcp_send_to_remoteserver data
  send_data data
end