Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/socks5.py
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def __init__(self, cmd, atyp, addr, port, username, password): | ||||
self.password = password | self.password = password | ||||
def __repr__(self): | def __repr__(self): | ||||
return 'Socks5Command({},{},{},{},{},{})'.format( | return 'Socks5Command({},{},{},{},{},{})'.format( | ||||
self.cmd, self.atyp, self.addr, self.port, self.username, self.password) | self.cmd, self.atyp, self.addr, self.port, self.username, self.password) | ||||
class Socks5Connection(): | class Socks5Connection(): | ||||
def __init__(self, serv, conn, peer): | def __init__(self, serv, conn): | ||||
self.serv = serv | self.serv = serv | ||||
self.conn = conn | self.conn = conn | ||||
self.peer = peer | |||||
def handle(self): | def handle(self): | ||||
"""Handle socks5 request according to RFC192.""" | """Handle socks5 request according to RFC192.""" | ||||
try: | try: | ||||
# Verify socks version | # Verify socks version | ||||
ver = recvall(self.conn, 1)[0] | ver = recvall(self.conn, 1)[0] | ||||
if ver != 0x05: | if ver != 0x05: | ||||
raise IOError('Invalid socks version {}'.format(ver)) | raise IOError('Invalid socks version {}'.format(ver)) | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | def __init__(self, conf): | ||||
self.s.bind(conf.addr) | self.s.bind(conf.addr) | ||||
self.s.listen(5) | self.s.listen(5) | ||||
self.running = False | self.running = False | ||||
self.thread = None | self.thread = None | ||||
self.queue = queue.Queue() # report connections and exceptions to client | self.queue = queue.Queue() # report connections and exceptions to client | ||||
def run(self): | def run(self): | ||||
while self.running: | while self.running: | ||||
(sockconn, peer) = self.s.accept() | (sockconn, _) = self.s.accept() | ||||
if self.running: | if self.running: | ||||
conn = Socks5Connection(self, sockconn, peer) | conn = Socks5Connection(self, sockconn) | ||||
thread = threading.Thread(None, conn.handle) | thread = threading.Thread(None, conn.handle) | ||||
thread.daemon = True | thread.daemon = True | ||||
thread.start() | thread.start() | ||||
def start(self): | def start(self): | ||||
assert not self.running | assert not self.running | ||||
self.running = True | self.running = True | ||||
self.thread = threading.Thread(None, self.run) | self.thread = threading.Thread(None, self.run) | ||||
Show All 10 Lines |