Class: Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Inherits:
-
Object
- Object
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Defined in:
- lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb
Overview
This class will be instantiated by SOCKS5BytestreamsServer upon accepting a new connection
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(socket) ⇒ SOCKS5BytestreamsPeer
constructor
- Initialize a new peer socket
-
[TCPSocket].
-
#start ⇒ Object
Start handshake process.
Constructor Details
#initialize(socket) ⇒ SOCKS5BytestreamsPeer
Initialize a new peer
- socket
- TCPSocket
130 131 132 133 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb', line 130 def initialize(socket) @socket = socket Jabber::debuglog("SOCKS5 BytestreamsServer: accepted peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]}") end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
125 126 127 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb', line 125 def address @address end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
125 126 127 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb', line 125 def socket @socket end |
Instance Method Details
#start ⇒ Object
Start handshake process
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb', line 137 def start auth_ver = @socket.getc if auth_ver != 5 # Unsupported version @socket.close return end auth_nmethods = @socket.getc auth_methods = @socket.read(auth_nmethods) unless auth_methods.index("\x00") # Client won't accept no authentication @socket.write("\x05\xff") @socket.close return end @socket.write("\x05\x00") Jabber::debuglog("SOCKS5 BytestreamsServer: peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]} authenticated") req = @socket.read(4) if req != "\x05\x01\x00\x03" # Unknown version, command, reserved, address-type @socket.close return end req_addrlen = @socket.getc req_addr = @socket.read(req_addrlen) req_port = @socket.read(2) if req_port != "\x00\x00" # Port is not 0 @socket.write("\x05\x01") @socket.close return end @socket.write("\x05\x00\x00\x03#{req_addrlen.chr}#{req_addr}\x00\x00") Jabber::debuglog("SOCKS5 BytestreamsServer: peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]} connected for #{req_addr}") @address = req_addr end |