Skip to content

Commit

Permalink
Merge d5d9106 into ce5fb34
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Oct 17, 2023
2 parents ce5fb34 + d5d9106 commit cf4485e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
23 changes: 23 additions & 0 deletions tests/test_waku_netconfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,26 @@ suite "Waku NetConfig":
check:
netConfig.enrMultiaddrs.contains(dns4TcpEndPoint(dns4DomainName, extPort))

asyncTest "wsHostAddress is not announced if a WS address is provided in extMultiAddrs":

let
conf = defaultTestWakuNodeConf()
extAddIp = ValidIpAddress.init("1.2.3.4")
extAddPort = Port(1234)
wssEnabled = false
extMultiAddrs = @[(ip4TcpEndPoint(extAddIp, extAddPort) & wsFlag(wssEnabled))]

let netConfigRes = NetConfig.init(
bindIp = conf.listenAddress,
bindPort = conf.tcpPort,
extMultiAddrs = extMultiAddrs
)

assert netConfigRes.isOk(), $netConfigRes.error

let netConfig = netConfigRes.get()

check:
netConfig.announcedAddresses.len == 2 # Bind address + extAddress
netConfig.announcedAddresses[1] == extMultiAddrs[0]

15 changes: 13 additions & 2 deletions waku/node/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import
std/[options, sequtils, strutils],
stew/results,
stew/shims/net,
libp2p/multiaddress
libp2p/[multiaddress, multicodec]
import
../../waku/waku_core/peers
import
Expand Down Expand Up @@ -59,6 +59,16 @@ proc formatListenAddress(inputMultiAdd: MultiAddress): MultiAddress =
# If MultiAddress contains "0.0.0.0", replace it for "127.0.0.1"
return MultiAddress.init(inputStr.replace("0.0.0.0", "127.0.0.1")).get()

proc isWsAddress(ma: MultiAddress): bool =
let
isWs = ma.contains(multiCodec("ws")).get()
isWss = ma.contains(multiCodec("wss")).get()

return isWs or isWss

proc containsWsAddress(extMultiAddrs: seq[MultiAddress]): bool =
return extMultiAddrs.filterIt( it.isWsAddress() ).len > 0

proc init*(T: type NetConfig,
bindIp: ValidIpAddress,
bindPort: Port,
Expand Down Expand Up @@ -126,7 +136,8 @@ proc init*(T: type NetConfig,

if wsExtAddress.isSome():
announcedAddresses.add(wsExtAddress.get())
elif wsHostAddress.isSome():
elif wsHostAddress.isSome() and not containsWsAddress(extMultiAddrs):
# Only publish wsHostAddress if a WS address is not set in extMultiAddrs
announcedAddresses.add(wsHostAddress.get())

let
Expand Down

0 comments on commit cf4485e

Please sign in to comment.