Properly exit when address is already in use, fix #15 (#108)

This commit is contained in:
Kim De Mey 2020-08-27 04:44:52 +02:00 committed by GitHub
parent 0e62e8ffa4
commit e875dfd1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import
confutils, chronicles, chronos, stew/byteutils,
eth/[keys, p2p, async_utils],
eth/[keys, p2p],
../../waku/protocol/v1/waku_protocol,
../../waku/node/v1/waku_helpers,
./config_example
@ -47,12 +47,18 @@ if config.staticnodes.len > 0:
# connect to bootnodes, and/or start discovery.
# This will block until first connection is made, which in this case can only
# happen if we directly connect to nodes (step above) or if an incoming
# connection occurs, which is why we use `traceAsyncErrors` instead of `await`.
# connection occurs, which is why we use a callback to exit on errors instead of
# using `await`.
# TODO: This looks a bit awkward and the API should perhaps be altered here.
traceAsyncErrors node.connectToNetwork(@[],
let connectedFut = node.connectToNetwork(@[],
true, # Enable listening
false # Disable discovery (only discovery v4 is currently supported)
)
connectedFut.callback = proc(data: pointer) {.gcsafe.} =
{.gcsafe.}:
if connectedFut.failed:
fatal "connectToNetwork failed", msg = connectedFut.readError.msg
quit(1)
# Using a hardcoded symmetric key for encryption of the payload for the sake of
# simplicity.

View File

@ -1,7 +1,7 @@
import
std/strutils,
confutils, chronos, json_rpc/rpcserver, metrics, metrics/chronicles_support,
eth/[keys, p2p, async_utils], eth/common/utils,
eth/[keys, p2p], eth/common/utils,
eth/p2p/[discovery, enode, peer_pool, bootnodes, whispernodes],
eth/p2p/rlpx_protocols/whisper_protocol,
../../protocol/v1/[waku_protocol, waku_bridge],
@ -46,8 +46,13 @@ proc run(config: WakuNodeConf, rng: ref BrHmacDrbgContext) =
elif config.fleet == test : setBootNodes(StatusBootNodesTest)
else: @[]
traceAsyncErrors node.connectToNetwork(bootnodes, not config.noListen,
let connectedFut = node.connectToNetwork(bootnodes, not config.noListen,
config.discovery)
connectedFut.callback = proc(data: pointer) {.gcsafe.} =
{.gcsafe.}:
if connectedFut.failed:
fatal "connectToNetwork failed", msg = connectedFut.readError.msg
quit(1)
if not config.bootnodeOnly:
# Optionally direct connect with a set of nodes