From 5ff6c26efc9660fbc7032c8da6c9c4d011882a4f Mon Sep 17 00:00:00 2001 From: "jai.s" Date: Fri, 10 Jan 2020 19:06:21 +0530 Subject: [PATCH] Solved python3 database issue and now network connection created via using the python3 db --- src/network/bmproto.py | 2 +- src/network/connectionpool.py | 6 +++++- src/network/tcp.py | 11 ++++++++--- src/protocol.py | 14 +++++++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index dfb57092..099dc358 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -486,7 +486,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): continue except KeyError: pass - if len(knownnodes.knownNodes[stream]) < BMConfigParser().safeGetInt("knownnodes", "maxnodes"): + if len(knownnodes.knownNodes[stream]) < int(BMConfigParser().safeGet("knownnodes", "maxnodes")): with knownnodes.knownNodesLock: try: knownnodes.knownNodes[stream][peer]["lastseen"] = seenTime diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index 4b9ab62b..719c798c 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -326,7 +326,11 @@ class BMConnectionPool(object): continue try: - if chosen.host.endswith(".onion") and Proxy.onion_proxy: + if type(chosen.host) == bytes: + onion= '.onion'.encode() + else: + onion = '.onion' + if chosen.host.endswith(onion) and Proxy.onion_proxy: if onionsocksproxytype == "SOCKS5": self.addConnection(Socks5BMConnection(chosen)) elif onionsocksproxytype == "SOCKS4a": diff --git a/src/network/tcp.py b/src/network/tcp.py index 7dff0122..586dedd6 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -69,9 +69,14 @@ class TCPConnection(BMProto, TLSDispatcher): else: self.destination = address self.isOutbound = True - self.create_socket( - socket.AF_INET6 if ":" in address.host else socket.AF_INET, - socket.SOCK_STREAM) + try: + self.create_socket( + socket.AF_INET6 if ":" in address.host else socket.AF_INET, + socket.SOCK_STREAM) + except TypeError: + self.create_socket( + socket.AF_INET6 if ':'.encode() in address.host else socket.AF_INET, + socket.SOCK_STREAM) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) TLSDispatcher.__init__(self, sock, server_side=False) self.connect(self.destination) diff --git a/src/protocol.py b/src/protocol.py index dd3af795..6fa989a3 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -96,9 +96,17 @@ def isBitSetWithinBitfield(fourByteString, n): def encodeHost(host): """Encode a given host to be used in low-level socket operations""" - if host.find('.onion') > -1: - return '\xfd\x87\xd8\x7e\xeb\x43'.encode('utf-8') + base64.b32decode(host.split(".")[0], True) - elif host.find(':') == -1: + if type(host) == bytes: + onion = 'onion'.encode() + colon = ':'.encode() + full_stop = '.'.encode() + else: + onion = 'onion' + colon = ':' + full_stop = '.' + if host.find(onion) > -1: + return '\xfd\x87\xd8\x7e\xeb\x43'.encode('raw_unicode_escape') + base64.b32decode(host.split(full_stop)[0], True) + elif host.find(colon) == -1: return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF'.encode('raw_unicode_escape') + \ socket.inet_aton(host) return socket.inet_pton(socket.AF_INET6, host)