From 0324958e9234ccbe66af12e15cbc7f5d7cb2c348 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 6 Aug 2017 23:05:54 +0200 Subject: [PATCH] Peer discovery fixes - incoming packets weren't correctly processed --- src/network/connectionchooser.py | 2 +- src/network/connectionpool.py | 4 ++-- src/network/udp.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index b4d7a37f..616a80f6 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -8,7 +8,7 @@ import state def getDiscoveredPeer(stream): try: - peer = random.choice(state.discoveredPeers.keys()) + return random.choice(state.discoveredPeers.keys()) except (IndexError, KeyError): raise ValueError diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index be7b8ceb..201432f0 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -61,8 +61,8 @@ class BMConnectionPool(object): return self.inboundConnections[addr.host] if addr in self.outboundConnections: return self.outboundConnections[addr] - if addr in self.udpSockets: - return self.udpSockets[addr] + if addr.host in self.udpSockets: + return self.udpSockets[addr.host] raise KeyError def isAlreadyConnected(self, nodeid): diff --git a/src/network/udp.py b/src/network/udp.py index 910e2430..8448da16 100644 --- a/src/network/udp.py +++ b/src/network/udp.py @@ -100,7 +100,7 @@ class UDPSocket(BMProto): return True logger.debug("received peer discovery from %s:%i (port %i):", self.destination.host, self.destination.port, remoteport) if self.local: - state.discoveredPeers[state.Peer(self.destination.host, remoteport)] = time.time + state.discoveredPeers[state.Peer(self.destination.host, remoteport)] = time.time() return True def bm_command_portcheck(self): @@ -143,7 +143,7 @@ class UDPSocket(BMProto): # overwrite the old buffer to avoid mixing data and so that self.local works correctly self.read_buf = recdata self.bm_proto_reset() - receiveDataQueue.put(self.destination) + receiveDataQueue.put(self.listening) def handle_write(self): try: