mirror of https://github.com/status-im/nim-eth.git
[discv5] Advertise the LibP2P TCP port properly
This commit is contained in:
parent
cca931d0b5
commit
cfdb26db40
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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.} =
|
||||||
|
@ -47,4 +48,4 @@ proc recvMsgMock*(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] =
|
||||||
var rlp = rlpFromBytes(@msg.toRange)
|
var rlp = rlpFromBytes(@msg.toRange)
|
||||||
|
|
||||||
let msgId = rlp.read(int32)
|
let msgId = rlp.read(int32)
|
||||||
return (msgId.int, rlp)
|
return (msgId.int, rlp)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue