tunnel bugs fix

This commit is contained in:
Barak Hoffer 2015-10-12 14:56:44 +03:00
parent e739b8104d
commit cc32b369b4
3 changed files with 27 additions and 14 deletions

View File

@ -8,6 +8,7 @@ class TransportProxyBase(Thread):
self.dest_port = dest_port self.dest_port = dest_port
self._stopped = False self._stopped = False
super(TransportProxyBase, self).__init__() super(TransportProxyBase, self).__init__()
self.daemon = True
def stop(self): def stop(self):
self._stopped = True self._stopped = True

View File

@ -18,7 +18,8 @@ class SocketsPipe(Thread):
self.dest = dest self.dest = dest
self.timeout = timeout self.timeout = timeout
self._keep_connection = True self._keep_connection = True
super(SocketsPipe, self).__init__() super(SocketsPipe, self).__init__()
self.daemon = True
def run(self): def run(self):
sockets = [self.source, self.dest] sockets = [self.source, self.dest]

View File

@ -37,21 +37,31 @@ def find_tunnel(attempts=3, timeout=DEFAULT_TIMEOUT):
for attempt in range(0, attempts): for attempt in range(0, attempts):
try: try:
sock.sendto("?", (MCAST_GROUP, MCAST_PORT)) sock.sendto("?", (MCAST_GROUP, MCAST_PORT))
answer, address = sock.recvfrom(BUFFER_READ) tunnels = []
while True:
try:
answer, address = sock.recvfrom(BUFFER_READ)
if not answer in ['?', '+', '-']:
tunnels.append(answer)
except socket.timeout:
break
while answer in ['?', '+', '-']: for tunnel in tunnels:
answer, address = sock.recvfrom(BUFFER_READ) if tunnel.find(':') != -1:
address, port = tunnel.split(':', 1)
if address in l_ips:
continue
LOG.debug("Checking tunnel %s:%d" % (address, port))
is_open,_ = check_port_tcp(address, int(port))
if not is_open:
LOG.debug("Could not connect to %s:%d" % (address, port))
continue
if answer.find(':') != -1: sock.sendto("+", (address, MCAST_PORT))
address, port = answer.split(':', 1) sock.close()
if address in l_ips: return (address, port)
continue
if not check_port_tcp(address, int(port)):
continue
sock.sendto("+", (address, MCAST_PORT))
sock.close()
return (address, port)
except: except:
continue continue
@ -78,6 +88,7 @@ class MonkeyTunnel(Thread):
self._stopped = False self._stopped = False
self._clients = [] self._clients = []
super(MonkeyTunnel, self).__init__() super(MonkeyTunnel, self).__init__()
self.daemon = True
def run(self): def run(self):
self._broad_sock = _set_multicast_socket(self._timeout) self._broad_sock = _set_multicast_socket(self._timeout)