mirror of https://github.com/waku-org/nwaku.git
Publish multiple address when websocket enabled. (#766)
* publish multiple nodes Signed-off-by: rshiv <reeshav96@gmail.com> * Print multiple addresses if wsenabled Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review comment fix Signed-off-by: rshiv <reeshav96@gmail.com> * review changes Signed-off-by: rshiv <reeshav96@gmail.com> * review changes Signed-off-by: rshiv <reeshav96@gmail.com> * code review changes Signed-off-by: rshiv <reeshav96@gmail.com> * review comments Signed-off-by: rshiv <reeshav96@gmail.com> * review fixes Signed-off-by: rshiv <reeshav96@gmail.com> * websocket address fix Signed-off-by: rshiv <reeshav96@gmail.com>
This commit is contained in:
parent
067478d725
commit
6cad482ca6
|
@ -55,6 +55,7 @@ const clientId* = "Nimbus Waku v2 node"
|
||||||
# Default topic
|
# Default topic
|
||||||
const defaultTopic = "/waku/2/default-waku/proto"
|
const defaultTopic = "/waku/2/default-waku/proto"
|
||||||
|
|
||||||
|
|
||||||
# key and crypto modules different
|
# key and crypto modules different
|
||||||
type
|
type
|
||||||
KeyPair* = crypto.KeyPair
|
KeyPair* = crypto.KeyPair
|
||||||
|
@ -87,6 +88,7 @@ type
|
||||||
filters*: Filters
|
filters*: Filters
|
||||||
rng*: ref BrHmacDrbgContext
|
rng*: ref BrHmacDrbgContext
|
||||||
wakuDiscv5*: WakuDiscoveryV5
|
wakuDiscv5*: WakuDiscoveryV5
|
||||||
|
announcedAddresses* : seq[MultiAddress]
|
||||||
started*: bool # Indicates that node has started listening
|
started*: bool # Indicates that node has started listening
|
||||||
|
|
||||||
proc protocolMatcher(codec: string): Matcher =
|
proc protocolMatcher(codec: string): Matcher =
|
||||||
|
@ -168,8 +170,9 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||||
enrTcpPort = if extPort.isSome(): extPort
|
enrTcpPort = if extPort.isSome(): extPort
|
||||||
else: some(bindPort)
|
else: some(bindPort)
|
||||||
enr = createEnr(nodeKey, enrIp, enrTcpPort, none(Port))
|
enr = createEnr(nodeKey, enrIp, enrTcpPort, none(Port))
|
||||||
|
|
||||||
|
|
||||||
if wsEnabled == true or wssEnabled == true:
|
if wsEnabled or wssEnabled:
|
||||||
info "Initializing networking", hostAddress, wsHostAddress,
|
info "Initializing networking", hostAddress, wsHostAddress,
|
||||||
announcedAddresses
|
announcedAddresses
|
||||||
peerInfo.addrs.add(wsHostAddress)
|
peerInfo.addrs.add(wsHostAddress)
|
||||||
|
@ -178,7 +181,7 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||||
|
|
||||||
peerInfo.addrs.add(hostAddress)
|
peerInfo.addrs.add(hostAddress)
|
||||||
for multiaddr in announcedAddresses:
|
for multiaddr in announcedAddresses:
|
||||||
peerInfo.addrs.add(multiaddr) # Announced addresses in index > 0
|
peerInfo.addrs.add(multiaddr)
|
||||||
|
|
||||||
var switch = newWakuSwitch(some(nodekey),
|
var switch = newWakuSwitch(some(nodekey),
|
||||||
hostAddress,
|
hostAddress,
|
||||||
|
@ -194,10 +197,11 @@ proc new*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||||
let wakuNode = WakuNode(
|
let wakuNode = WakuNode(
|
||||||
peerManager: PeerManager.new(switch, peerStorage),
|
peerManager: PeerManager.new(switch, peerStorage),
|
||||||
switch: switch,
|
switch: switch,
|
||||||
rng: rng,
|
rng: rng,
|
||||||
peerInfo: peerInfo,
|
peerInfo: peerInfo,
|
||||||
enr: enr,
|
enr: enr,
|
||||||
filters: initTable[string, Filter]()
|
filters: initTable[string, Filter](),
|
||||||
|
announcedAddresses: announcedAddresses
|
||||||
)
|
)
|
||||||
|
|
||||||
return wakuNode
|
return wakuNode
|
||||||
|
@ -814,7 +818,11 @@ proc start*(node: WakuNode) {.async.} =
|
||||||
# TODO Get this from WakuNode obj
|
# TODO Get this from WakuNode obj
|
||||||
let peerInfo = node.peerInfo
|
let peerInfo = node.peerInfo
|
||||||
info "PeerInfo", peerId = peerInfo.peerId, addrs = peerInfo.addrs
|
info "PeerInfo", peerId = peerInfo.peerId, addrs = peerInfo.addrs
|
||||||
let listenStr = $peerInfo.addrs[^1] & "/p2p/" & $peerInfo.peerId
|
var listenStr = ""
|
||||||
|
for address in node.announcedAddresses:
|
||||||
|
var fulladdr = "[" & $address & "/p2p/" & $peerInfo.peerId & "]"
|
||||||
|
listenStr &= fulladdr
|
||||||
|
|
||||||
## XXX: this should be /ip4..., / stripped?
|
## XXX: this should be /ip4..., / stripped?
|
||||||
info "Listening on", full = listenStr
|
info "Listening on", full = listenStr
|
||||||
info "Discoverable ENR ", enr = node.enr.toURI()
|
info "Discoverable ENR ", enr = node.enr.toURI()
|
||||||
|
@ -1046,9 +1054,9 @@ when isMainModule:
|
||||||
## Resume history, connect to static nodes and start
|
## Resume history, connect to static nodes and start
|
||||||
## keep-alive, if configured.
|
## keep-alive, if configured.
|
||||||
|
|
||||||
# Start Waku v2 node
|
# Start Waku v2 node
|
||||||
waitFor node.start()
|
waitFor node.start()
|
||||||
|
|
||||||
# Resume historical messages, this has to be called after the node has been started
|
# Resume historical messages, this has to be called after the node has been started
|
||||||
if conf.store and conf.persistMessages:
|
if conf.store and conf.persistMessages:
|
||||||
waitFor node.resume()
|
waitFor node.resume()
|
||||||
|
|
|
@ -90,7 +90,7 @@ proc newWakuSwitch*(
|
||||||
if wsEnabled == true:
|
if wsEnabled == true:
|
||||||
b = b.withAddresses(@[wsAddress, address])
|
b = b.withAddresses(@[wsAddress, address])
|
||||||
b = b.withWsTransport()
|
b = b.withWsTransport()
|
||||||
if wssEnabled == true:
|
elif wssEnabled == true:
|
||||||
b = b.withAddresses(@[wsAddress, address])
|
b = b.withAddresses(@[wsAddress, address])
|
||||||
b = b.withWssTransport(secureKeyPath, secureCertPath)
|
b = b.withWssTransport(secureKeyPath, secureCertPath)
|
||||||
else :
|
else :
|
||||||
|
|
Loading…
Reference in New Issue