From cfdb26db4097b078f02db172534977bd47e0e6c3 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 18 Feb 2020 01:07:23 +0200 Subject: [PATCH] [discv5] Advertise the LibP2P TCP port properly --- eth/p2p/discoveryv5/protocol.nim | 10 +++++++--- tests/p2p/p2p_test_helper.nim | 5 +++-- tests/p2p/test_discoveryv5.nim | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 7d6db55..ac14a75 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -33,9 +33,12 @@ proc whoareyouMagic(toNode: NodeId): array[32, byte] = for i, c in prefix: data[sizeof(toNode) + i] = byte(c) sha256.digest(data).data -proc newProtocol*(privKey: PrivateKey, db: Database, port: Port): Protocol = +proc newProtocol*(privKey: PrivateKey, + db: Database, + tcpPort, udpPort: Port): Protocol = result = Protocol(privateKey: privKey, db: db) - let a = Address(ip: parseIpAddress("127.0.0.1"), udpPort: port) + let a = Address(ip: parseIpAddress("127.0.0.1"), + tcpPort: tcpPort, udpPort: udpPort) result.localNode = newNode(initENode(result.privateKey.getPublicKey(), a)) result.localNode.record = enr.Record.init(12, result.privateKey, a) @@ -364,7 +367,8 @@ when isMainModule: else: pk = newPrivateKey() - let d = newProtocol(pk, DiscoveryDB.init(newMemoryDB()), Port(12001 + i)) + let d = newProtocol(pk, DiscoveryDB.init(newMemoryDB()), + Port(12001 + i), Port(12001 + i)) d.open() result.add(d) diff --git a/tests/p2p/p2p_test_helper.nim b/tests/p2p/p2p_test_helper.nim index 7a1087c..e75e64c 100644 --- a/tests/p2p/p2p_test_helper.nim +++ b/tests/p2p/p2p_test_helper.nim @@ -6,7 +6,8 @@ var nextPort = 30303 proc localAddress*(port: int): Address = let port = Port(port) - result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1")) + result = Address(udpPort: port, tcpPort: port, + ip: parseIpAddress("127.0.0.1")) proc startDiscoveryNode*(privKey: PrivateKey, address: Address, bootnodes: seq[ENode]): Future[DiscoveryProtocol] {.async.} = @@ -47,4 +48,4 @@ proc recvMsgMock*(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] = var rlp = rlpFromBytes(@msg.toRange) let msgId = rlp.read(int32) - return (msgId.int, rlp) \ No newline at end of file + return (msgId.int, rlp) diff --git a/tests/p2p/test_discoveryv5.nim b/tests/p2p/test_discoveryv5.nim index 4e2776c..7998833 100644 --- a/tests/p2p/test_discoveryv5.nim +++ b/tests/p2p/test_discoveryv5.nim @@ -6,9 +6,9 @@ import ./p2p_test_helper proc startDiscoveryv5Node*(privKey: PrivateKey, address: Address, - bootnodes: seq[Record]): discv5_protocol.Protocol = + bootnodes: seq[Record]): discv5_protocol.Protocol = var db = DiscoveryDB.init(newMemoryDB()) - result = newProtocol(privKey, db, address.udpPort) + result = newProtocol(privKey, db, address.tcpPort, address.udpPort) for node in bootnodes: result.addNode(node)