Skip to content

Commit

Permalink
chore: vendor bump for 0.23.0 (#2274)
Browse files Browse the repository at this point in the history
* on_chain/group_manager: use .async: (raises:[Exception]).
* bump nim-dnsdisc
* update nim-chronos to the latest state
* chat2.nim: catch any possible exception when stopping
* chat2bridge.nim: make it to compile after vendor bump
* ValidIpAddress (deprecated) -> IpAddress
* vendor/nim-libp2p additional bump
* libwaku: adapt to vendor bump
* testlib/wakunode.nim: adapt to vendor bump (ValidIpAddress -> IpAddress)
* waku_node: avoid throwing any exception from stop*(node: WakuNode)
* test_confutils_envvar.nim: ValidIpAddress -> IpAddress
* test_jsonrpc_store: capture exception
* test_rln*: handling exceptions
* adaptation to make test_rln_* to work properly
* signature enhancement of group_manager methods
  • Loading branch information
Ivansete-status committed Dec 14, 2023
1 parent 0cc0c80 commit 385daf1
Show file tree
Hide file tree
Showing 81 changed files with 626 additions and 459 deletions.
7 changes: 5 additions & 2 deletions apps/chat2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ proc readNick(transp: StreamTransport): Future[string] {.async.} =
return await transp.readLine()


proc startMetricsServer(serverIp: ValidIpAddress, serverPort: Port): Result[MetricsHttpServerRef, string] =
proc startMetricsServer(serverIp: IpAddress, serverPort: Port): Result[MetricsHttpServerRef, string] =
info "Starting metrics HTTP server", serverIp= $serverIp, serverPort= $serverPort

let metricsServerRes = MetricsHttpServerRef.new($serverIp, serverPort)
Expand Down Expand Up @@ -269,7 +269,10 @@ proc writeAndPrint(c: Chat) {.async.} =

echo "quitting..."

await c.node.stop()
try:
await c.node.stop()
except:
echo "exception happened when stopping: " & getCurrentExceptionMsg()

quit(QuitSuccess)
else:
Expand Down
24 changes: 12 additions & 12 deletions apps/chat2/config_chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type
listenAddress* {.
defaultValue: defaultListenAddress(config)
desc: "Listening address for the LibP2P traffic."
name: "listen-address"}: ValidIpAddress
name: "listen-address"}: IpAddress

tcpPort* {.
desc: "TCP listening port."
Expand Down Expand Up @@ -135,8 +135,8 @@ type

rpcAddress* {.
desc: "Listening address of the JSON-RPC server.",
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "rpc-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "rpc-address" }: IpAddress

rpcPort* {.
desc: "Listening port of the JSON-RPC server.",
Expand All @@ -162,8 +162,8 @@ type

metricsServerAddress* {.
desc: "Listening address of the metrics server."
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "metrics-server-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "metrics-server-address" }: IpAddress

metricsServerPort* {.
desc: "Listening HTTP port of the metrics server."
Expand All @@ -189,8 +189,8 @@ type

dnsDiscoveryNameServers* {.
desc: "DNS name server IPs to query. Argument may be repeated."
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
name: "dns-discovery-name-server" }: seq[ValidIpAddress]
defaultValue: @[parseIpAddress("1.1.1.1"), parseIpAddress("1.0.0.1")]
name: "dns-discovery-name-server" }: seq[IpAddress]

## Chat2 configuration

Expand Down Expand Up @@ -278,13 +278,13 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
proc parseCmdArg*(T: type IpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
result = parseIpAddress(p)
except CatchableError as e:
raise newException(ValueError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
proc completeCmdArg*(T: type IpAddress, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type Port, p: string): T =
Expand All @@ -302,7 +302,7 @@ proc parseCmdArg*(T: type Option[uint], p: string): T =
except CatchableError:
raise newException(ValueError, "Invalid unsigned integer")

func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
func defaultListenAddress*(conf: Chat2Conf): IpAddress =
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
(static ValidIpAddress.init("0.0.0.0"))
(static parseIpAddress("0.0.0.0"))
22 changes: 13 additions & 9 deletions apps/chat2bridge/chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import
chronos, confutils, chronicles, chronicles/topics_registry, chronos/streams/tlsstream,
metrics, metrics/chronos_httpserver,
stew/byteutils,
stew/shims/net as stewNet, json_rpc/rpcserver,
eth/net/nat,
json_rpc/rpcserver,
# Matterbridge client imports
../../waku/common/utils/matterbridge_client,
# Waku v2 imports
Expand Down Expand Up @@ -51,7 +52,7 @@ type
seen: seq[Hash] #FIFO queue
contentTopic: string

MbMessageHandler* = proc (jsonNode: JsonNode) {.gcsafe.}
MbMessageHandler = proc (jsonNode: JsonNode) {.async.}

###################
# Helper funtions #
Expand Down Expand Up @@ -129,7 +130,7 @@ proc pollMatterbridge(cmb: Chat2MatterBridge, handler: MbMessageHandler) {.async

if getRes.isOk():
for jsonNode in getRes[]:
handler(jsonNode)
await handler(jsonNode)
else:
error "Matterbridge host unreachable. Sleeping before retrying."
await sleepAsync(chronos.seconds(10))
Expand All @@ -145,8 +146,8 @@ proc new*(T: type Chat2MatterBridge,
mbGateway: string,
# NodeV2 initialisation
nodev2Key: crypto.PrivateKey,
nodev2BindIp: ValidIpAddress, nodev2BindPort: Port,
nodev2ExtIp = none[ValidIpAddress](), nodev2ExtPort = none[Port](),
nodev2BindIp: IpAddress, nodev2BindPort: Port,
nodev2ExtIp = none[IpAddress](), nodev2ExtPort = none[Port](),
contentTopic: string): T
{.raises: [Defect, ValueError, KeyError, TLSStreamProtocolError, IOError, LPError].} =

Expand Down Expand Up @@ -183,7 +184,7 @@ proc start*(cmb: Chat2MatterBridge) {.async.} =
debug "Start polling Matterbridge"

# Start Matterbridge polling (@TODO: use streaming interface)
proc mbHandler(jsonNode: JsonNode) {.gcsafe, raises: [Exception].} =
proc mbHandler(jsonNode: JsonNode) {.async.} =
trace "Bridging message from Matterbridge to chat2", jsonNode=jsonNode
waitFor cmb.toChat2(jsonNode)

Expand All @@ -200,13 +201,16 @@ proc start*(cmb: Chat2MatterBridge) {.async.} =

# Bridging
# Handle messages on Waku v2 and bridge to Matterbridge
proc relayHandler(pubsubTopic: PubsubTopic, msg: WakuMessage): Future[void] {.async, gcsafe.} =
proc relayHandler(pubsubTopic: PubsubTopic, msg: WakuMessage): Future[void] {.async.} =
trace "Bridging message from Chat2 to Matterbridge", msg=msg
cmb.toMatterbridge(msg)
try:
cmb.toMatterbridge(msg)
except:
error "exception in relayHandler: " & getCurrentExceptionMsg()

cmb.nodev2.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))

proc stop*(cmb: Chat2MatterBridge) {.async.} =
proc stop*(cmb: Chat2MatterBridge) {.async: (raises: [Exception]).} =
info "Stopping Chat2MatterBridge"

cmb.running = false
Expand Down
24 changes: 12 additions & 12 deletions apps/chat2bridge/config_chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type
listenAddress* {.
defaultValue: defaultListenAddress(config)
desc: "Listening address for the LibP2P traffic"
name: "listen-address"}: ValidIpAddress
name: "listen-address"}: IpAddress

libp2pTcpPort* {.
desc: "Libp2p TCP listening port (for Waku v2)"
Expand Down Expand Up @@ -42,8 +42,8 @@ type

rpcAddress* {.
desc: "Listening address of the RPC server",
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "rpc-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "rpc-address" }: IpAddress

rpcPort* {.
desc: "Listening port of the RPC server"
Expand All @@ -57,8 +57,8 @@ type

metricsServerAddress* {.
desc: "Listening address of the metrics server"
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "metrics-server-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "metrics-server-address" }: IpAddress

metricsServerPort* {.
desc: "Listening HTTP port of the metrics server"
Expand Down Expand Up @@ -109,8 +109,8 @@ type
# Matterbridge options
mbHostAddress* {.
desc: "Listening address of the Matterbridge host",
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "mb-host-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "mb-host-address" }: IpAddress

mbHostPort* {.
desc: "Listening port of the Matterbridge host",
Expand Down Expand Up @@ -149,14 +149,14 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
proc parseCmdArg*(T: type IpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
result = parseIpAddress(p)
except CatchableError:
raise newException(ValueError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
proc completeCmdArg*(T: type IpAddress, val: string): seq[string] =
return @[]

func defaultListenAddress*(conf: Chat2MatterbridgeConf): ValidIpAddress =
(static ValidIpAddress.init("0.0.0.0"))
func defaultListenAddress*(conf: Chat2MatterbridgeConf): IpAddress =
(parseIpAddress("0.0.0.0"))
8 changes: 4 additions & 4 deletions apps/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ proc crawlNetwork(node: WakuNode,

await sleepAsync(crawlInterval.millis - elapsed.millis)

proc retrieveDynamicBootstrapNodes(dnsDiscovery: bool, dnsDiscoveryUrl: string, dnsDiscoveryNameServers: seq[ValidIpAddress]): Result[seq[RemotePeerInfo], string] =
proc retrieveDynamicBootstrapNodes(dnsDiscovery: bool, dnsDiscoveryUrl: string, dnsDiscoveryNameServers: seq[IpAddress]): Result[seq[RemotePeerInfo], string] =
if dnsDiscovery and dnsDiscoveryUrl != "":
# DNS discovery
debug "Discovering nodes using Waku DNS discovery", url=dnsDiscoveryUrl
Expand Down Expand Up @@ -328,7 +328,7 @@ proc retrieveDynamicBootstrapNodes(dnsDiscovery: bool, dnsDiscoveryUrl: string,

proc getBootstrapFromDiscDns(conf: NetworkMonitorConf): Result[seq[enr.Record], string] =
try:
let dnsNameServers = @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
let dnsNameServers = @[parseIpAddress("1.1.1.1"), parseIpAddress("1.0.0.1")]
let dynamicBootstrapNodesRes = retrieveDynamicBootstrapNodes(true, conf.dnsDiscoveryUrl, dnsNameServers)
if not dynamicBootstrapNodesRes.isOk():
error("failed discovering peers from DNS")
Expand All @@ -350,12 +350,12 @@ proc getBootstrapFromDiscDns(conf: NetworkMonitorConf): Result[seq[enr.Record],

proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV5), string] =
let bindIp = try:
ValidIpAddress.init("0.0.0.0")
parseIpAddress("0.0.0.0")
except CatchableError:
return err("could not start node: " & getCurrentExceptionMsg())

let extIp = try:
ValidIpAddress.init("127.0.0.1")
parseIpAddress("127.0.0.1")
except CatchableError:
return err("could not start node: " & getCurrentExceptionMsg())

Expand Down
10 changes: 5 additions & 5 deletions apps/networkmonitor/networkmonitor_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type

metricsServerAddress* {.
desc: "Listening address of the metrics server."
defaultValue: ValidIpAddress.init("127.0.0.1")
name: "metrics-server-address" }: ValidIpAddress
defaultValue: parseIpAddress("127.0.0.1")
name: "metrics-server-address" }: IpAddress

metricsServerPort* {.
desc: "Listening HTTP port of the metrics server."
Expand All @@ -64,13 +64,13 @@ type
defaultValue: 8009,
name: "metrics-rest-port" }: uint16

proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
proc parseCmdArg*(T: type IpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
result = parseIpAddress(p)
except CatchableError as e:
raise newException(ValueError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
proc completeCmdArg*(T: type IpAddress, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type chronos.Duration, p: string): T =
Expand Down
2 changes: 1 addition & 1 deletion apps/networkmonitor/networkmonitor_metrics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proc installHandler*(router: var RestRouter,
# TODO: toJson() includes the hash
return RestApiResponse.response($(%numMessagesPerContentTopic), contentType="application/json")

proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port): Result[void, string] =
proc startMetricsServer*(serverIp: IpAddress, serverPort: Port): Result[void, string] =
info "Starting metrics HTTP server", serverIp, serverPort

try:
Expand Down
6 changes: 3 additions & 3 deletions apps/wakucanary/wakucanary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
# create dns resolver
let
nameServers = @[
initTAddress(ValidIpAddress.init("1.1.1.1"), Port(53)),
initTAddress(ValidIpAddress.init("1.0.0.1"), Port(53))]
initTAddress(parseIpAddress("1.1.1.1"), Port(53)),
initTAddress(parseIpAddress("1.0.0.1"), Port(53))]
resolver: DnsResolver = DnsResolver.new(nameServers)

if conf.logLevel != LogLevel.NONE:
Expand All @@ -149,7 +149,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =

let
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
bindIp = ValidIpAddress.init("0.0.0.0")
bindIp = parseIpAddress("0.0.0.0")
wsBindPort = Port(conf.nodePort + WebSocketPortOffset)
nodeTcpPort = Port(conf.nodePort)
isWs = peer.addrs[0].contains(multiCodec("ws")).get()
Expand Down
13 changes: 8 additions & 5 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ proc setupPeerPersistence*(app: var App): AppResult[void] =

## Retrieve dynamic bootstrap nodes (DNS discovery)

proc retrieveDynamicBootstrapNodes*(dnsDiscovery: bool, dnsDiscoveryUrl: string, dnsDiscoveryNameServers: seq[ValidIpAddress]): AppResult[seq[RemotePeerInfo]] =
proc retrieveDynamicBootstrapNodes*(dnsDiscovery: bool,
dnsDiscoveryUrl: string,
dnsDiscoveryNameServers: seq[IpAddress]):
AppResult[seq[RemotePeerInfo]] =

if dnsDiscovery and dnsDiscoveryUrl != "":
# DNS discovery
Expand Down Expand Up @@ -647,7 +650,7 @@ proc startApp*(app: var App): AppResult[void] =

## Monitoring and external interfaces

proc startRestServer(app: App, address: ValidIpAddress, port: Port, conf: WakuNodeConf): AppResult[RestServerRef] =
proc startRestServer(app: App, address: IpAddress, port: Port, conf: WakuNodeConf): AppResult[RestServerRef] =

# Used to register api endpoints that are not currently installed as keys,
# values are holding error messages to be returned to the client
Expand Down Expand Up @@ -752,7 +755,7 @@ proc startRestServer(app: App, address: ValidIpAddress, port: Port, conf: WakuNo

ok(server)

proc startRpcServer(app: App, address: ValidIpAddress, port: Port, conf: WakuNodeConf): AppResult[RpcHttpServer] =
proc startRpcServer(app: App, address: IpAddress, port: Port, conf: WakuNodeConf): AppResult[RpcHttpServer] =
let ta = initTAddress(address, port)

var server: RpcHttpServer
Expand Down Expand Up @@ -792,7 +795,7 @@ proc startRpcServer(app: App, address: ValidIpAddress, port: Port, conf: WakuNod

ok(server)

proc startMetricsServer(serverIp: ValidIpAddress, serverPort: Port): AppResult[MetricsHttpServerRef] =
proc startMetricsServer(serverIp: IpAddress, serverPort: Port): AppResult[MetricsHttpServerRef] =
info "Starting metrics HTTP server", serverIp= $serverIp, serverPort= $serverPort

let metricsServerRes = MetricsHttpServerRef.new($serverIp, serverPort)
Expand Down Expand Up @@ -845,7 +848,7 @@ proc setupMonitoringAndExternalInterfaces*(app: var App): AppResult[void] =

# App shutdown

proc stop*(app: App): Future[void] {.async.} =
proc stop*(app: App): Future[void] {.async: (raises: [Exception]).} =
if app.restServer.isSome():
await app.restServer.get().stop()

Expand Down
Loading

0 comments on commit 385daf1

Please sign in to comment.