feat(enr): add discv5 UDP port to node's main discoverable ENR (#996)

This commit is contained in:
Hanno Cornelius 2022-06-09 17:46:21 +02:00 committed by GitHub
parent 271a2c750b
commit 6a09ed2c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -161,7 +161,7 @@ template wsFlag(wssEnabled: bool): MultiAddress =
proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
bindIp: ValidIpAddress, bindPort: Port,
extIp = none[ValidIpAddress](), extPort = none[Port](),
extIp = none(ValidIpAddress), extPort = none(Port),
peerStorage: PeerStorage = nil,
maxConnections = builders.MaxConnections,
wsBindPort: Port = (Port)8000,
@ -172,7 +172,8 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
wakuFlags = none(WakuEnrBitfield),
nameResolver: NameResolver = nil,
sendSignedPeerRecord = false,
dns4DomainName = none(string)
dns4DomainName = none(string),
discv5UdpPort = none(Port)
): T
{.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
## Creates a Waku Node.
@ -228,7 +229,8 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
else: @[]
enr = initEnr(nodeKey,
enrIp,
enrTcpPort, none(Port),
enrTcpPort,
discv5UdpPort,
wakuFlags,
enrMultiaddrs)
@ -1100,6 +1102,9 @@ when isMainModule:
dns4DomainName = if conf.dns4DomainName != "": some(conf.dns4DomainName)
else: none(string)
discv5UdpPort = if conf.discv5Discovery: some(Port(uint16(conf.discv5UdpPort) + conf.portsShift))
else: none(Port)
## @TODO: the NAT setup assumes a manual port mapping configuration if extIp config is set. This probably
## implies adding manual config item for extPort as well. The following heuristic assumes that, in absence of manual
@ -1127,12 +1132,12 @@ when isMainModule:
some(wakuFlags),
dnsResolver,
conf.relayPeerExchange, # We send our own signed peer record when peer exchange enabled
dns4DomainName
dns4DomainName,
discv5UdpPort
)
if conf.discv5Discovery:
let
discv5UdpPort = Port(uint16(conf.discv5UdpPort) + conf.portsShift)
discoveryConfig = DiscoveryConfig.init(
conf.discv5TableIpLimit, conf.discv5BucketIpLimit, conf.discv5BitsPerHop)
@ -1152,9 +1157,9 @@ when isMainModule:
addBootstrapNode(enrUri, discv5BootstrapEnrs)
node.wakuDiscv5 = WakuDiscoveryV5.new(
extIP, extPort, some(discv5UdpPort),
extIP, extPort, discv5UdpPort,
conf.listenAddress,
discv5UdpPort,
discv5UdpPort.get(),
discv5BootstrapEnrs,
conf.discv5EnrAutoUpdate,
keys.PrivateKey(conf.nodekey.skkey),