From 8550c710eb29c779a4fd3cee703bc72c3a81fcd0 Mon Sep 17 00:00:00 2001 From: Konrad Feldmeier Date: Fri, 23 Dec 2016 15:09:22 +0100 Subject: [PATCH] Fix bootstrap/setup test, enforce bonding (WIP) #50 --- devp2p/kademlia.py | 2 ++ devp2p/tests/test_kademlia_protocol.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/devp2p/kademlia.py b/devp2p/kademlia.py index 960a0fb..e14ec8e 100644 --- a/devp2p/kademlia.py +++ b/devp2p/kademlia.py @@ -371,10 +371,12 @@ def bootstrap(self, nodes): for node in nodes: if node == self.this_node: continue + self.bond(node) self.routing.add_node(node) self.find_node(self.this_node.id, via_node=node) def bond(self, node): + log.debug("bond called", local=self.this_node, remote=node) if not node.pong_recv: if not node in self.waiting_for_pong: self.ping(node) diff --git a/devp2p/tests/test_kademlia_protocol.py b/devp2p/tests/test_kademlia_protocol.py index 567c633..7a00779 100644 --- a/devp2p/tests/test_kademlia_protocol.py +++ b/devp2p/tests/test_kademlia_protocol.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import random -import time from devp2p.utils import int_to_big_endian from devp2p import kademlia import pytest @@ -108,6 +107,8 @@ def test_bootstrap(proto): # lookup self proto.bootstrap(nodes=[other.this_node]) msg = wire.poll(other.this_node) + assert msg[:2] == ('ping', proto.routing.this_node) + msg = wire.poll(other.this_node) assert msg == ('find_node', proto.routing.this_node, proto.routing.this_node.id) assert wire.poll(other.this_node) is None assert wire.messages == [] @@ -124,6 +125,8 @@ def test_setup(proto): # lookup self proto.bootstrap(nodes=[other.this_node]) msg = wire.poll(other.this_node) + assert msg[:2] == ('ping', proto.routing.this_node) + msg = wire.poll(other.this_node) assert msg == ('find_node', proto.routing.this_node, proto.routing.this_node.id) assert wire.poll(other.this_node) is None assert wire.messages == [] @@ -477,7 +480,6 @@ def test_two(proto): assert m[1] == 'ping' -@pytest.mark.skip @pytest.mark.parametrize('num_nodes', [17]) def test_many(proto): assert num_nodes >= kademlia.k_bucket_size + 1 @@ -486,12 +488,14 @@ def test_many(proto): wire = bootstrap.wire # bootstrap - for p in protos[1:]: + for num, p in enumerate(protos[1:]): + print("bootstrapping {i} {node}".format(i=num, node=p.this_node)) p.bootstrap([bootstrap.this_node]) wire.process(protos) # successively add nodes # now everbody does a find node to fill the buckets for p in protos[1:]: + # TODO: shouldn't this be `p.find_node(random_node())` ? p.find_node(p.this_node.id) wire.process(protos) # can all send in parallel