Class: Jabber::Bytestreams::SOCKS5BytestreamsPeer

Class | Jabber::Bytestreams::SOCKS5BytestreamsPeer
In: | lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb
Parent: | Object

This class will be instantiated by SOCKS5BytestreamsServer upon accepting a new connection

### Methods

new start

### Attributes

address | [R] |
socket | [R] |

### Public Class methods

new(socket)

Initialize a new peer

socket: | [TCPSocket]

[Source]

         # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 146
    146:       def initialize(socket)
    147:         @socket = socket
    148:         Jabber::debuglog("SOCKS5 BytestreamsServer: accepted peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]}")
    149:       end

### Public Instance methods

start()

Start handshake process

[Source]

         # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb, line 153
    153:       def start
    154:         if !@socket.respond_to? :getbyte
    155:           class << @socket; alias getbyte getc; end
    156:         end
    157:
    158:         auth_ver = @socket.getbyte
    159:         if auth_ver != 5
    160:           # Unsupported version
    161:           @socket.close
    162:           return
    163:         end
    164:
    165:         auth_nmethods = @socket.getbyte
    166:         auth_methods = @socket.read(auth_nmethods)
    167:         unless auth_methods.index("\x00")
    168:           # Client won't accept no authentication
    169:           @socket.write("\x05\xff")
    170:           @socket.close
    171:           return
    172:         end
    173:         @socket.write("\x05\x00")
    174:         Jabber::debuglog("SOCKS5 BytestreamsServer: peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]} authenticated")
    175:
    176:         req = @socket.read(4)
    177:         if req != "\x05\x01\x00\x03"
    178:           # Unknown version, command, reserved, address-type
    179:           @socket.close
    180:           return
    181:         end
    182:         req_addrlen = @socket.getbyte
    183:         req_addr = @socket.read(req_addrlen)
    184:         req_port = @socket.read(2)
    185:         if req_port != "\x00\x00"
    186:           # Port is not 0
    187:           @socket.write("\x05\x01")
    188:           @socket.close
    189:           return
    190:         end
    191:         @socket.write("\x05\x00\x00\x03#{req_addrlen.chr}#{req_addr}\x00\x00")
    192:         Jabber::debuglog("SOCKS5 BytestreamsServer: peer #{@socket.peeraddr[2]}:#{@socket.peeraddr[1]} connected for #{req_addr}")
    193:
    194:         @address = req_addr
    195:       end

[Validate]