From 15857e6551862a119c699a68524ab2f9eed1ca99 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 20 Oct 2017 01:07:30 +0200 Subject: [PATCH] Asyncore updates - reduce buffer size to 128kB (was 2MB) - IP address handling use str instead of buffer (the latter, even though it should be faster, breaks the code on Windows) - read up to full buffer after fully established (otherwise downloads become too slow due to the loop time). This reverts a change made in d28a7bfb862e6d9b9716098b27e5ec1d2f482da8 --- src/network/advanceddispatcher.py | 4 ++-- src/network/bmproto.py | 8 ++++---- src/network/udp.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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: