From 19dd011711207484e7668cbb6a4b43b9140b8723 Mon Sep 17 00:00:00 2001 From: fryorcraken Date: Fri, 11 Apr 2025 20:11:00 +1000 Subject: [PATCH] wakunode2 compiles --- apps/networkmonitor/networkmonitor.nim | 2 +- tests/factory/test_waku_conf.nim | 21 - waku/factory/external_config.nim | 514 +++++-------------------- waku/factory/internal_config.nim | 65 ++-- waku/factory/node_factory.nim | 27 +- waku/factory/waku.nim | 13 +- waku/factory/waku_conf.nim | 40 +- waku/factory/waku_conf_builder.nim | 139 ++++--- 8 files changed, 243 insertions(+), 578 deletions(-) diff --git a/apps/networkmonitor/networkmonitor.nim b/apps/networkmonitor/networkmonitor.nim index 2861c85ae..10af3506c 100644 --- a/apps/networkmonitor/networkmonitor.nim +++ b/apps/networkmonitor/networkmonitor.nim @@ -462,7 +462,7 @@ proc initAndStartApp( nodeBuilder.withNodeKey(key) nodeBuilder.withRecord(record) - nodeBUilder.withSwitchConfiguration(maxConnections = some(MaxConnectedPeers)) + nodeBuilder.withSwitchConfiguration(maxConnections = some(MaxConnectedPeers)) nodeBuilder.withPeerManagerConfig( maxConnections = MaxConnectedPeers, diff --git a/tests/factory/test_waku_conf.nim b/tests/factory/test_waku_conf.nim index 36e8aa9e9..1b9ca98eb 100644 --- a/tests/factory/test_waku_conf.nim +++ b/tests/factory/test_waku_conf.nim @@ -18,8 +18,6 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) - builder.withMaxConnections(10) builder.discv5Conf.withUdpPort(9000) builder.withRelayServiceRatio("50:50") # Mount all shards in network @@ -63,8 +61,6 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") builder.discv5Conf.withUdpPort(9000) # Mount all shards in network @@ -98,8 +94,6 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") builder.discv5Conf.withUdpPort(9000) @@ -134,9 +128,7 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) builder.discv5Conf.withUdpPort(9000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") let shards = @[2.uint16, 3.uint16] @@ -166,9 +158,7 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) builder.discv5Conf.withUdpPort(9000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") let shards = @[2.uint16, 10.uint16] @@ -189,9 +179,7 @@ suite "Waku Conf - build with cluster conf": ## Setup let clusterConf = ClusterConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.withP2pTcpPort(60000) builder.discv5Conf.withUdpPort(9000) - builder.withMaxConnections(10) builder.rlnRelayConf.withEthClientAddress("https://my_eth_rpc_url/") builder.withRelayServiceRatio("50:50") @@ -237,10 +225,7 @@ suite "Waku Conf - node key": ## Setup var builder = WakuConfBuilder.init() builder.withClusterId(1) - builder.withMaxMessageSizeBytes(1) - builder.withP2pTcpPort(60000) builder.discv5Conf.withUdpPort(9000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") ## Given @@ -264,9 +249,6 @@ suite "Waku Conf - node key": crypto.PrivateKey(scheme: Secp256k1, skkey: key) var builder = WakuConfBuilder.init() builder.withClusterId(1) - builder.withMaxMessageSizeBytes(1) - builder.withP2pTcpPort(60000) - builder.withMaxConnections(10) builder.discv5Conf.withUdpPort(9000) builder.withRelayServiceRatio("50:50") @@ -289,10 +271,7 @@ suite "Waku Conf - extMultiaddrs": ## Setup var builder = WakuConfBuilder.init() builder.withClusterId(1) - builder.withMaxMessageSizeBytes(1) - builder.withP2pTcpPort(60000) builder.discv5Conf.withUdpPort(9000) - builder.withMaxConnections(10) builder.withRelayServiceRatio("50:50") ## Given diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index 0d02a4a6b..228eee993 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -306,18 +306,6 @@ hence would have reachability issues.""", name: "rln-relay-dynamic" .}: bool - rlnRelayIdKey* {. - desc: "Rln relay identity secret key as a Hex string", - defaultValue: "", - name: "rln-relay-id-key" - .}: string - - rlnRelayIdCommitmentKey* {. - desc: "Rln relay identity commitment key as a Hex string", - defaultValue: "", - name: "rln-relay-id-commitment-key" - .}: string - rlnRelayTreePath* {. desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)", defaultValue: "", @@ -912,13 +900,22 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = b.withLogLevel(n.logLevel) b.withLogFormat(n.logFormat) - b.rlnRelayConf.withCredPath(n.rlnRelayCredPath) - b.rlnRelayConf.withEthClientAddress(n.rlnRelayEthClientAddress.string) - b.rlnRelayConf.withEthContractAddress(n.rlnRelayEthContractAddress) - b.rlnRelayConf.withChainId(n.rlnRelayChainId) - b.rlnRelayConf.withCredPassword(n.rlnRelayCredPassword) - b.rlnRelayConf.withUserMessageLimit(n.rlnRelayUserMessageLimit) - b.rlnRelayConf.withEpochSizeSec(n.rlnEpochSizeSec) + if n.rlnRelay: + b.rlnRelayConf.withEnabled(n.rlnRelay) + b.rlnRelayConf.withCredPath(n.rlnRelayCredPath) + b.rlnRelayConf.withEthClientAddress(n.rlnRelayEthClientAddress.string) + b.rlnRelayConf.withEthContractAddress(n.rlnRelayEthContractAddress) + b.rlnRelayConf.withChainId(n.rlnRelayChainId) + b.rlnRelayConf.withCredPassword(n.rlnRelayCredPassword) + b.rlnRelayConf.withUserMessageLimit(n.rlnRelayUserMessageLimit) + b.rlnRelayConf.withEpochSizeSec(n.rlnEpochSizeSec) + + if n.rlnRelayCredIndex.isSome(): + b.rlnRelayConf.withCredIndex(n.rlnRelayCredIndex.get()) + + b.rlnRelayConf.withDynamic(n.rlnRelayDynamic) + b.rlnRelayConf.withTreePath(n.rlnRelayTreePath) + b.withMaxMessageSize(n.maxMessageSize) b.withProtectedShards(n.protectedShards) b.withClusterId(n.clusterId) @@ -945,430 +942,93 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = b.withRelayServiceRatio(n.relayServiceRatio) b.withColocationLimit(n.colocationLimit) - b.withPeerStoreCapacity(n.peerStoreCapacity) - b.peerPersistence(n.peerPersistence) + + if n.peerStoreCapacity.isSome: + b.withPeerStoreCapacity(n.peerStoreCapacity.get()) + + b.withPeerPersistence(n.peerPersistence) b.withDnsAddrs(n.dnsAddrs) b.withDnsAddrsNameServers(n.dnsAddrsNameServers) - b.withDns4DomainNanme(n.dns4DomainName) + b.withDns4DomainName(n.dns4DomainName) b.withCircuitRelayClient(n.isRelayClient) b.withRelay(n.relay) b.withRelayPeerExchange(n.relayPeerExchange) + b.withRelayShardedPeerManagement(n.relayShardedPeerManagement) + b.withStaticNodes(n.staticNodes) + b.withKeepAlive(n.keepAlive) + b.withNumShardsInNetwork(n.numShardsInNetwork) + b.withShards(n.shards) + b.withContentTopics(n.contentTopics) - # relayShardedPeerManagement* {. - # desc: - # "Enable experimental shard aware peer manager for relay protocol: true|false", - # defaultValue: false, - # name: "relay-shard-manager" - # .}: bool + if n.store: + b.storeServiceConf.withEnabled(n.store) + b.storeServiceConf.withLegacy(n.legacyStore) + b.storeServiceConf.withRetentionPolicy(n.storeMessageRetentionPolicy) + b.storeServiceConf.withDbUrl(n.storeMessageDbUrl) + b.storeServiceConf.withDbVacuum(n.storeMessageDbVacuum) + b.storeServiceConf.withDbMigration(n.storeMessageDbMigration) + b.storeServiceConf.withMaxNumDbConnections(n.storeMaxNumDbConnections) + b.storeServiceConf.withResume(n.storeResume) - # rlnRelay* {. - # desc: "Enable spam protection through rln-relay: true|false.", - # defaultValue: false, - # name: "rln-relay" - # .}: bool + b.withRemoteStoreNode(n.storenode) + b.withRemoteFilterNode(n.filternode) + b.withRemoteLightPushNode(n.lightpushnode) - # rlnRelayCredIndex* {. - # desc: "the index of the onchain commitment to use", - # name: "rln-relay-membership-index" - # .}: Option[uint] + if n.storeSync: + b.storeServiceConf.storeSyncConf.withEnabled(n.storeSync) + b.storeServiceConf.storeSyncConf.withIntervalSec(n.storeSyncInterval) + b.storeServiceConf.storeSyncConf.withRangeSec(n.storeSyncRange) + b.storeServiceConf.storeSyncConf.withRelayJitterSec(n.storeSyncRelayJitter) - # rlnRelayDynamic* {. - # desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false.", - # defaultValue: false, - # name: "rln-relay-dynamic" - # .}: bool + if n.filter: + b.filterServiceConf.withEnabled(n.filter) + b.filterServiceConf.withSubscriptionTimeout(n.filterSubscriptionTimeout) + b.filterServiceConf.withMaxPeersToServe(n.filterMaxPeersToServe) + b.filterServiceConf.withMaxCriteria(n.filterMaxCriteria) - # rlnRelayIdKey* {. - # desc: "Rln relay identity secret key as a Hex string", - # defaultValue: "", - # name: "rln-relay-id-key" - # .}: string + b.withLightPush(n.lightpush) + b.withP2pReliability(n.reliabilityEnabled) - # rlnRelayIdCommitmentKey* {. - # desc: "Rln relay identity commitment key as a Hex string", - # defaultValue: "", - # name: "rln-relay-id-commitment-key" - # .}: string + if n.rest: + b.restServerConf.withEnabled(n.rest) + b.restServerConf.withListenAddress(n.restAddress) + b.restServerConf.withPort(n.restPort) + b.restServerConf.withRelayCacheCapacity(n.restRelayCacheCapacity) + b.restServerConf.withAdmin(n.restAdmin) + b.restServerConf.withAllowOrigin(n.restAllowOrigin) - # rlnRelayTreePath* {. - # desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)", - # defaultValue: "", - # name: "rln-relay-tree-path" - # .}: string + if n.metricsServer: + b.metricsServerConf.withEnabled(n.metricsServer) + b.metricsServerConf.withHttpAddress(n.metricsServerAddress) + b.metricsServerConf.withHttpPort(n.metricsServerPort) + b.metricsServerConf.withLogging(n.metricsLogging) - # staticnodes* {. - # desc: "Peer multiaddr to directly connect with. Argument may be repeated.", - # name: "staticnode" - # .}: seq[string] + if n.dnsDiscovery: + b.dnsDiscoveryConf.withEnabled(n.dnsDiscovery) + b.dnsDiscoveryConf.withEnrTreeUrl(n.dnsDiscoveryUrl) + b.dnsDiscoveryConf.withNameServers(n.dnsDiscoveryNameServers) - # keepAlive* {. - # desc: "Enable keep-alive for idle connections: true|false", - # defaultValue: false, - # name: "keep-alive" - # .}: bool + if n.discv5Discovery: + b.discv5Conf.withEnabled(n.discv5Discovery) + b.discv5Conf.withUdpPort(n.discv5UdpPort) + b.discv5Conf.withBootstrapNodes(n.discv5BootstrapNodes) + b.discv5Conf.withEnrAutoUpdate(n.discv5EnrAutoUpdate) + b.discv5Conf.withTableIpLimit(n.discv5TableIpLimit) + b.discv5Conf.withBucketIpLimit(n.discv5BucketIpLimit) + b.discv5Conf.withBitsPerHop(n.discv5BitsPerHop) + b.discv5Conf.withDiscv5Only(n.discv5Only) - # # TODO: This is trying to do too much, this should only be used for autosharding, which itself should be configurable - # # If numShardsInNetwork is not set, we use the number of shards configured as numShardsInNetwork - # numShardsInNetwork* {. - # desc: "Number of shards in the network", - # defaultValue: 0, - # name: "num-shards-in-network" - # .}: uint32 + b.withPeerExchange(n.peerExchange) + b.withRemotePeerExchangeNode(n.peerExchangeNode) + b.withRendezvous(n.rendezvous) - # shards* {. - # desc: - # "Shards index to subscribe to [0..NUM_SHARDS_IN_NETWORK-1]. Argument may be repeated.", - # defaultValue: - # @[ - # uint16(0), - # uint16(1), - # uint16(2), - # uint16(3), - # uint16(4), - # uint16(5), - # uint16(6), - # uint16(7), - # ], - # name: "shard" - # .}: seq[uint16] + if n.websocketSupport: + b.webSocketConf.withEnabled(n.websocketSupport) + b.webSocketConf.withWebSocketPort(n.websocketPort) + b.webSocketConf.withSecureEnabled(n.websocketSecureSupport) + b.webSocketConf.withKeyPath(n.websocketSecureKeyPath) + b.webSocketConf.withCertPath(n.websocketSecureCertPath) - # contentTopics* {. - # desc: "Default content topic to subscribe to. Argument may be repeated.", - # name: "content-topic" - # .}: seq[string] + b.withRateLimits(n.rateLimits) - # ## Store and message store config - # store* {. - # desc: "Enable/disable waku store protocol", defaultValue: false, name: "store" - # .}: bool - - # legacyStore* {. - # desc: "Enable/disable waku store legacy mode", - # defaultValue: true, - # name: "legacy-store" - # .}: bool - - # storenode* {. - # desc: "Peer multiaddress to query for storage", - # defaultValue: "", - # name: "storenode" - # .}: string - - # storeMessageRetentionPolicy* {. - # desc: - # "Message store retention policy. Time retention policy: 'time:'. Capacity retention policy: 'capacity:'. Size retention policy: 'size:'. Set to 'none' to disable.", - # defaultValue: "time:" & $2.days.seconds, - # name: "store-message-retention-policy" - # .}: string - - # storeMessageDbUrl* {. - # desc: "The database connection URL for peristent storage.", - # defaultValue: "sqlite://store.sqlite3", - # name: "store-message-db-url" - # .}: string - - # storeMessageDbVacuum* {. - # desc: - # "Enable database vacuuming at start. Only supported by SQLite database engine.", - # defaultValue: false, - # name: "store-message-db-vacuum" - # .}: bool - - # storeMessageDbMigration* {. - # desc: "Enable database migration at start.", - # defaultValue: true, - # name: "store-message-db-migration" - # .}: bool - - # storeMaxNumDbConnections* {. - # desc: "Maximum number of simultaneous Postgres connections.", - # defaultValue: 50, - # name: "store-max-num-db-connections" - # .}: int - - # storeResume* {. - # desc: "Enable store resume functionality", - # defaultValue: false, - # name: "store-resume" - # .}: bool - - # ## Sync config - # storeSync* {. - # desc: "Enable store sync protocol: true|false", - # defaultValue: false, - # name: "store-sync" - # .}: bool - - # storeSyncInterval* {. - # desc: "Interval between store sync attempts. In seconds.", - # defaultValue: 300, # 5 minutes - # name: "store-sync-interval" - # .}: uint32 - - # storeSyncRange* {. - # desc: "Amount of time to sync. In seconds.", - # defaultValue: 3600, # 1 hours - # name: "store-sync-range" - # .}: uint32 - - # storeSyncRelayJitter* {. - # hidden, - # desc: "Time offset to account for message propagation jitter. In seconds.", - # defaultValue: 20, - # name: "store-sync-relay-jitter" - # .}: uint32 - - # ## Filter config - # filter* {. - # desc: "Enable filter protocol: true|false", defaultValue: false, name: "filter" - # .}: bool - - # filternode* {. - # desc: "Peer multiaddr to request content filtering of messages.", - # defaultValue: "", - # name: "filternode" - # .}: string - - # filterSubscriptionTimeout* {. - # desc: - # "Timeout for filter subscription without ping or refresh it, in seconds. Only for v2 filter protocol.", - # defaultValue: 300, # 5 minutes - # name: "filter-subscription-timeout" - # .}: uint16 - - # filterMaxPeersToServe* {. - # desc: "Maximum number of peers to serve at a time. Only for v2 filter protocol.", - # defaultValue: 1000, - # name: "filter-max-peers-to-serve" - # .}: uint32 - - # filterMaxCriteria* {. - # desc: - # "Maximum number of pubsub- and content topic combination per peers at a time. Only for v2 filter protocol.", - # defaultValue: 1000, - # name: "filter-max-criteria" - # .}: uint32 - - # ## Lightpush config - # lightpush* {. - # desc: "Enable lightpush protocol: true|false", - # defaultValue: false, - # name: "lightpush" - # .}: bool - - # lightpushnode* {. - # desc: "Peer multiaddr to request lightpush of published messages.", - # defaultValue: "", - # name: "lightpushnode" - # .}: string - - # ## Reliability config - # reliabilityEnabled* {. - # desc: - # """Adds an extra effort in the delivery/reception of messages by leveraging store-v3 requests. - # with the drawback of consuming some more bandwidth.""", - # defaultValue: false, - # name: "reliability" - # .}: bool - - # ## REST HTTP config - # rest* {. - # desc: "Enable Waku REST HTTP server: true|false", defaultValue: true, name: "rest" - # .}: bool - - # restAddress* {. - # desc: "Listening address of the REST HTTP server.", - # defaultValue: parseIpAddress("127.0.0.1"), - # name: "rest-address" - # .}: IpAddress - - # restPort* {. - # desc: "Listening port of the REST HTTP server.", - # defaultValue: 8645, - # name: "rest-port" - # .}: uint16 - - # restRelayCacheCapacity* {. - # desc: "Capacity of the Relay REST API message cache.", - # defaultValue: 30, - # name: "rest-relay-cache-capacity" - # .}: uint32 - - # restAdmin* {. - # desc: "Enable access to REST HTTP Admin API: true|false", - # defaultValue: false, - # name: "rest-admin" - # .}: bool - - # restAllowOrigin* {. - # desc: - # "Allow cross-origin requests from the specified origin." & - # "Argument may be repeated." & "Wildcards: * or ? allowed." & - # "Ex.: \"localhost:*\" or \"127.0.0.1:8080\"", - # defaultValue: newSeq[string](), - # name: "rest-allow-origin" - # .}: seq[string] - - # ## Metrics config - # metricsServer* {. - # desc: "Enable the metrics server: true|false", - # defaultValue: false, - # name: "metrics-server" - # .}: bool - - # metricsServerAddress* {. - # desc: "Listening address of the metrics server.", - # defaultValue: parseIpAddress("127.0.0.1"), - # name: "metrics-server-address" - # .}: IpAddress - - # metricsServerPort* {. - # desc: "Listening HTTP port of the metrics server.", - # defaultValue: 8008, - # name: "metrics-server-port" - # .}: uint16 - - # metricsLogging* {. - # desc: "Enable metrics logging: true|false", - # defaultValue: true, - # name: "metrics-logging" - # .}: bool - - # ## DNS discovery config - # dnsDiscovery* {. - # desc: - # "Deprecated, please set dns-discovery-url instead. Enable discovering nodes via DNS", - # defaultValue: false, - # name: "dns-discovery" - # .}: bool - - # dnsDiscoveryUrl* {. - # desc: "URL for DNS node list in format 'enrtree://@'", - # defaultValue: "", - # name: "dns-discovery-url" - # .}: string - - # dnsDiscoveryNameServers* {. - # desc: "DNS name server IPs to query. Argument may be repeated.", - # defaultValue: @[parseIpAddress("1.1.1.1"), parseIpAddress("1.0.0.1")], - # name: "dns-discovery-name-server" - # .}: seq[IpAddress] - - # ## Discovery v5 config - # discv5Discovery* {. - # desc: "Enable discovering nodes via Node Discovery v5.", - # defaultValue: false, - # name: "discv5-discovery" - # .}: bool - - # discv5UdpPort* {. - # desc: "Listening UDP port for Node Discovery v5.", - # defaultValue: 9000, - # name: "discv5-udp-port" - # .}: Port - - # discv5BootstrapNodes* {. - # desc: - # "Text-encoded ENR for bootstrap node. Used when connecting to the network. Argument may be repeated.", - # name: "discv5-bootstrap-node" - # .}: seq[string] - - # discv5EnrAutoUpdate* {. - # desc: - # "Discovery can automatically update its ENR with the IP address " & - # "and UDP port as seen by other nodes it communicates with. " & - # "This option allows to enable/disable this functionality", - # defaultValue: false, - # name: "discv5-enr-auto-update" - # .}: bool - - # discv5TableIpLimit* {. - # hidden, - # desc: "Maximum amount of nodes with the same IP in discv5 routing tables", - # defaultValue: 10, - # name: "discv5-table-ip-limit" - # .}: uint - - # discv5BucketIpLimit* {. - # hidden, - # desc: "Maximum amount of nodes with the same IP in discv5 routing table buckets", - # defaultValue: 2, - # name: "discv5-bucket-ip-limit" - # .}: uint - - # discv5BitsPerHop* {. - # hidden, - # desc: "Kademlia's b variable, increase for less hops per lookup", - # defaultValue: 1, - # name: "discv5-bits-per-hop" - # .}: int - - # discv5Only* {. - # desc: "Disable all protocols other than discv5", - # defaultValue: false, - # name: "discv5-only" - # .}: bool - - # ## waku peer exchange config - # peerExchange* {. - # desc: "Enable waku peer exchange protocol (responder side): true|false", - # defaultValue: false, - # name: "peer-exchange" - # .}: bool - - # peerExchangeNode* {. - # desc: - # "Peer multiaddr to send peer exchange requests to. (enables peer exchange protocol requester side)", - # defaultValue: "", - # name: "peer-exchange-node" - # .}: string - - # ## Rendez vous - # rendezvous* {. - # desc: "Enable waku rendezvous discovery server", - # defaultValue: true, - # name: "rendezvous" - # .}: bool - - # ## websocket config - # websocketSupport* {. - # desc: "Enable websocket: true|false", - # defaultValue: false, - # name: "websocket-support" - # .}: bool - - # websocketPort* {. - # desc: "WebSocket listening port.", defaultValue: 8000, name: "websocket-port" - # .}: Port - - # websocketSecureSupport* {. - # desc: "Enable secure websocket: true|false", - # defaultValue: false, - # name: "websocket-secure-support" - # .}: bool - - # websocketSecureKeyPath* {. - # desc: "Secure websocket key path: '/path/to/key.txt' ", - # defaultValue: "", - # name: "websocket-secure-key-path" - # .}: string - - # websocketSecureCertPath* {. - # desc: "Secure websocket Certificate path: '/path/to/cert.txt' ", - # defaultValue: "", - # name: "websocket-secure-cert-path" - # .}: string - - # ## Rate limitation config, if not set, rate limit checks will not be performed - # rateLimits* {. - # desc: - # "Rate limit settings for different protocols." & - # "Format: protocol:volume/period" & - # " Where 'protocol' can be one of: if not defined it means a global setting" & - # " 'volume' and period must be an integer value. " & - # " 'unit' must be one of - hours, minutes, seconds, milliseconds respectively. " & - # "Argument may be repeated.", - # defaultValue: newSeq[string](0), - # name: "rate-limit" - # .}: seq[string] return b.build() diff --git a/waku/factory/internal_config.nim b/waku/factory/internal_config.nim index 3e8c79971..29fec7828 100644 --- a/waku/factory/internal_config.nim +++ b/waku/factory/internal_config.nim @@ -6,14 +6,7 @@ import libp2p/nameresolving/dnsresolver, std/[options, sequtils, strutils, net], results -import - ./external_config, - ../common/utils/nat, - ../node/net_config, - ../waku_enr/capabilities, - ../waku_enr, - ../waku_core, - ./waku_conf +import ../common/utils/nat, ../node/net_config, ../waku_enr, ../waku_core, ./waku_conf proc enrConfiguration*( conf: WakuConf, netConfig: NetConfig @@ -45,31 +38,40 @@ proc enrConfiguration*( return ok(record) proc dnsResolve*( - domain: DomainName, conf: WakuConf + domain: string, dnsAddrsNameServers: seq[IpAddress] ): Future[Result[string, string]] {.async.} = # Use conf's DNS servers var nameServers: seq[TransportAddress] - for ip in conf.dnsAddrsNameServers: + for ip in dnsAddrsNameServers: nameServers.add(initTAddress(ip, Port(53))) # Assume all servers use port 53 let dnsResolver = DnsResolver.new(nameServers) # Resolve domain IP - let resolved = await dnsResolver.resolveIp(domain.string, 0.Port, Domain.AF_UNSPEC) + let resolved = await dnsResolver.resolveIp(domain, 0.Port, Domain.AF_UNSPEC) if resolved.len > 0: return ok(resolved[0].host) # Use only first answer else: return err("Could not resolve IP from DNS: empty response") -proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = +proc networkConfiguration*( + clusterId: uint16, + conf: NetworkConfig, + discv5Conf: Option[Discv5Conf], + webSocketConf: Option[WebSocketConf], + wakuFlags: CapabilitiesBitfield, + dnsAddrsNameServers: seq[IpAddress], + portsShift: uint16, + clientId: string, +): NetConfigResult = ## `udpPort` is only supplied to satisfy underlying APIs but is not ## actually a supported transport for libp2p traffic. let natRes = setupNat( conf.natStrategy.string, clientId, - Port(uint16(conf.p2pTcpPort) + conf.portsShift), - Port(uint16(conf.p2pTcpPort) + conf.portsShift), + Port(uint16(conf.p2pTcpPort) + portsShift), + Port(uint16(conf.p2pTcpPort) + portsShift), ) if natRes.isErr(): return err("failed to setup NAT: " & $natRes.error) @@ -78,8 +80,8 @@ proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = let discv5UdpPort = - if conf.discv5Conf.isSome: - some(Port(uint16(conf.discv5Conf.get().udpPort) + conf.portsShift)) + if discv5Conf.isSome: + some(Port(uint16(discv5Conf.get().udpPort) + portsShift)) else: none(Port) @@ -89,22 +91,14 @@ proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = ## manual config, the external port is the same as the bind port. extPort = if (extIp.isSome() or conf.dns4DomainName.isSome()) and extTcpPort.isNone(): - some(Port(uint16(conf.p2pTcpPort) + conf.portsShift)) + some(Port(uint16(conf.p2pTcpPort) + portsShift)) else: extTcpPort - wakuFlags = CapabilitiesBitfield.init( - lightpush = conf.lightpush, - filter = conf.filterServiceConf.isSome, - store = conf.storeServiceConf.isSome, - relay = conf.relay, - sync = conf.storeSyncConf.isSome, - ) - # Resolve and use DNS domain IP if conf.dns4DomainName.isSome() and extIp.isNone(): try: - let dnsRes = waitFor dnsResolve(conf.dns4DomainName.get(), conf) + let dnsRes = waitFor dnsResolve(conf.dns4DomainName.get(), dnsAddrsNameServers) if dnsRes.isErr(): return err($dnsRes.error) # Pass error down the stack @@ -115,13 +109,9 @@ proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = err("Could not update extIp to resolved DNS IP: " & getCurrentExceptionMsg()) let (wsEnabled, wsBindPort, wssEnabled) = - if conf.webSocketConf.isSome: - let webSocketConf = conf.webSocketConf.get() - ( - true, - some(Port(webSocketConf.port.uint16 + conf.portsShift)), - webSocketConf.secureConf.isSome, - ) + if webSocketConf.isSome: + let wsConf = webSocketConf.get() + (true, some(Port(wsConf.port.uint16 + portsShift)), wsConf.secureConf.isSome) else: (false, none(Port), false) @@ -129,9 +119,9 @@ proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = # TODO: We could change bindIp in NetConfig to be something less restrictive # than IpAddress, which doesn't allow default construction let netConfigRes = NetConfig.init( - clusterId = conf.clusterId, + clusterId = clusterId, bindIp = conf.p2pListenAddress, - bindPort = Port(uint16(conf.p2pTcpPort) + conf.portsShift), + bindPort = Port(uint16(conf.p2pTcpPort) + portsShift), extIp = extIp, extPort = extPort, extMultiAddrs = conf.extMultiAddrs, @@ -139,10 +129,7 @@ proc networkConfiguration*(conf: WakuConf, clientId: string): NetConfigResult = wsBindPort = wsBindPort, wsEnabled = wsEnabled, wssEnabled = wssEnabled, - dns4DomainName = conf.dns4DomainName.map( - proc(dn: DomainName): string = - dn.string - ), + dns4DomainName = conf.dns4DomainName, discv5UdpPort = discv5UdpPort, wakuFlags = some(wakuFlags), ) diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 1b0146551..c0e77927e 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -242,6 +242,17 @@ proc setupProtocols( "failed to mount waku store protocremoteStoreNodeol: " & getCurrentExceptionMsg() ) + if storeServiceConf.storeSyncConf.isSome: + let confStoreSync = storeServiceConf.storeSyncConf.get() + + ( + await node.mountStoreSync( + confStoreSync.rangeSec, confStoreSync.intervalSec, + confStoreSync.relayJitterSec, + ) + ).isOkOr: + return err("failed to mount waku store sync protocol: " & $error) + mountStoreClient(node) if conf.remoteStoreNode.isSome: let storeNode = parsePeerInfo(conf.remoteStoreNode.get()) @@ -405,16 +416,6 @@ proc setupProtocols( else: return err("failed to set node waku filter peer: " & filterNode.error) - if conf.storeSyncConf.isSome: - let confStoreSync = conf.storeSyncConf.get() - - ( - await node.mountStoreSync( - confStoreSync.rangeSec, confStoreSync.intervalSec, confStoreSync.relayJitterSec - ) - ).isOkOr: - return err("failed to mount waku store sync protocol: " & $error) - # waku peer exchange setup if conf.peerExchange: try: @@ -493,7 +494,11 @@ proc startNode*( proc setupNode*( wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay ): Result[WakuNode, string] = - let netConfig = networkConfiguration(wakuConf, clientId).valueOr: + let netConfig = networkConfiguration( + wakuConf.clusterId, wakuConf.networkConf, wakuConf.discv5Conf, + wakuConf.webSocketConf, wakuConf.wakuFlags, wakuConf.dnsAddrsNameServers, + wakuConf.portsShift, clientId, + ).valueOr: error "failed to create internal config", error = error return err("failed to create internal config: " & error) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 6a11f3580..38ff07479 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -172,7 +172,7 @@ proc new*( ## Delivery Monitor var deliveryMonitor: DeliveryMonitor - if wakuConf.p2pReliabilityEnabled: + if wakuConf.p2pReliability: if wakuConf.remoteStoreNode.isNone: return err("A remoteStoreNode should be set when reliability mode is on") @@ -222,14 +222,17 @@ proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] = return err("Could not retrieve ports " & error) if tcpPort.isSome(): - conf.p2pTcpPort = tcpPort.get() + conf.networkConf.p2pTcpPort = tcpPort.get() if websocketPort.isSome() and conf.webSocketConf.isSome: var websocketConf = conf.webSocketConf.get() websocketConf.port = websocketPort.get() # Rebuild NetConfig with bound port values - let netConf = networkConfiguration(conf, clientId).valueOr: + let netConf = networkConfiguration( + conf.clusterId, conf.networkConf, conf.discv5Conf, conf.webSocketConf, + conf.wakuFlags, conf.dnsAddrsNameServers, conf.portsShift, clientId, + ).valueOr: return err("Could not update NetConfig: " & error) return ok(netConf) @@ -278,7 +281,7 @@ proc updateAddressInENR(waku: ptr Waku): Result[void, string] = proc updateWaku(waku: ptr Waku): Result[void, string] = let conf = waku[].conf - if conf.p2pTcpPort == Port(0) or + if conf.networkConf.p2pTcpPort == Port(0) or (conf.websocketConf.isSome and conf.websocketConf.get.port == Port(0)): updateEnr(waku).isOkOr: return err("error calling updateEnr: " & $error) @@ -362,7 +365,7 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async.} = waku.dynamicBootstrapNodes, waku.rng, conf.nodeKey, - conf.p2pListenAddress, + conf.networkConf.p2pListenAddress, conf.portsShift, ) diff --git a/waku/factory/waku_conf.nim b/waku/factory/waku_conf.nim index cea4070df..b9634afbf 100644 --- a/waku/factory/waku_conf.nim +++ b/waku/factory/waku_conf.nim @@ -12,17 +12,14 @@ import ../discovery/waku_discv5, ../node/waku_metrics, ../common/logging, - ./networks_config + ./networks_config, + ../waku_enr/capabilities export RlnRelayConf, RlnRelayCreds, RestServerConf, Discv5Conf, MetricsServerConf logScope: topics = "waku conf" -type - NatStrategy* = distinct string - DomainName* = distinct string - # TODO: should be defined in validator_signed.nim and imported here type ProtectedShard* {.requiresInit.} = object shard*: uint16 @@ -61,6 +58,14 @@ type WebSocketConf* = object port*: Port secureConf*: Option[WebSocketSecureConf] +type NetworkConfig* = object # TODO: make enum + natStrategy*: string + p2pTcpPort*: Port + dns4DomainName*: Option[string] + p2pListenAddress*: IpAddress + extMultiAddrs*: seq[MultiAddress] + extMultiAddrsOnly*: bool + ## `WakuConf` is a valid configuration for a Waku node ## All information needed by a waku node should be contained ## In this object. A convenient `validate` method enables doing @@ -95,6 +100,13 @@ type WakuConf* {.requiresInit.} = ref object rlnRelayConf*: Option[RlnRelayConf] restServerConf*: Option[RestServerConf] metricsServerConf*: Option[MetricsServerConf] + webSocketConf*: Option[WebSocketConf] + + portsShift*: uint16 + dnsAddrs*: bool + dnsAddrsNameServers*: seq[IpAddress] + networkConf*: NetworkConfig + wakuFlags*: CapabilitiesBitfield # TODO: could probably make it a `PeerRemoteInfo` staticNodes*: seq[string] @@ -108,18 +120,6 @@ type WakuConf* {.requiresInit.} = ref object logLevel*: logging.LogLevel logFormat*: logging.LogFormat - natStrategy*: NatStrategy - - p2pTcpPort*: Port - p2pListenAddress*: IpAddress - portsShift*: uint16 - dns4DomainName*: Option[DomainName] - extMultiAddrs*: seq[MultiAddress] - extMultiAddrsOnly*: bool - webSocketConf*: Option[WebSocketConf] - - dnsAddrs*: bool - dnsAddrsNameServers*: seq[IpAddress] peerPersistence*: bool # TODO: should clearly be a uint peerStoreCapacity*: Option[int] @@ -139,7 +139,7 @@ type WakuConf* {.requiresInit.} = ref object # TODO: use proper type relayServiceRatio*: string - p2pReliabilityEnabled*: bool + p2pReliability*: bool proc log*(conf: WakuConf) = info "Configuration: Enabled protocols", @@ -188,8 +188,8 @@ proc validateShards(wakuConf: WakuConf): Result[void, string] = return ok() proc validateNoEmptyStrings(wakuConf: WakuConf): Result[void, string] = - if wakuConf.dns4DomainName.isSome and - isEmptyOrWhiteSpace(wakuConf.dns4DomainName.get().string): + if wakuConf.networkConf.dns4DomainName.isSome and + isEmptyOrWhiteSpace(wakuConf.networkConf.dns4DomainName.get().string): return err("dns4DomainName is an empty string, set it to none(string) instead") if isEmptyOrWhiteSpace(wakuConf.relayServiceRatio): diff --git a/waku/factory/waku_conf_builder.nim b/waku/factory/waku_conf_builder.nim index d316acd35..0ab8f1846 100644 --- a/waku/factory/waku_conf_builder.nim +++ b/waku/factory/waku_conf_builder.nim @@ -6,12 +6,16 @@ import results import - ./waku_conf, ./networks_config, ../common/logging, ../common/utils/parse_size_units + ./waku_conf, + ./networks_config, + ../common/logging, + ../common/utils/parse_size_units, + ../waku_enr/capabilities logScope: topics = "waku conf builder" -proc generateWithProc(builderType, argName, argType, targetType: NimNode): NimNode = +proc generateWithProc(builderType, argName, argType, fromType: NimNode): NimNode = builderType.expectKind nnkIdent argName.expectKind nnkIdent @@ -22,15 +26,15 @@ proc generateWithProc(builderType, argName, argType, targetType: NimNode): NimNo let builderVar = newDotExpr(builderIdent, ident($argName)) let resVar = ident($argName) - if argType == targetType: + if argType == fromType: result.add quote do: proc `procName`*(`builderIdent`: var `builderType`, `resVar`: `argType`) = `builderVar` = some(`argName`) else: result.add quote do: - proc `procName`*(`builderIdent`: var `builderType`, `resVar`: `argType`) = - `builderVar` = some(`argName`.`targetType`) + proc `procName`*(`builderIdent`: var `builderType`, `resVar`: `fromType`) = + `builderVar` = some(`argName`.`argType`) ## A simple macro to set a property on the builder. ## For example: @@ -45,28 +49,28 @@ proc generateWithProc(builderType, argName, argType, targetType: NimNode): NimNo ## proc withRlnRelay*(builder: var RlnRelayConfBuilder, rlnRelay: bool) = ## builder.rlnRelay = some(rlnRelay) ## ``` -macro with( - builderType: untyped, argName: untyped, argType: untyped, targetType: untyped -) = - result = generateWithProc(builderType, argName, argType, targetType) +macro with(builderType: untyped, argName: untyped, argType: untyped) = + result = generateWithProc(builderType, argName, argType, argType) ## A simple macro to set a property on the builder, and convert the property -## to the right (distinct) type. +## to the right type. ## ## For example: ## ## ``` -## with(RlnRelayConfBuilder, ethContractAddress, string, ContractAddress) +## with(WakuConfBuilder, p2pPort, Port, uint16) ## ``` ## ## Generates ## ## ``` -## proc withRlnRelay*(builder: var RlnRelayConfBuilder, ethContractAddress: string) = -## builder.ethContractAddress = some(ethContractAddress.ContractAddress) +## proc withp2pPort*(builder: var WakuConfBuilder, p2pPort: uint16) = +## builder.p2pPort = some(p2pPort.Port) ## ``` -macro with(builderType: untyped, argName: untyped, argType: untyped) = - result = generateWithProc(builderType, argName, argType, argType) +macro with( + builderType: untyped, argName: untyped, argType: untyped, fromType: untyped +) = + result = generateWithProc(builderType, argName, argType, fromType) ############################## ## RLN Relay Config Builder ## @@ -237,7 +241,7 @@ type StoreServiceConfBuilder = object maxNumDbConnections: Option[int] retentionPolicy: Option[string] resume: Option[bool] - storeSyncConf: StoreSyncConfBuilder + storeSyncConf*: StoreSyncConfBuilder proc init(T: type StoreServiceConfBuilder): StoreServiceConfBuilder = StoreServiceConfBuilder(storeSyncConf: StoreSyncConfBuilder.init()) @@ -303,11 +307,12 @@ type RestServerConfBuilder = object proc init(T: type RestServerConfBuilder): RestServerConfBuilder = RestServerConfBuilder() -proc withAllowOrigin(builder: var RestServerConfBuilder, allowOrigin: seq[string]) = +proc withAllowOrigin*(builder: var RestServerConfBuilder, allowOrigin: seq[string]) = builder.allowOrigin = concat(builder.allowOrigin, allowOrigin) +with(RestServerConfBuilder, enabled, bool) with(RestServerConfBuilder, listenAddress, IpAddress) -with(RestServerConfBuilder, port, Port) +with(RestServerConfBuilder, port, Port, uint16) with(RestServerConfBuilder, admin, bool) with(RestServerConfBuilder, relayCacheCapacity, uint32) @@ -387,9 +392,10 @@ with(Discv5ConfBuilder, bucketIpLimit, uint) with(Discv5ConfBuilder, discv5Only, bool) with(Discv5ConfBuilder, enrAutoUpdate, bool) with(Discv5ConfBuilder, tableIpLimit, uint) -with(Discv5ConfBuilder, udpPort, uint16, Port) +with(Discv5ConfBuilder, udpPort, Port, uint16) +with(Discv5ConfBuilder, udpPort, Port) -proc withBootstrapNodes(builder: var Discv5ConfBuilder, bootstrapNodes: seq[string]) = +proc withBootstrapNodes*(builder: var Discv5ConfBuilder, bootstrapNodes: seq[string]) = # TODO: validate ENRs? builder.bootstrapNodes = concat(builder.bootstrapNodes, bootstrapNodes) @@ -432,8 +438,8 @@ type WebSocketConfBuilder* = object enabled: Option[bool] webSocketPort: Option[Port] secureEnabled: Option[bool] - webSocketSecureKeyPath: Option[string] - webSocketSecureCertPath: Option[string] + keyPath: Option[string] + certPath: Option[string] proc init*(T: type WebSocketConfBuilder): WebSocketConfBuilder = WebSocketConfBuilder() @@ -441,8 +447,9 @@ proc init*(T: type WebSocketConfBuilder): WebSocketConfBuilder = with(WebSocketConfBuilder, enabled, bool) with(WebSocketConfBuilder, secureEnabled, bool) with(WebSocketConfBuilder, webSocketPort, Port) -with(WebSocketConfBuilder, webSocketSecureKeyPath, string) -with(WebSocketConfBuilder, webSocketSecureCertPath, string) +with(WebSocketConfBuilder, webSocketPort, Port, uint16) +with(WebSocketConfBuilder, keyPath, string) +with(WebSocketConfBuilder, certPath, string) proc build(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] = if not b.enabled.get(false): @@ -460,9 +467,9 @@ proc build(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] = ) ) - if b.webSocketSecureKeyPath.get("") == "": + if b.keyPath.get("") == "": return err("WebSocketSecure enabled but key path is not specified") - if b.webSocketSecureCertPath.get("") == "": + if b.certPath.get("") == "": return err("WebSocketSecure enabled but cert path is not specified") return ok( @@ -470,10 +477,7 @@ proc build(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] = WebSocketConf( port: b.webSocketPort.get(), secureConf: some( - WebSocketSecureConf( - keyPath: b.webSocketSecureKeyPath.get(), - certPath: b.webSocketSecureCertPath.get(), - ) + WebSocketSecureConf(keyPath: b.keyPath.get(), certPath: b.certPath.get()) ), ) ) @@ -493,6 +497,9 @@ proc init(T: type MetricsServerConfBuilder): MetricsServerConfBuilder = MetricsServerConfBuilder() with(MetricsServerConfBuilder, enabled, bool) +with(MetricsServerConfBuilder, httpAddress, IpAddress) +with(MetricsServerConfBuilder, httpPort, Port, uint16) +with(MetricsServerConfBuilder, logging, bool) proc build(b: MetricsServerConfBuilder): Result[Option[MetricsServerConf], string] = if b.enabled.get(false): @@ -552,13 +559,13 @@ type WakuConfBuilder* = object contentTopics: Option[seq[string]] # Conf builders - dnsDiscoveryConf: DnsDiscoveryConfBuilder + dnsDiscoveryConf*: DnsDiscoveryConfBuilder discv5Conf*: Discv5ConfBuilder - filterServiceConf: FilterServiceConfBuilder + filterServiceConf*: FilterServiceConfBuilder metricsServerConf*: MetricsServerConfBuilder restServerConf*: RestServerConfBuilder rlnRelayConf*: RlnRelayConfBuilder - storeServiceConf: StoreServiceConfBuilder + storeServiceConf*: StoreServiceConfBuilder webSocketConf*: WebSocketConfBuilder # End conf builders relay: Option[bool] @@ -584,12 +591,12 @@ type WakuConfBuilder* = object logLevel: Option[logging.LogLevel] logFormat: Option[logging.LogFormat] - natStrategy: Option[NatStrategy] + natStrategy: Option[string] p2pTcpPort: Option[Port] p2pListenAddress: Option[IpAddress] portsShift: Option[uint16] - dns4DomainName: Option[DomainName] + dns4DomainName: Option[string] extMultiAddrs: seq[string] extMultiAddrsOnly: Option[bool] @@ -610,7 +617,7 @@ type WakuConfBuilder* = object relayServiceRatio: Option[string] circuitRelayClient: Option[bool] keepAlive: Option[bool] - p2pReliabilityEnabled: Option[bool] + p2pReliability: Option[bool] proc init*(T: type WakuConfBuilder): WakuConfBuilder = WakuConfBuilder( @@ -627,11 +634,14 @@ proc init*(T: type WakuConfBuilder): WakuConfBuilder = with(WakuConfBuilder, clusterConf, ClusterConf) with(WakuConfBuilder, nodeKey, PrivateKey) with(WakuConfBuilder, clusterId, uint16) +with(WakuConfBuilder, numShardsInNetwork, uint32) with(WakuConfBuilder, shards, seq[uint16]) with(WakuConfBuilder, protectedShards, seq[ProtectedShard]) with(WakuConfBuilder, contentTopics, seq[string]) with(WakuConfBuilder, relay, bool) +with(WakuConfBuilder, lightPush, bool) with(WakuConfBuilder, storeSync, bool) +with(WakuConfBuilder, peerExchange, bool) with(WakuConfBuilder, relayPeerExchange, bool) with(WakuConfBuilder, rendezvous, bool) with(WakuConfBuilder, remoteStoreNode, string) @@ -646,17 +656,21 @@ with(WakuConfBuilder, dnsAddrsNameServers, seq[IpAddress]) with(WakuConfBuilder, logLevel, logging.LogLevel) with(WakuConfBuilder, logFormat, logging.LogFormat) with(WakuConfBuilder, p2pTcpPort, Port) -with(WakuConfBuilder, p2pTcpPort, uint16, Port) +with(WakuConfBuilder, p2pTcpPort, Port, uint16) with(WakuConfBuilder, portsShift, uint16) with(WakuConfBuilder, p2pListenAddress, IpAddress) with(WakuConfBuilder, extMultiAddrsOnly, bool) -with(WakuConfBuilder, dns4DomainName, string, DomainName) -with(WakuConfBuilder, natStrategy, string, NatStrategy) +with(WakuConfBuilder, dns4DomainName, string) +with(WakuConfBuilder, natStrategy, string) with(WakuConfBuilder, agentString, string) with(WakuConfBuilder, colocationLimit, int) with(WakuConfBuilder, rateLimits, seq[string]) with(WakuConfBuilder, maxRelayPeers, int) with(WakuConfBuilder, relayServiceRatio, string) +with(WakuConfBuilder, circuitRelayClient, bool) +with(WakuConfBuilder, relayShardedPeerManagement, bool) +with(WakuConfBuilder, keepAlive, bool) +with(WakuConfBuilder, p2pReliability, bool) proc withExtMultiAddrs*(builder: var WakuConfBuilder, extMultiAddrs: seq[string]) = builder.extMultiAddrs = concat(builder.extMultiAddrs, extMultiAddrs) @@ -667,6 +681,9 @@ proc withMaxMessageSize*(builder: var WakuConfBuilder, maxMessageSizeBytes: uint proc withMaxMessageSize*(builder: var WakuConfBuilder, maxMessageSize: string) = builder.maxMessageSize = MaxMessageSize(kind: mmskStr, str: maxMessageSize) +proc withStaticNodes*(builder: var WakuConfBuilder, staticNodes: seq[string]) = + builder.staticNodes = concat(builder.staticNodes, staticNodes) + proc nodeKey( builder: WakuConfBuilder, rng: ref HmacDrbgContext ): Result[PrivateKey, string] = @@ -835,7 +852,8 @@ proc build*( of mmskStr: ?parseMsgSize(builder.maxMessageSize.str) else: - return err("Max Message Size was not specified") + warn "Max Message Size not specified, defaulting to 150KiB" + parseCorrectMsgSize("150KiB") let contentTopics = builder.contentTopics.get(@[]) @@ -884,14 +902,14 @@ proc build*( builder.natStrategy.get() else: warn "Nat Strategy is not specified, defaulting to none" - "none".NatStrategy + "none" let p2pTcpPort = if builder.p2pTcpPort.isSome(): builder.p2pTcpPort.get() else: warn "P2P Listening TCP Port is not specified, listening on 60000" - 6000.Port + 60000.Port let p2pListenAddress = if builder.p2pListenAddress.isSome(): @@ -913,9 +931,9 @@ proc build*( if d.string != "": some(d) else: - none(DomainName) + none(string) else: - none(DomainName) + none(string) var extMultiAddrs: seq[MultiAddress] = @[] for s in builder.extMultiAddrs: @@ -955,7 +973,8 @@ proc build*( if builder.maxConnections.isSome(): builder.maxConnections.get() else: - return err "Max Connections was not specified" + warn "Max Connections was not specified, defaulting to 300" + 300 let relayServiceRatio = if builder.relayServiceRatio.isSome(): @@ -980,8 +999,16 @@ proc build*( if builder.keepAlive.isNone(): return err("keepAlive is not specified") - if builder.p2pReliabilityEnabled.isNone(): - return err("p2pReliabilityEnabled is not specified") + if builder.p2pReliability.isNone(): + return err("p2pReliability is not specified") + + let wakuFlags = CapabilitiesBitfield.init( + lightpush = lightPush, + filter = filterServiceConf.isSome, + store = storeServiceConf.isSome, + relay = relay, + sync = storeServiceConf.isSome() and storeServiceConf.get().storeSyncConf.isSome, + ) return ok( WakuConf( @@ -1012,13 +1039,16 @@ proc build*( maxMessageSizeBytes: maxMessageSizeBytes, logLevel: logLevel, logFormat: logFormat, - natStrategy: natStrategy, - p2pTcpPort: p2pTcpPort, - p2pListenAddress: p2pListenAddress, + # TODO: Separate builders + networkConf: NetworkConfig( + natStrategy: natStrategy, + p2pTcpPort: p2pTcpPort, + dns4DomainName: dns4DomainName, + p2pListenAddress: p2pListenAddress, + extMultiAddrs: extMultiAddrs, + extMultiAddrsOnly: extMultiAddrsOnly, + ), portsShift: portsShift, - dns4DomainName: dns4DomainName, - extMultiAddrs: extMultiAddrs, - extMultiAddrsOnly: extMultiAddrsOnly, webSocketConf: webSocketConf, dnsAddrs: dnsAddrs, dnsAddrsNameServers: dnsAddrsNameServers, @@ -1034,6 +1064,7 @@ proc build*( keepAlive: builder.keepAlive.get(), staticNodes: builder.staticNodes, relayShardedPeerManagement: relayShardedPeerManagement, - p2pReliabilityEnabled: builder.p2pReliabilityEnabled.get(), + p2pReliability: builder.p2pReliability.get(), + wakuFlags: wakuFlags, ) )