slightly modify IPv6 modifications so that IPv4-only hosts properly handle v6 IPs

This commit is contained in:
Jonathan Warren 2014-04-27 18:05:43 -04:00
parent 7da6ea958f
commit 114ba4e23a
2 changed files with 22 additions and 1 deletions

View File

@ -59,7 +59,24 @@ class outgoingSynSender(threading.Thread):
address_family = socket.AF_INET address_family = socket.AF_INET
else: else:
address_family = socket.AF_INET6 address_family = socket.AF_INET6
sock = socks.socksocket(address_family, socket.SOCK_STREAM) try:
sock = socks.socksocket(address_family, socket.SOCK_STREAM)
except:
"""
The line can fail on Windows systems which aren't
64-bit compatiable:
File "C:\Python27\lib\socket.py", line 187, in __init__
_sock = _realsocket(family, type, proto)
error: [Errno 10047] An address incompatible with the requested protocol was used
So let us remove the offending address from our knownNodes file.
"""
shared.knownNodesLock.acquire()
del shared.knownNodes[self.streamNumber][peer]
shared.knownNodesLock.release()
with shared.printLock:
print 'deleting ', peer, 'from shared.knownNodes because it caused a socks.socksocket exception. We must not be 64-bit compatible.'
continue
# This option apparently avoids the TIME_WAIT state so that we # This option apparently avoids the TIME_WAIT state so that we
# can rebind faster # can rebind faster
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

View File

@ -622,6 +622,10 @@ class receiveDataThread(threading.Thread):
continue continue
else: else:
hostFromAddrMessage = socket.inet_ntop(socket.AF_INET6, fullHost) hostFromAddrMessage = socket.inet_ntop(socket.AF_INET6, fullHost)
if hostFromAddrMessage == "":
# This can happen on Windows systems which are not 64-bit compatible
# so let us drop the IPv6 address.
continue
if not self._checkIPv6Address(fullHost, hostFromAddrMessage): if not self._checkIPv6Address(fullHost, hostFromAddrMessage):
continue continue
timeSomeoneElseReceivedMessageFromThisNode, = unpack('>Q', data[lengthOfNumberOfAddresses + ( timeSomeoneElseReceivedMessageFromThisNode, = unpack('>Q', data[lengthOfNumberOfAddresses + (