mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
wakucanary maintenance (#3415)
- Add more possible protocols to monitor - Simplify protocol validation simple algorithm - Properly pass the shard CLI parameter to the ENR info - Mount metadata protocol - Properly use of quit(QuitFailure)
This commit is contained in:
parent
d5063e7d89
commit
3bb40d48e3
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
std/[strutils, sequtils, tables],
|
std/[strutils, sequtils, tables, strformat],
|
||||||
confutils,
|
confutils,
|
||||||
chronos,
|
chronos,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
@ -21,6 +21,14 @@ const ProtocolsTable = {
|
|||||||
"relay": "/vac/waku/relay/",
|
"relay": "/vac/waku/relay/",
|
||||||
"lightpush": "/vac/waku/lightpush/",
|
"lightpush": "/vac/waku/lightpush/",
|
||||||
"filter": "/vac/waku/filter-subscribe/2",
|
"filter": "/vac/waku/filter-subscribe/2",
|
||||||
|
"filter-push": "/vac/waku/filter-push/",
|
||||||
|
"ipfs-id": "/ipfs/id/",
|
||||||
|
"autonat": "/libp2p/autonat/",
|
||||||
|
"circuit-relay": "/libp2p/circuit/relay/",
|
||||||
|
"metadata": "/vac/waku/metadata/",
|
||||||
|
"rendezvous": "/rendezvous/",
|
||||||
|
"ipfs-ping": "/ipfs/ping/",
|
||||||
|
"peer-exchange": "/vac/waku/peer-exchange/",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
const WebSocketPortOffset = 1000
|
const WebSocketPortOffset = 1000
|
||||||
@ -105,21 +113,30 @@ proc parseCmdArg*(T: type chronos.Duration, p: string): T =
|
|||||||
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
# checks if rawProtocols (skipping version) are supported in nodeProtocols
|
|
||||||
proc areProtocolsSupported(
|
proc areProtocolsSupported(
|
||||||
rawProtocols: seq[string], nodeProtocols: seq[string]
|
toValidateProtocols: seq[string], nodeProtocols: seq[string]
|
||||||
): bool =
|
): bool =
|
||||||
|
## Checks if all toValidateProtocols are contained in nodeProtocols.
|
||||||
|
## nodeProtocols contains the full list of protocols currently informed by the node under analysis.
|
||||||
|
## toValidateProtocols contains the protocols, without version number, that we want to check if they are supported by the node.
|
||||||
var numOfSupportedProt: int = 0
|
var numOfSupportedProt: int = 0
|
||||||
|
|
||||||
for nodeProtocol in nodeProtocols:
|
for rawProtocol in toValidateProtocols:
|
||||||
for rawProtocol in rawProtocols:
|
let protocolTag = ProtocolsTable[rawProtocol]
|
||||||
let protocolTag = ProtocolsTable[rawProtocol]
|
debug "Checking if protocol is supported", expected_protocol_tag = protocolTag
|
||||||
|
|
||||||
|
var protocolSupported = false
|
||||||
|
for nodeProtocol in nodeProtocols:
|
||||||
if nodeProtocol.startsWith(protocolTag):
|
if nodeProtocol.startsWith(protocolTag):
|
||||||
info "Supported protocol ok", expected = protocolTag, supported = nodeProtocol
|
info "The node supports the protocol", supported_protocol = nodeProtocol
|
||||||
numOfSupportedProt += 1
|
numOfSupportedProt += 1
|
||||||
|
protocolSupported = true
|
||||||
break
|
break
|
||||||
|
|
||||||
if numOfSupportedProt == rawProtocols.len:
|
if not protocolSupported:
|
||||||
|
error "The node does not support the protocol", expected_protocol = protocolTag
|
||||||
|
|
||||||
|
if numOfSupportedProt == toValidateProtocols.len:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -167,7 +184,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
let peerRes = parsePeerInfo(conf.address)
|
let peerRes = parsePeerInfo(conf.address)
|
||||||
if peerRes.isErr():
|
if peerRes.isErr():
|
||||||
error "Couldn't parse 'conf.address'", error = peerRes.error
|
error "Couldn't parse 'conf.address'", error = peerRes.error
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
|
|
||||||
let peer = peerRes.value
|
let peer = peerRes.value
|
||||||
|
|
||||||
@ -202,6 +219,12 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
|
|
||||||
var enrBuilder = EnrBuilder.init(nodeKey)
|
var enrBuilder = EnrBuilder.init(nodeKey)
|
||||||
|
|
||||||
|
enrBuilder.withWakuRelaySharding(
|
||||||
|
RelayShards(clusterId: conf.clusterId, shardIds: conf.shards)
|
||||||
|
).isOkOr:
|
||||||
|
error "could not initialize ENR with shards", error
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
let recordRes = enrBuilder.build()
|
let recordRes = enrBuilder.build()
|
||||||
let record =
|
let record =
|
||||||
if recordRes.isErr():
|
if recordRes.isErr():
|
||||||
@ -217,7 +240,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
createDir(CertsDirectory)
|
createDir(CertsDirectory)
|
||||||
if generateSelfSignedCertificate(certPath, keyPath) != 0:
|
if generateSelfSignedCertificate(certPath, keyPath) != 0:
|
||||||
error "Error generating key and certificate"
|
error "Error generating key and certificate"
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
|
|
||||||
builder.withRecord(record)
|
builder.withRecord(record)
|
||||||
builder.withNetworkConfiguration(netConfig.tryGet())
|
builder.withNetworkConfiguration(netConfig.tryGet())
|
||||||
@ -232,7 +255,11 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
await mountLibp2pPing(node)
|
await mountLibp2pPing(node)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
error "failed to mount libp2p ping protocol: " & getCurrentExceptionMsg()
|
error "failed to mount libp2p ping protocol: " & getCurrentExceptionMsg()
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
|
|
||||||
|
node.mountMetadata(conf.clusterId).isOkOr:
|
||||||
|
error "failed to mount metadata protocol", error
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
await node.start()
|
await node.start()
|
||||||
|
|
||||||
@ -243,7 +270,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
let timedOut = not await node.connectToNodes(@[peer]).withTimeout(conf.timeout)
|
let timedOut = not await node.connectToNodes(@[peer]).withTimeout(conf.timeout)
|
||||||
if timedOut:
|
if timedOut:
|
||||||
error "Timedout after", timeout = conf.timeout
|
error "Timedout after", timeout = conf.timeout
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
|
|
||||||
let lp2pPeerStore = node.switch.peerStore
|
let lp2pPeerStore = node.switch.peerStore
|
||||||
let conStatus = node.peerManager.switch.peerStore[ConnectionBook][peer.peerId]
|
let conStatus = node.peerManager.switch.peerStore[ConnectionBook][peer.peerId]
|
||||||
@ -253,13 +280,14 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
|
|
||||||
if conStatus in [Connected, CanConnect]:
|
if conStatus in [Connected, CanConnect]:
|
||||||
let nodeProtocols = lp2pPeerStore[ProtoBook][peer.peerId]
|
let nodeProtocols = lp2pPeerStore[ProtoBook][peer.peerId]
|
||||||
|
|
||||||
if not areProtocolsSupported(conf.protocols, nodeProtocols):
|
if not areProtocolsSupported(conf.protocols, nodeProtocols):
|
||||||
error "Not all protocols are supported",
|
error "Not all protocols are supported",
|
||||||
expected = conf.protocols, supported = nodeProtocols
|
expected = conf.protocols, supported = nodeProtocols
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
elif conStatus == CannotConnect:
|
elif conStatus == CannotConnect:
|
||||||
error "Could not connect", peerId = peer.peerId
|
error "Could not connect", peerId = peer.peerId
|
||||||
return 1
|
quit(QuitFailure)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user