Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nim-waku config inconsistencies #543

Merged
merged 4 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions examples/v2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,24 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
(extIp, extTcpPort, extUdpPort) = setupNat(conf.nat, clientId,
Port(uint16(conf.tcpPort) + conf.portsShift),
Port(uint16(conf.udpPort) + conf.portsShift))
node = WakuNode.init(conf.nodeKey, conf.listenAddress,
node = WakuNode.init(conf.nodekey_depr, conf.listenAddress, # @TODO remove deprecated config item
Port(uint16(conf.tcpPort) + conf.portsShift), extIp, extTcpPort)

await node.start()

if conf.filternode != "":
node.mountRelay(conf.topics.split(" "), rlnRelayEnabled = conf.rlnrelay, keepAlive = conf.keepAlive)
node.mountRelay(conf.topics.split(" "), rlnRelayEnabled = (conf.rlnrelay_depr or conf.rlnRelay), keepAlive = conf.keepAlive) # @TODO remove deprecated config item
else:
node.mountRelay(@[], rlnRelayEnabled = conf.rlnrelay, keepAlive = conf.keepAlive)
node.mountRelay(@[], rlnRelayEnabled = (conf.rlnrelay_depr or conf.rlnRelay), keepAlive = conf.keepAlive) # @TODO remove deprecated config item

let nick = await readNick(transp)
echo "Welcome, " & nick & "!"

var chat = Chat(node: node, transp: transp, subscribed: true, connected: false, started: true, nick: nick, prompt: false)

if conf.staticnodes.len > 0:
if conf.staticnodes_depr.len > 0: # @TODO remove deprecated config item
await connectToNodes(chat, conf.staticnodes_depr)
elif conf.staticnodes.len > 0:
await connectToNodes(chat, conf.staticnodes)
else:
# Connect to at least one random fleet node
Expand All @@ -277,7 +279,7 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
node.mountSwap()

if (conf.storenode != "") or (conf.store == true):
node.mountStore(persistMessages = conf.persistmessages)
node.mountStore(persistMessages = conf.persistMessages)

var storenode: string

Expand Down
6 changes: 4 additions & 2 deletions examples/v2/matterbridge/chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ when isMainModule:
bridge = Chat2Matterbridge.new(
mbHostUri = "http://" & $initTAddress(conf.mbHostAddress, Port(conf.mbHostPort)),
mbGateway = conf.mbGateway,
nodev2Key = conf.nodekey,
nodev2Key = conf.nodekey_depr, # @TODO remove deprecated config item
nodev2BindIp = conf.listenAddress, nodev2BindPort = Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
nodev2ExtIp = nodev2ExtIp, nodev2ExtPort = nodev2ExtPort)

Expand All @@ -247,7 +247,9 @@ when isMainModule:
if conf.filter:
mountFilter(bridge.nodev2)

if conf.staticnodes.len > 0:
if conf.staticnodes_depr.len > 0: # @TODO remove deprecated config item
waitFor connectToNodes(bridge.nodev2, conf.staticnodes_depr)
elif conf.staticnodes.len > 0:
waitFor connectToNodes(bridge.nodev2, conf.staticnodes)

if conf.storenode != "":
Expand Down
15 changes: 13 additions & 2 deletions examples/v2/matterbridge/config_chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,25 @@ type
name: "metrics-server-port" .}: uint16

### Waku v2 options
staticnodes* {.
# @TODO: deprecate this item. Name changed from `staticnode` -> `staticnodes`
staticnodes_depr* {.
desc: "Multiaddr of peer to directly connect with. Argument may be repeated"
name: "staticnode" }: seq[string]

staticnodes* {.
desc: "Multiaddr of peer to directly connect with. Argument may be repeated"
name: "staticnodes" }: seq[string]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this singular typically because of the way it works in confutils. At CLI it expects the usage as such --staticnode:... --staticnode:... for multiple staticnodes.
The actual variable can be plural as it holds the full provided list in a seq.
So to me it makes more sense like this from a UX PoV. It would be different when the CLI would expect a comma separated list. I've seen some users making that error in the past actually, trying to provide the comma separated list when it was called --staticnodes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. As long as --help clearly indicates that it can be used multiple times.

It would also match how flags like these are named in Nimbus:
https://github.com/status-im/nimbus-eth2/blob/e1a8049e/beacon_chain/conf.nim#L109-L111
https://github.com/status-im/nimbus-eth2/blob/e1a8049e/beacon_chain/conf.nim#L314-L316


nodekey* {.
# @TODO: deprecate this item. Name changed from `nodekey` -> `node-key`
nodekey_depr* {.
desc: "P2P node private key as hex"
defaultValue: crypto.PrivateKey.random(Secp256k1, newRng()[]).tryGet()
name: "nodekey" }: crypto.PrivateKey

nodeKey* {.
desc: "P2P node private key as hex"
defaultValue: crypto.PrivateKey.random(Secp256k1, newRng()[]).tryGet()
name: "node-key" }: crypto.PrivateKey

topics* {.
desc: "Default topics to subscribe to (space separated list)"
Expand Down
44 changes: 34 additions & 10 deletions waku/common/config_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,64 @@ type
name: "metrics-server-port" .}: uint16

### Waku v1 options
fleetv1* {.
# @TODO: deprecate this item. Name changed from `fleetv1` -> `fleet-v1`
fleetv1_depr* {.
desc: "Select the Waku v1 fleet to connect to"
defaultValue: FleetV1.none
name: "fleetv1" .}: FleetV1

fleetV1* {.
desc: "Select the Waku v1 fleet to connect to"
defaultValue: FleetV1.none
name: "fleet-v1" .}: FleetV1

staticnodesv1* {.
# @TODO: deprecate this item. Name changed from `staticnodev1` -> `staticnodes-v1`
staticnodesv1_depr* {.
desc: "Enode URL to directly connect with. Argument may be repeated"
name: "staticnodev1" .}: seq[string]

staticnodesV1* {.
desc: "Enode URL to directly connect with. Argument may be repeated"
name: "staticnodes-v1" .}: seq[string]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem above


nodekeyv1* {.
# @TODO: deprecate this item. Name changed from `nodekeyv1` -> `node-key-v1`
nodekeyv1_depr* {.
desc: "DevP2P node private key as hex",
# TODO: can the rng be passed in somehow via Load?
defaultValue: keys.KeyPair.random(keys.newRng()[])
name: "nodekeyv1" .}: keys.KeyPair

nodeKeyV1* {.
desc: "DevP2P node private key as hex",
# TODO: can the rng be passed in somehow via Load?
defaultValue: keys.KeyPair.random(keys.newRng()[])
name: "node-key-v1" .}: keys.KeyPair

wakuPow* {.
desc: "PoW requirement of Waku node.",
defaultValue: 0.002
name: "waku-pow" .}: float64

### Waku v2 options
staticnodesv2* {.
# @TODO: deprecate this item. Name changed from `staticnodev2` -> `staticnodes-v2`
staticnodesv2_depr* {.
desc: "Multiaddr of peer to directly connect with. Argument may be repeated"
name: "staticnodev2" }: seq[string]

staticnodesV2* {.
desc: "Multiaddr of peer to directly connect with. Argument may be repeated"
name: "staticnodes-v2" }: seq[string]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


nodekeyv2* {.
# @TODO: deprecate this item. Name changed from `nodekeyv2` -> `node-key-v2`
nodekeyv2_depr* {.
desc: "P2P node private key as hex"
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
name: "nodekeyv2" }: crypto.PrivateKey

nodeKeyV2* {.
desc: "P2P node private key as hex"
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
name: "node-key-v2" }: crypto.PrivateKey

topics* {.
desc: "Default topics to subscribe to (space separated list)"
Expand All @@ -116,11 +145,6 @@ type
desc: "Flag whether to start store protocol",
defaultValue: true
name: "store" }: bool

persistmessages* {.
desc: "Enable message persistence: true|false",
defaultValue: false
name: "persist-messages" }: bool

filter* {.
desc: "Flag whether to start filter protocol",
Expand Down
26 changes: 17 additions & 9 deletions waku/common/wakubridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,40 @@ when isMainModule:
Port(uint16(conf.udpPort) + conf.portsShift))

let
bridge = WakuBridge.new(nodev1Key = conf.nodekeyv1,
bridge = WakuBridge.new(nodev1Key = conf.nodekeyv1_depr, # @TODO remove deprecated config item
nodev1Address = nodev1Address,
powRequirement = conf.wakuPow,
rng = rng,
nodev2Key = conf.nodeKeyv2,
nodev2Key = conf.nodekeyv2_depr, # @TODO remove deprecated config item
nodev2BindIp = conf.listenAddress, nodev2BindPort = Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
nodev2ExtIp = nodev2ExtIp, nodev2ExtPort = nodev2ExtPort)

waitFor bridge.start()

# Now load rest of config
# Optionally direct connect nodev1 with a set of nodes
if conf.staticnodesv1.len > 0: connectToNodes(bridge.nodev1, conf.staticnodesv1)
elif conf.fleetv1 == prod: connectToNodes(bridge.nodev1, WhisperNodes)
elif conf.fleetv1 == staging: connectToNodes(bridge.nodev1, WhisperNodesStaging)
elif conf.fleetv1 == test: connectToNodes(bridge.nodev1, WhisperNodesTest)
# @TODO remove deprecated config items
if conf.staticnodesv1_depr.len > 0: connectToNodes(bridge.nodev1, conf.staticnodesv1_depr)
elif conf.fleetv1_depr == prod: connectToNodes(bridge.nodev1, WhisperNodes)
elif conf.fleetv1_depr == staging: connectToNodes(bridge.nodev1, WhisperNodesStaging)
elif conf.fleetv1_depr == test: connectToNodes(bridge.nodev1, WhisperNodesTest)

if conf.staticnodesV1.len > 0: connectToNodes(bridge.nodev1, conf.staticnodesV1)
elif conf.fleetV1 == prod: connectToNodes(bridge.nodev1, WhisperNodes)
elif conf.fleetV1 == staging: connectToNodes(bridge.nodev1, WhisperNodesStaging)
elif conf.fleetV1 == test: connectToNodes(bridge.nodev1, WhisperNodesTest)

# Mount configured Waku v2 protocols
if conf.store:
mountStore(bridge.nodev2, persistMessages = conf.persistmessages)
mountStore(bridge.nodev2, persistMessages = false) # Bridge does not persist messages

if conf.filter:
mountFilter(bridge.nodev2)

if conf.staticnodesv2.len > 0:
waitFor connectToNodes(bridge.nodev2, conf.staticnodesv2)
if conf.staticnodesv2_depr.len > 0: # @TODO remove deprecated config item
waitFor connectToNodes(bridge.nodev2, conf.staticnodesv2_depr)
elif conf.staticnodesV2.len > 0:
waitFor connectToNodes(bridge.nodev2, conf.staticnodesV2)

if conf.storenode != "":
setStorePeer(bridge.nodev2, conf.storenode)
Expand Down
Loading