Skip to content

Add discovery v5.1 implementation #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 16, 2020
8 changes: 8 additions & 0 deletions eth.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ proc runP2pTests() =
"test_lru",
"test_discoveryv5",
"test_discv5_encoding",
"test_discv51_encoding",
"test_routing_table"
]:
runTest("tests/p2p/" & filename)

proc runDiscv51Test() =
let path = "tests/p2p/test_discoveryv5"
echo "\nRunning: ", path
exec "nim c -r -d:UseDiscv51=true -d:release -d:chronicles_log_level=ERROR --verbosity:0 --hints:off " & path
rmFile path

task test_p2p, "run p2p tests":
runP2pTests()
runDiscv51Test()

proc runRlpTests() =
runTest("tests/rlp/all_tests")
Expand Down
16 changes: 14 additions & 2 deletions eth/p2p/discoveryv5/dcli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import
std/[options, strutils],
chronos, chronicles, chronicles/topics_registry, confutils, metrics,
stew/byteutils, confutils/std/net,
eth/keys, eth/net/nat, protocol, enr, node
eth/keys, eth/net/nat, enr, node

### This is all just temporary to be compatible with both versions
const UseDiscv51* {.booldefine.} = false

when UseDiscv51:
import protocolv1
else:
import protocol
###

type
DiscoveryCmd* = enum
Expand Down Expand Up @@ -166,7 +175,10 @@ proc run(config: DiscoveryConf) =
else:
echo "No Pong message returned"
of findnode:
let nodes = waitFor d.findNode(config.findNodeTarget, config.distance)
when UseDiscv51:
let nodes = waitFor d.findNode(config.findNodeTarget, @[config.distance])
else:
let nodes = waitFor d.findNode(config.findNodeTarget, config.distance)
if nodes.isOk():
echo "Received valid records:"
for node in nodes[]:
Expand Down
Loading