Skip to content

Commit

Permalink
chore: decoupling announced and listen addresses (#2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Nov 16, 2023
1 parent c9e869f commit ef8ffbd
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import
libp2p/protocols/connectivity/autonat/service,
libp2p/protocols/rendezvous,
libp2p/builders,
libp2p/transports/transport,
libp2p/transports/tcptransport,
libp2p/transports/wstransport
import
Expand Down Expand Up @@ -1082,16 +1083,29 @@ proc isBindIpWithZeroPort(inputMultiAdd: MultiAddress): bool =

proc printNodeNetworkInfo*(node: WakuNode): void =
let peerInfo = node.switch.peerInfo
var announcedStr = ""
var listenStr = ""
var localIp = ""

try:
localIp = $getPrimaryIPAddr()
except Exception as e:
warn "Could not retrieve localIp", msg=e.msg

info "PeerInfo", peerId = peerInfo.peerId, addrs = peerInfo.addrs

for address in node.announcedAddresses:
var fulladdr = "[" & $address & "/p2p/" & $peerInfo.peerId & "]"
listenStr &= fulladdr
announcedStr &= fulladdr

for transport in node.switch.transports:
for address in transport.addrs:
var fulladdr = "[" & $address & "/p2p/" & $peerInfo.peerId & "]"
listenStr &= fulladdr

## XXX: this should be /ip4..., / stripped?
info "Listening on", full = listenStr
info "Listening on", full = listenStr, localIp = localIp
info "Announcing addresses", full = announcedStr
info "DNS: discoverable ENR ", enr = node.enr.toUri()

proc start*(node: WakuNode) {.async.} =
Expand All @@ -1106,11 +1120,6 @@ proc start*(node: WakuNode) {.async.} =
if isBindIpWithZeroPort(address):
zeroPortPresent = true

if not zeroPortPresent:
printNodeNetworkInfo(node)
else:
info "Listening port is dynamically allocated, address and ENR generation postponed"

# Perform relay-specific startup tasks TODO: this should be rethought
if not node.wakuRelay.isNil():
await node.startRelay()
Expand All @@ -1129,6 +1138,11 @@ proc start*(node: WakuNode) {.async.} =

node.wakuMetadata.start()

if not zeroPortPresent:
printNodeNetworkInfo(node)
else:
info "Listening port is dynamically allocated, address and ENR generation postponed"

info "Node started successfully"

proc stop*(node: WakuNode) {.async.} =
Expand Down

0 comments on commit ef8ffbd

Please sign in to comment.