Class: Shadowsocks::Parser::Base
- Inherits:
-
Object
- Object
- Shadowsocks::Parser::Base
- Defined in:
- lib/shadowsocks/parser/base.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#mode ⇒ Object
Returns the value of attribute mode.
Instance Method Summary collapse
- #addr_len ⇒ Object
- #addr_to_send ⇒ Object
- #addr_type ⇒ Object
- #header_length ⇒ Object
-
#initialize(data) ⇒ Base
constructor
A new instance of Base.
- #remote_addr ⇒ Object
- #remote_port ⇒ Object
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shadowsocks/parser/base.rb', line 6 def initialize(data) @data = data @mode = \ case addr_type when "\x01" :ip when "\x03" :domain else :unsupported end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/shadowsocks/parser/base.rb', line 4 def data @data end |
#mode ⇒ Object
Returns the value of attribute mode.
4 5 6 |
# File 'lib/shadowsocks/parser/base.rb', line 4 def mode @mode end |
Instance Method Details
#addr_len ⇒ Object
24 25 26 |
# File 'lib/shadowsocks/parser/base.rb', line 24 def addr_len raise 'Called abstract method: addr_len' end |
#addr_to_send ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/shadowsocks/parser/base.rb', line 28 def addr_to_send case mode when :domain data[3..5 + addr_len + 2] when :ip data[3..9] end end |
#addr_type ⇒ Object
20 21 22 |
# File 'lib/shadowsocks/parser/base.rb', line 20 def addr_type raise 'Called abstract method: addr_type' end |
#header_length ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/shadowsocks/parser/base.rb', line 45 def header_length case mode when :domain 4 + addr_len when :ip 7 end end |
#remote_addr ⇒ Object
37 38 39 |
# File 'lib/shadowsocks/parser/base.rb', line 37 def remote_addr raise 'Called abstract method: remote_addr' end |
#remote_port ⇒ Object
41 42 43 |
# File 'lib/shadowsocks/parser/base.rb', line 41 def remote_port raise 'Called abstract method: remote_port' end |