Skip to content

Commit

Permalink
Fix bootstrap/setup test, enforce bonding (WIP) ethereum#50
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkonrad committed Jan 18, 2017
1 parent 0d651ea commit 8550c71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions devp2p/kademlia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions devp2p/tests/test_kademlia_protocol.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 == []
Expand All @@ -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 == []
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 8550c71

Please sign in to comment.