[discv5] Advertise the LibP2P TCP port properly

This commit is contained in:
Zahary Karadjov 2020-02-18 01:07:23 +02:00
parent cca931d0b5
commit cfdb26db40
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
3 changed files with 12 additions and 7 deletions

View File

@ -33,9 +33,12 @@ proc whoareyouMagic(toNode: NodeId): array[32, byte] =
for i, c in prefix: data[sizeof(toNode) + i] = byte(c) for i, c in prefix: data[sizeof(toNode) + i] = byte(c)
sha256.digest(data).data 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) 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 = newNode(initENode(result.privateKey.getPublicKey(), a))
result.localNode.record = enr.Record.init(12, result.privateKey, a) result.localNode.record = enr.Record.init(12, result.privateKey, a)
@ -364,7 +367,8 @@ when isMainModule:
else: else:
pk = newPrivateKey() 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() d.open()
result.add(d) result.add(d)

View File

@ -6,7 +6,8 @@ var nextPort = 30303
proc localAddress*(port: int): Address = proc localAddress*(port: int): Address =
let port = Port(port) 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, proc startDiscoveryNode*(privKey: PrivateKey, address: Address,
bootnodes: seq[ENode]): Future[DiscoveryProtocol] {.async.} = bootnodes: seq[ENode]): Future[DiscoveryProtocol] {.async.} =

View File

@ -6,9 +6,9 @@ import
./p2p_test_helper ./p2p_test_helper
proc startDiscoveryv5Node*(privKey: PrivateKey, address: Address, proc startDiscoveryv5Node*(privKey: PrivateKey, address: Address,
bootnodes: seq[Record]): discv5_protocol.Protocol = bootnodes: seq[Record]): discv5_protocol.Protocol =
var db = DiscoveryDB.init(newMemoryDB()) var db = DiscoveryDB.init(newMemoryDB())
result = newProtocol(privKey, db, address.udpPort) result = newProtocol(privKey, db, address.tcpPort, address.udpPort)
for node in bootnodes: for node in bootnodes:
result.addNode(node) result.addNode(node)