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