diff --git a/src/class_outgoingSynSender.py b/src/class_outgoingSynSender.py index 81403053..0fa74ad8 100644 --- a/src/class_outgoingSynSender.py +++ b/src/class_outgoingSynSender.py @@ -29,14 +29,19 @@ class outgoingSynSender(threading.Thread, StoppableThread): # If the user has specified a trusted peer then we'll only # ever connect to that. Otherwise we'll pick a random one from # the known nodes - shared.knownNodesLock.acquire() if shared.trustedPeer: + shared.knownNodesLock.acquire() peer = shared.trustedPeer shared.knownNodes[self.streamNumber][peer] = time.time() + shared.knownNodesLock.release() else: - peer, = random.sample(shared.knownNodes[self.streamNumber], 1) - shared.knownNodesLock.release() - + while True: + shared.knownNodesLock.acquire() + peer, = random.sample(shared.knownNodes[self.streamNumber], 1) + shared.knownNodesLock.release() + if shared.config.get('bitmessagesettings', 'socksproxytype') != 'none' or peer.host.find(".onion") == -1: + break + time.sleep(1) return peer def stopThread(self): diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index e2a25a3e..aec343d8 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -1,5 +1,6 @@ doTimingAttackMitigation = False +import base64 import errno import math import time @@ -517,6 +518,10 @@ class receiveDataThread(threading.Thread): if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF': hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:]) return self._checkIPv4Address(host[12:], hostStandardFormat) + elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43': + # Onion, based on BMD/bitcoind + hostStandardFormat = base64.b32encode(host[6:]).lower() + ".onion" + return hostStandardFormat else: hostStandardFormat = socket.inet_ntop(socket.AF_INET6, host) if hostStandardFormat == "": diff --git a/src/shared.py b/src/shared.py index 8a8f7339..933e0f40 100644 --- a/src/shared.py +++ b/src/shared.py @@ -9,6 +9,7 @@ useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the # Libraries. +import base64 import collections import ConfigParser import os @@ -150,7 +151,7 @@ def isInSqlInventory(hash): def encodeHost(host): if host.find('.onion') > -1: - return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x7F\x00\x00\x01' + return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(host.split(".")[0], True) elif host.find(':') == -1: return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ socket.inet_aton(host)