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."
|
desc: "External multiaddresses to advertise to the network. Argument may be repeated."
|
||||||
name: "ext-multiaddr" }: seq[string]
|
name: "ext-multiaddr" }: seq[string]
|
||||||
|
|
||||||
|
extMultiAddrsOnly* {.
|
||||||
|
desc: "Only announce external multiaddresses",
|
||||||
|
defaultValue: false,
|
||||||
|
name: "ext-multiaddr-only" }: bool
|
||||||
|
|
||||||
maxConnections* {.
|
maxConnections* {.
|
||||||
desc: "Maximum allowed number of libp2p connections."
|
desc: "Maximum allowed number of libp2p connections."
|
||||||
defaultValue: 50
|
defaultValue: 50
|
||||||
|
|
|
@ -111,6 +111,7 @@ proc networkConfiguration*(conf: WakuNodeConf,
|
||||||
extIp = extIp,
|
extIp = extIp,
|
||||||
extPort = extPort,
|
extPort = extPort,
|
||||||
extMultiAddrs = extMultiAddrs,
|
extMultiAddrs = extMultiAddrs,
|
||||||
|
extMultiAddrsOnly = conf.extMultiAddrsOnly,
|
||||||
wsBindPort = Port(uint16(conf.websocketPort) + conf.portsShift),
|
wsBindPort = Port(uint16(conf.websocketPort) + conf.portsShift),
|
||||||
wsEnabled = conf.websocketSupport,
|
wsEnabled = conf.websocketSupport,
|
||||||
wssEnabled = conf.websocketSecureSupport,
|
wssEnabled = conf.websocketSecureSupport,
|
||||||
|
|
|
@ -338,19 +338,63 @@ 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":
|
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
|
let
|
||||||
conf = defaultTestWakuNodeConf()
|
conf = defaultTestWakuNodeConf()
|
||||||
extAddIp = ValidIpAddress.init("1.2.3.4")
|
extAddIp = ValidIpAddress.init("1.2.3.4")
|
||||||
extAddPort = Port(1234)
|
extAddPort = Port(1234)
|
||||||
wssEnabled = false
|
extMultiAddrs = @[ip4TcpEndPoint(extAddIp, extAddPort)]
|
||||||
extMultiAddrs = @[(ip4TcpEndPoint(extAddIp, extAddPort) & wsFlag(wssEnabled))]
|
|
||||||
|
|
||||||
let netConfigRes = NetConfig.init(
|
let netConfigRes = NetConfig.init(
|
||||||
bindIp = conf.listenAddress,
|
bindIp = conf.listenAddress,
|
||||||
bindPort = conf.tcpPort,
|
bindPort = conf.tcpPort,
|
||||||
extMultiAddrs = extMultiAddrs
|
extMultiAddrs = extMultiAddrs,
|
||||||
|
extMultiAddrsOnly = true
|
||||||
)
|
)
|
||||||
|
|
||||||
assert netConfigRes.isOk(), $netConfigRes.error
|
assert netConfigRes.isOk(), $netConfigRes.error
|
||||||
|
@ -358,6 +402,6 @@ suite "Waku NetConfig":
|
||||||
let netConfig = netConfigRes.get()
|
let netConfig = netConfigRes.get()
|
||||||
|
|
||||||
check:
|
check:
|
||||||
netConfig.announcedAddresses.len == 2 # Bind address + extAddress
|
netConfig.announcedAddresses.len == 1 # ExtAddress
|
||||||
netConfig.announcedAddresses[1] == extMultiAddrs[0]
|
netConfig.announcedAddresses[0] == extMultiAddrs[0]
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ proc init*(T: type NetConfig,
|
||||||
extIp = none(ValidIpAddress),
|
extIp = none(ValidIpAddress),
|
||||||
extPort = none(Port),
|
extPort = none(Port),
|
||||||
extMultiAddrs = newSeq[MultiAddress](),
|
extMultiAddrs = newSeq[MultiAddress](),
|
||||||
|
extMultiAddrsOnly: bool = false,
|
||||||
wsBindPort: Port = Port(8000),
|
wsBindPort: Port = Port(8000),
|
||||||
wsEnabled: bool = false,
|
wsEnabled: bool = false,
|
||||||
wssEnabled: bool = false,
|
wssEnabled: bool = false,
|
||||||
|
@ -125,21 +126,22 @@ proc init*(T: type NetConfig,
|
||||||
|
|
||||||
var announcedAddresses = newSeq[MultiAddress]()
|
var announcedAddresses = newSeq[MultiAddress]()
|
||||||
|
|
||||||
if hostExtAddress.isSome():
|
if not extMultiAddrsOnly:
|
||||||
announcedAddresses.add(hostExtAddress.get())
|
if hostExtAddress.isSome():
|
||||||
else:
|
announcedAddresses.add(hostExtAddress.get())
|
||||||
announcedAddresses.add(formatListenAddress(hostAddress)) # We always have at least a bind address for the host
|
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
|
# External multiaddrs that the operator may have configured
|
||||||
if extMultiAddrs.len > 0:
|
if extMultiAddrs.len > 0:
|
||||||
announcedAddresses.add(extMultiAddrs)
|
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
|
let
|
||||||
# enrMultiaddrs are just addresses which cannot be represented in ENR, as described in
|
# enrMultiaddrs are just addresses which cannot be represented in ENR, as described in
|
||||||
# https://rfc.vac.dev/spec/31/#many-connection-types
|
# https://rfc.vac.dev/spec/31/#many-connection-types
|
||||||
|
|
Loading…
Reference in New Issue