mirror of https://github.com/waku-org/nwaku.git
chore: adding ext-multiaddr-only CLI flag (#2141)
This commit is contained in:
parent
13aeebe46f
commit
944dfdaa99
|
@ -92,6 +92,11 @@ type
|
|||
desc: "External multiaddresses to advertise to the network. Argument may be repeated."
|
||||
name: "ext-multiaddr" }: seq[string]
|
||||
|
||||
extMultiAddrsOnly* {.
|
||||
desc: "Only announce external multiaddresses",
|
||||
defaultValue: false,
|
||||
name: "ext-multiaddr-only" }: bool
|
||||
|
||||
maxConnections* {.
|
||||
desc: "Maximum allowed number of libp2p connections."
|
||||
defaultValue: 50
|
||||
|
|
|
@ -111,6 +111,7 @@ proc networkConfiguration*(conf: WakuNodeConf,
|
|||
extIp = extIp,
|
||||
extPort = extPort,
|
||||
extMultiAddrs = extMultiAddrs,
|
||||
extMultiAddrsOnly = conf.extMultiAddrsOnly,
|
||||
wsBindPort = Port(uint16(conf.websocketPort) + conf.portsShift),
|
||||
wsEnabled = conf.websocketSupport,
|
||||
wssEnabled = conf.websocketSecureSupport,
|
||||
|
|
|
@ -338,19 +338,63 @@ suite "Waku NetConfig":
|
|||
check:
|
||||
netConfig.enrMultiaddrs.contains(dns4TcpEndPoint(dns4DomainName, extPort))
|
||||
|
||||
asyncTest "wsHostAddress is not announced if a WS address is provided in extMultiAddrs":
|
||||
asyncTest "wsHostAddress is not announced if a WS/WSS address is provided in extMultiAddrs":
|
||||
|
||||
var
|
||||
conf = defaultTestWakuNodeConf()
|
||||
extAddIp = ValidIpAddress.init("1.2.3.4")
|
||||
extAddPort = Port(1234)
|
||||
wsEnabled = true
|
||||
wssEnabled = false
|
||||
extMultiAddrs = @[(ip4TcpEndPoint(extAddIp, extAddPort) & wsFlag(wssEnabled))]
|
||||
|
||||
var netConfigRes = NetConfig.init(
|
||||
bindIp = conf.listenAddress,
|
||||
bindPort = conf.tcpPort,
|
||||
extMultiAddrs = extMultiAddrs,
|
||||
wsEnabled = wsEnabled
|
||||
)
|
||||
|
||||
assert netConfigRes.isOk(), $netConfigRes.error
|
||||
|
||||
var netConfig = netConfigRes.get()
|
||||
|
||||
check:
|
||||
netConfig.announcedAddresses.len == 2 # Bind address + extAddress
|
||||
netConfig.announcedAddresses[1] == extMultiAddrs[0]
|
||||
|
||||
# Now same test for WSS external address
|
||||
wssEnabled = true
|
||||
extMultiAddrs = @[(ip4TcpEndPoint(extAddIp, extAddPort) & wsFlag(wssEnabled))]
|
||||
|
||||
netConfigRes = NetConfig.init(
|
||||
bindIp = conf.listenAddress,
|
||||
bindPort = conf.tcpPort,
|
||||
extMultiAddrs = extMultiAddrs,
|
||||
wssEnabled = wssEnabled
|
||||
)
|
||||
|
||||
assert netConfigRes.isOk(), $netConfigRes.error
|
||||
|
||||
netConfig = netConfigRes.get()
|
||||
|
||||
check:
|
||||
netConfig.announcedAddresses.len == 2 # Bind address + extAddress
|
||||
netConfig.announcedAddresses[1] == extMultiAddrs[0]
|
||||
|
||||
asyncTest "Only extMultiAddrs are published when enabling extMultiAddrsOnly flag":
|
||||
|
||||
let
|
||||
conf = defaultTestWakuNodeConf()
|
||||
extAddIp = ValidIpAddress.init("1.2.3.4")
|
||||
extAddPort = Port(1234)
|
||||
wssEnabled = false
|
||||
extMultiAddrs = @[(ip4TcpEndPoint(extAddIp, extAddPort) & wsFlag(wssEnabled))]
|
||||
extMultiAddrs = @[ip4TcpEndPoint(extAddIp, extAddPort)]
|
||||
|
||||
let netConfigRes = NetConfig.init(
|
||||
bindIp = conf.listenAddress,
|
||||
bindPort = conf.tcpPort,
|
||||
extMultiAddrs = extMultiAddrs
|
||||
extMultiAddrs = extMultiAddrs,
|
||||
extMultiAddrsOnly = true
|
||||
)
|
||||
|
||||
assert netConfigRes.isOk(), $netConfigRes.error
|
||||
|
@ -358,6 +402,6 @@ suite "Waku NetConfig":
|
|||
let netConfig = netConfigRes.get()
|
||||
|
||||
check:
|
||||
netConfig.announcedAddresses.len == 2 # Bind address + extAddress
|
||||
netConfig.announcedAddresses[1] == extMultiAddrs[0]
|
||||
netConfig.announcedAddresses.len == 1 # ExtAddress
|
||||
netConfig.announcedAddresses[0] == extMultiAddrs[0]
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ proc init*(T: type NetConfig,
|
|||
extIp = none(ValidIpAddress),
|
||||
extPort = none(Port),
|
||||
extMultiAddrs = newSeq[MultiAddress](),
|
||||
extMultiAddrsOnly: bool = false,
|
||||
wsBindPort: Port = Port(8000),
|
||||
wsEnabled: bool = false,
|
||||
wssEnabled: bool = false,
|
||||
|
@ -125,21 +126,22 @@ proc init*(T: type NetConfig,
|
|||
|
||||
var announcedAddresses = newSeq[MultiAddress]()
|
||||
|
||||
if hostExtAddress.isSome():
|
||||
announcedAddresses.add(hostExtAddress.get())
|
||||
else:
|
||||
announcedAddresses.add(formatListenAddress(hostAddress)) # We always have at least a bind address for the host
|
||||
if not extMultiAddrsOnly:
|
||||
if hostExtAddress.isSome():
|
||||
announcedAddresses.add(hostExtAddress.get())
|
||||
else:
|
||||
announcedAddresses.add(formatListenAddress(hostAddress)) # We always have at least a bind address for the host
|
||||
|
||||
if wsExtAddress.isSome():
|
||||
announcedAddresses.add(wsExtAddress.get())
|
||||
elif wsHostAddress.isSome() and not containsWsAddress(extMultiAddrs):
|
||||
# Only publish wsHostAddress if a WS address is not set in extMultiAddrs
|
||||
announcedAddresses.add(wsHostAddress.get())
|
||||
|
||||
# External multiaddrs that the operator may have configured
|
||||
if extMultiAddrs.len > 0:
|
||||
announcedAddresses.add(extMultiAddrs)
|
||||
|
||||
if wsExtAddress.isSome():
|
||||
announcedAddresses.add(wsExtAddress.get())
|
||||
elif wsHostAddress.isSome() and not containsWsAddress(extMultiAddrs):
|
||||
# Only publish wsHostAddress if a WS address is not set in extMultiAddrs
|
||||
announcedAddresses.add(wsHostAddress.get())
|
||||
|
||||
let
|
||||
# enrMultiaddrs are just addresses which cannot be represented in ENR, as described in
|
||||
# https://rfc.vac.dev/spec/31/#many-connection-types
|
||||
|
|
Loading…
Reference in New Issue