mirror of https://github.com/waku-org/nwaku.git
fix: consider WS extMultiAddrs before publishing host address (#2122)
This commit is contained in:
parent
ce5fb3401d
commit
a5b1cfd024
|
@ -338,3 +338,26 @@ suite "Waku NetConfig":
|
||||||
check:
|
check:
|
||||||
netConfig.enrMultiaddrs.contains(dns4TcpEndPoint(dns4DomainName, extPort))
|
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]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import
|
||||||
std/[options, sequtils, strutils],
|
std/[options, sequtils, strutils],
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
libp2p/multiaddress
|
libp2p/[multiaddress, multicodec]
|
||||||
import
|
import
|
||||||
../../waku/waku_core/peers
|
../../waku/waku_core/peers
|
||||||
import
|
import
|
||||||
|
@ -59,6 +59,16 @@ proc formatListenAddress(inputMultiAdd: MultiAddress): MultiAddress =
|
||||||
# If MultiAddress contains "0.0.0.0", replace it for "127.0.0.1"
|
# 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()
|
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,
|
proc init*(T: type NetConfig,
|
||||||
bindIp: ValidIpAddress,
|
bindIp: ValidIpAddress,
|
||||||
bindPort: Port,
|
bindPort: Port,
|
||||||
|
@ -126,7 +136,8 @@ proc init*(T: type NetConfig,
|
||||||
|
|
||||||
if wsExtAddress.isSome():
|
if wsExtAddress.isSome():
|
||||||
announcedAddresses.add(wsExtAddress.get())
|
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())
|
announcedAddresses.add(wsHostAddress.get())
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
Loading…
Reference in New Issue