mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 17:03:09 +00:00
Domain name config for nwaku node (#852)
This commit is contained in:
parent
dd2ed886a3
commit
2fd5b6c4ea
@ -1482,3 +1482,22 @@ procSuite "WakuNode":
|
|||||||
node.switch.peerInfo.addrs.contains(announcedEndpoint)
|
node.switch.peerInfo.addrs.contains(announcedEndpoint)
|
||||||
|
|
||||||
await node.stop()
|
await node.stop()
|
||||||
|
|
||||||
|
asyncTest "Node can use dns4 in announced addresses":
|
||||||
|
let
|
||||||
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||||
|
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||||
|
bindPort = Port(60000)
|
||||||
|
extIp = some(ValidIpAddress.init("127.0.0.1"))
|
||||||
|
extPort = some(Port(60002))
|
||||||
|
domainName = "example.com"
|
||||||
|
expectedDns4Addr = MultiAddress.init("/dns4/" & domainName & "/tcp/" & $(extPort.get())).get()
|
||||||
|
node = WakuNode.new(
|
||||||
|
nodeKey,
|
||||||
|
bindIp, bindPort,
|
||||||
|
extIp, extPort,
|
||||||
|
dns4DomainName = some(domainName))
|
||||||
|
|
||||||
|
check:
|
||||||
|
node.announcedAddresses.len == 1
|
||||||
|
node.announcedAddresses.contains(expectedDns4Addr)
|
||||||
|
|||||||
@ -76,6 +76,11 @@ type
|
|||||||
desc: "DNS name server IPs to query for DNS multiaddrs resolution. Argument may be repeated."
|
desc: "DNS name server IPs to query for DNS multiaddrs resolution. Argument may be repeated."
|
||||||
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
|
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
|
||||||
name: "dns-addrs-name-server" }: seq[ValidIpAddress]
|
name: "dns-addrs-name-server" }: seq[ValidIpAddress]
|
||||||
|
|
||||||
|
dns4DomainName* {.
|
||||||
|
desc: "The domain name resolving to the node's public IPv4 address",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "dns4-domain-name" }: string
|
||||||
|
|
||||||
## Relay config
|
## Relay config
|
||||||
|
|
||||||
|
|||||||
@ -142,10 +142,19 @@ proc updateSwitchPeerInfo(node: WakuNode) =
|
|||||||
if node.announcedAddresses.len > 0:
|
if node.announcedAddresses.len > 0:
|
||||||
node.switch.peerInfo.addrs = node.announcedAddresses
|
node.switch.peerInfo.addrs = node.announcedAddresses
|
||||||
|
|
||||||
template tcpEndPoint(address, port): auto =
|
template ip4TcpEndPoint(address, port): MultiAddress =
|
||||||
MultiAddress.init(address, tcpProtocol, port)
|
MultiAddress.init(address, tcpProtocol, port)
|
||||||
|
|
||||||
func wsFlag(wssEnabled: bool): MultiAddress {.raises: [Defect, LPError]} =
|
template dns4Ma(dns4DomainName: string): MultiAddress =
|
||||||
|
MultiAddress.init("/dns4/" & dns4DomainName).tryGet()
|
||||||
|
|
||||||
|
template tcpPortMa(port: Port): MultiAddress =
|
||||||
|
MultiAddress.init("/tcp/" & $port).tryGet()
|
||||||
|
|
||||||
|
template dns4TcpEndPoint(dns4DomainName: string, port: Port): MultiAddress =
|
||||||
|
dns4Ma(dns4DomainName) & tcpPortMa(port)
|
||||||
|
|
||||||
|
template wsFlag(wssEnabled: bool): MultiAddress =
|
||||||
if wssEnabled: MultiAddress.init("/wss").tryGet()
|
if wssEnabled: MultiAddress.init("/wss").tryGet()
|
||||||
else: MultiAddress.init("/ws").tryGet()
|
else: MultiAddress.init("/ws").tryGet()
|
||||||
|
|
||||||
@ -161,6 +170,7 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
|||||||
secureCert: string = "",
|
secureCert: string = "",
|
||||||
wakuFlags = none(WakuEnrBitfield),
|
wakuFlags = none(WakuEnrBitfield),
|
||||||
nameResolver: NameResolver = nil,
|
nameResolver: NameResolver = nil,
|
||||||
|
dns4DomainName = none(string)
|
||||||
): T
|
): T
|
||||||
{.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
{.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
||||||
## Creates a Waku Node.
|
## Creates a Waku Node.
|
||||||
@ -171,16 +181,28 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
|||||||
## Initialize addresses
|
## Initialize addresses
|
||||||
let
|
let
|
||||||
# Bind addresses
|
# Bind addresses
|
||||||
hostAddress = tcpEndPoint(bindIp, bindPort)
|
hostAddress = ip4TcpEndPoint(bindIp, bindPort)
|
||||||
wsHostAddress = if wsEnabled or wssEnabled: some(tcpEndPoint(bindIp, wsbindPort) & wsFlag(wssEnabled))
|
wsHostAddress = if wsEnabled or wssEnabled: some(ip4TcpEndPoint(bindIp, wsbindPort) & wsFlag(wssEnabled))
|
||||||
else: none(MultiAddress)
|
else: none(MultiAddress)
|
||||||
|
|
||||||
# External addresses
|
# Setup external addresses, if available
|
||||||
hostExtAddress = if extIp.isNone() or extPort.isNone(): none(MultiAddress)
|
var
|
||||||
else: some(tcpEndPoint(extIp.get(), extPort.get()))
|
hostExtAddress, wsExtAddress = none(MultiAddress)
|
||||||
wsExtAddress = if wsHostAddress.isNone(): none(MultiAddress)
|
|
||||||
elif hostExtAddress.isNone(): none(MultiAddress)
|
if (dns4DomainName.isSome()):
|
||||||
else: some(tcpEndPoint(extIp.get(), wsBindPort) & wsFlag(wssEnabled))
|
# Use dns4 for externally announced addresses
|
||||||
|
|
||||||
|
hostExtAddress = some(dns4TcpEndPoint(dns4DomainName.get(), extPort.get()))
|
||||||
|
|
||||||
|
if (wsHostAddress.isSome()):
|
||||||
|
wsExtAddress = some(dns4TcpEndPoint(dns4DomainName.get(), wsBindPort) & wsFlag(wssEnabled))
|
||||||
|
else:
|
||||||
|
# No public domain name, use ext IP if available
|
||||||
|
if extIp.isSome() and extPort.isSome():
|
||||||
|
hostExtAddress = some(ip4TcpEndPoint(extIp.get(), extPort.get()))
|
||||||
|
|
||||||
|
if (wsHostAddress.isSome()):
|
||||||
|
wsExtAddress = some(ip4TcpEndPoint(extIp.get(), wsBindPort) & wsFlag(wssEnabled))
|
||||||
|
|
||||||
var announcedAddresses: seq[MultiAddress]
|
var announcedAddresses: seq[MultiAddress]
|
||||||
if hostExtAddress.isSome:
|
if hostExtAddress.isSome:
|
||||||
@ -1030,6 +1052,9 @@ when isMainModule:
|
|||||||
else:
|
else:
|
||||||
extTcpPort
|
extTcpPort
|
||||||
|
|
||||||
|
dns4DomainName = if conf.dns4DomainName != "": some(conf.dns4DomainName)
|
||||||
|
else: none(string)
|
||||||
|
|
||||||
wakuFlags = initWakuFlags(conf.lightpush,
|
wakuFlags = initWakuFlags(conf.lightpush,
|
||||||
conf.filter,
|
conf.filter,
|
||||||
conf.store,
|
conf.store,
|
||||||
@ -1046,7 +1071,8 @@ when isMainModule:
|
|||||||
conf.websocketSecureKeyPath,
|
conf.websocketSecureKeyPath,
|
||||||
conf.websocketSecureCertPath,
|
conf.websocketSecureCertPath,
|
||||||
some(wakuFlags),
|
some(wakuFlags),
|
||||||
dnsResolver
|
dnsResolver,
|
||||||
|
dns4DomainName
|
||||||
)
|
)
|
||||||
|
|
||||||
if conf.discv5Discovery:
|
if conf.discv5Discovery:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user