diff --git a/src/network/advanceddispatcher.py b/src/network/advanceddispatcher.py index 35121d1c..50ddf44b 100644 --- a/src/network/advanceddispatcher.py +++ b/src/network/advanceddispatcher.py @@ -8,7 +8,7 @@ from helper_threading import BusyError, nonBlocking import state class AdvancedDispatcher(asyncore.dispatcher): - _buf_len = 2097152 # 2MB + _buf_len = 131072 # 128kB def __init__(self, sock=None): if not hasattr(self, '_map'): @@ -85,7 +85,7 @@ class AdvancedDispatcher(asyncore.dispatcher): if asyncore.maxDownloadRate > 0: self.downloadChunk = asyncore.downloadBucket try: - if self.expectBytes > 0: + if self.expectBytes > 0 and not self.fullyEstablished: self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf)) if self.downloadChunk < 0: self.downloadChunk = 0 diff --git a/src/network/bmproto.py b/src/network/bmproto.py index d66d8c4b..445af9a9 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -144,16 +144,16 @@ class BMProto(AdvancedDispatcher, ObjectTracker): def decode_payload_node(self): services, host, port = self.decode_payload_content("Q16sH") if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF': - host = socket.inet_ntop(socket.AF_INET, buffer(host, 12, 4)) + host = socket.inet_ntop(socket.AF_INET, str(host[12:16])) elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43': # Onion, based on BMD/bitcoind host = base64.b32encode(host[6:]).lower() + ".onion" else: - host = socket.inet_ntop(socket.AF_INET6, buffer(host)) + host = socket.inet_ntop(socket.AF_INET6, str(host)) if host == "": # This can happen on Windows systems which are not 64-bit compatible # so let us drop the IPv6 address. - host = socket.inet_ntop(socket.AF_INET, buffer(host, 12, 4)) + host = socket.inet_ntop(socket.AF_INET, str(host[12:16])) return Node(services, host, port) @@ -376,7 +376,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): addresses = self._decode_addr() for i in addresses: seenTime, stream, services, ip, port = i - decodedIP = protocol.checkIPAddress(buffer(ip)) + decodedIP = protocol.checkIPAddress(str(ip)) if stream not in state.streamsInWhichIAmParticipating: continue if decodedIP is not False and seenTime > time.time() - BMProto.addressAlive: diff --git a/src/network/udp.py b/src/network/udp.py index 3d238a5e..e7f6974d 100644 --- a/src/network/udp.py +++ b/src/network/udp.py @@ -89,7 +89,7 @@ class UDPSocket(BMProto): remoteport = False for i in addresses: seenTime, stream, services, ip, port = i - decodedIP = protocol.checkIPAddress(buffer(ip)) + decodedIP = protocol.checkIPAddress(str(ip)) if stream not in state.streamsInWhichIAmParticipating: continue if seenTime < time.time() - BMProto.maxTimeOffset or seenTime > time.time() + BMProto.maxTimeOffset: