From 648ddd194cd9629c62f75974d0b64edc1b021f58 Mon Sep 17 00:00:00 2001 From: SionoiS Date: Mon, 4 May 2026 10:03:09 -0400 Subject: [PATCH] latest libp2p master & disable bootstrapping --- apps/chat2disco/chat2disco.nim | 8 +- apps/chat2disco/config_chat2disco.nim | 186 +++++++++++++------------- waku.nimble | 2 +- waku/discovery/waku_kademlia.nim | 10 +- waku/node/waku_switch.nim | 12 +- 5 files changed, 112 insertions(+), 106 deletions(-) diff --git a/apps/chat2disco/chat2disco.nim b/apps/chat2disco/chat2disco.nim index be2f14cff..dbe7b99cc 100644 --- a/apps/chat2disco/chat2disco.nim +++ b/apps/chat2disco/chat2disco.nim @@ -347,7 +347,13 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = continue kadBootstrapPeers.add((peerId, @[ma])) - node.wakuKademlia = WakuKademlia.new(node.switch, node.peerManager, kadBootstrapPeers) + node.wakuKademlia = WakuKademlia.new( + switch = node.switch, + peerManager = node.peerManager, + bootstrapNodes = kadBootstrapPeers, + xprPublishing = false, + disableBootstrapping = true, + ) let catchRes = catch: node.switch.mount(node.wakuKademlia.protocol) diff --git a/apps/chat2disco/config_chat2disco.nim b/apps/chat2disco/config_chat2disco.nim index 86b505bd8..c7c459133 100644 --- a/apps/chat2disco/config_chat2disco.nim +++ b/apps/chat2disco/config_chat2disco.nim @@ -11,121 +11,117 @@ import std/strutils import waku/waku_core -const - defaultMetricsAddress* = parseIpAddress("127.0.0.1") +const defaultMetricsAddress* = parseIpAddress("127.0.0.1") -type - Chat2DiscoConf* = object ## General node config - logLevel* {. - desc: "Sets the log level.", defaultValue: LogLevel.INFO, name: "log-level" - .}: LogLevel +type Chat2DiscoConf* = object ## General node config + logLevel* {. + desc: "Sets the log level.", defaultValue: LogLevel.INFO, name: "log-level" + .}: LogLevel - nodekey* {.desc: "P2P node private key as 64 char hex string.", name: "nodekey".}: - Option[crypto.PrivateKey] + nodekey* {.desc: "P2P node private key as 64 char hex string.", name: "nodekey".}: + Option[crypto.PrivateKey] - listenAddress* {. - defaultValue: defaultListenAddress(config), - desc: "Listening address for the LibP2P traffic.", - name: "listen-address" - .}: IpAddress + listenAddress* {. + defaultValue: defaultListenAddress(config), + desc: "Listening address for the LibP2P traffic.", + name: "listen-address" + .}: IpAddress - tcpPort* {.desc: "TCP listening port.", defaultValue: 60000, name: "tcp-port".}: - Port + tcpPort* {.desc: "TCP listening port.", defaultValue: 60000, name: "tcp-port".}: Port - udpPort* {.desc: "UDP listening port.", defaultValue: 60000, name: "udp-port".}: - Port + udpPort* {.desc: "UDP listening port.", defaultValue: 60000, name: "udp-port".}: Port - portsShift* {. - desc: "Add a shift to all port numbers.", defaultValue: 0, name: "ports-shift" - .}: uint16 + portsShift* {. + desc: "Add a shift to all port numbers.", defaultValue: 0, name: "ports-shift" + .}: uint16 - nat* {. - desc: - "Specify method to use for determining public address. " & - "Must be one of: any, none, upnp, pmp, extip:.", - defaultValue: "any" - .}: string + nat* {. + desc: + "Specify method to use for determining public address. " & + "Must be one of: any, none, upnp, pmp, extip:.", + defaultValue: "any" + .}: string - ## Relay config - relay* {. - desc: "Enable relay protocol: true|false", defaultValue: true, name: "relay" - .}: bool + ## Relay config + relay* {. + desc: "Enable relay protocol: true|false", defaultValue: true, name: "relay" + .}: bool - keepAlive* {. - desc: "Enable keep-alive for idle connections: true|false", - defaultValue: false, - name: "keep-alive" - .}: bool + keepAlive* {. + desc: "Enable keep-alive for idle connections: true|false", + defaultValue: false, + name: "keep-alive" + .}: bool - clusterId* {. - desc: - "Cluster id that the node is running in. Node in a different cluster id is disconnected.", - defaultValue: 0, - name: "cluster-id" - .}: uint16 + clusterId* {. + desc: + "Cluster id that the node is running in. Node in a different cluster id is disconnected.", + defaultValue: 0, + name: "cluster-id" + .}: uint16 - shards* {. - desc: - "Shards index to subscribe to [0..NUM_SHARDS_IN_NETWORK-1]. Argument may be repeated.", - defaultValue: @[uint16(0)], - name: "shard" - .}: seq[uint16] + shards* {. + desc: + "Shards index to subscribe to [0..NUM_SHARDS_IN_NETWORK-1]. Argument may be repeated.", + defaultValue: @[uint16(0)], + name: "shard" + .}: seq[uint16] - ## Metrics config - metricsServer* {. - desc: "Enable the metrics server: true|false", - defaultValue: false, - name: "metrics-server" - .}: bool + ## 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: defaultMetricsAddress, - name: "metrics-server-address" - .}: IpAddress + metricsServerAddress* {. + desc: "Listening address of the metrics server.", + defaultValue: defaultMetricsAddress, + name: "metrics-server-address" + .}: IpAddress - metricsServerPort* {. - desc: "Listening HTTP port of the metrics server.", - defaultValue: 8008, - name: "metrics-server-port" - .}: uint16 + 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 + metricsLogging* {. + desc: "Enable metrics logging: true|false", + defaultValue: true, + name: "metrics-logging" + .}: bool - ## Chat2 configuration - contentTopic* {. - desc: "Content topic for chat messages.", - defaultValue: "/chat2disco/1/default/proto", - name: "content-topic" - .}: string + ## Chat2 configuration + contentTopic* {. + desc: "Content topic for chat messages.", + defaultValue: "/chat2disco/1/default/proto", + name: "content-topic" + .}: string - ## Websocket Configuration - websocketSupport* {. - desc: "Enable websocket: true|false", - defaultValue: false, - name: "websocket-support" - .}: bool + ## Websocket Configuration + websocketSupport* {. + desc: "Enable websocket: true|false", + defaultValue: false, + name: "websocket-support" + .}: bool - websocketPort* {. - desc: "WebSocket listening port.", defaultValue: 8000, name: "websocket-port" - .}: Port + websocketPort* {. + desc: "WebSocket listening port.", defaultValue: 8000, name: "websocket-port" + .}: Port - websocketSecureSupport* {. - desc: "WebSocket Secure Support.", - defaultValue: false, - name: "websocket-secure-support" - .}: bool + websocketSecureSupport* {. + desc: "WebSocket Secure Support.", + defaultValue: false, + name: "websocket-secure-support" + .}: bool - ## Kademlia Discovery config - kadBootstrapNodes* {. - desc: - "Peer multiaddr for kademlia discovery bootstrap node (must include /p2p/). Argument may be repeated.", - name: "kad-bootstrap-node" - .}: seq[string] + ## Kademlia Discovery config + kadBootstrapNodes* {. + desc: + "Peer multiaddr for kademlia discovery bootstrap node (must include /p2p/). Argument may be repeated.", + name: "kad-bootstrap-node" + .}: seq[string] # NOTE: Keys are different in nim-libp2p proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T = diff --git a/waku.nimble b/waku.nimble index bd9a442ed..f18e8d1a3 100644 --- a/waku.nimble +++ b/waku.nimble @@ -27,7 +27,7 @@ requires "nim >= 2.2.4", "toml_serialization", "faststreams", # Networking & P2P - "https://github.com/vacp2p/nim-libp2p.git#9b6fedca059f3c054582407be9268e2999c7d05d", + "https://github.com/vacp2p/nim-libp2p.git#df777fc66cc100191dbefd3c222a4472b4d3b924", "eth", "nat_traversal", "dnsdisc", diff --git a/waku/discovery/waku_kademlia.nim b/waku/discovery/waku_kademlia.nim index 8c3caa026..d1e05182c 100644 --- a/waku/discovery/waku_kademlia.nim +++ b/waku/discovery/waku_kademlia.nim @@ -166,7 +166,8 @@ proc new*( bootstrapNodes: seq[(PeerId, seq[MultiAddress])] = @[], providedServices: seq[ServiceInfo] = @[], loopInterval: Duration = DefaultKademliaDiscoveryInterval, - xprPublishing: bool = false, + xprPublishing: bool = true, + disableBootstrapping: bool = false, ): T = if bootstrapNodes.len == 0: debug "creating kademlia discovery as seed node (no bootstrap nodes)" @@ -174,8 +175,11 @@ proc new*( let kademlia = ServiceDiscovery.new( switch, bootstrapNodes = bootstrapNodes, - config = - KadDHTConfig.new(validator = ExtEntryValidator(), selector = ExtEntrySelector()), + config = KadDHTConfig.new( + validator = ExtEntryValidator(), + selector = ExtEntrySelector(), + disableBootstrapping = disableBootstrapping, + ), services = providedServices, xprPublishing = xprPublishing, ) diff --git a/waku/node/waku_switch.nim b/waku/node/waku_switch.nim index 941c20807..e658bd0e4 100644 --- a/waku/node/waku_switch.nim +++ b/waku/node/waku_switch.nim @@ -23,11 +23,11 @@ import const MaxConnections* = 50 const MaxConnectionsPerPeer* = 1 -proc withWsTransport*(b: SwitchBuilder): SwitchBuilder = +#[ proc withWsTransport*(b: SwitchBuilder): SwitchBuilder = b.withTransport( proc(upgr: Upgrade, privateKey: crypto.PrivateKey): Transport = WsTransport.new(upgr) - ) + ) ]# proc getSecureKey(path: string): TLSPrivateKey {.raises: [Defect, IOError].} = trace "Key path is.", path = path @@ -47,7 +47,7 @@ proc getSecureCert(path: string): TLSCertificate {.raises: [Defect, IOError].} = except TLSStreamProtocolError as exc: info "exception raised from getSecureCert", err = exc.msg -proc withWssTransport*( +#[ proc withWssTransport*( b: SwitchBuilder, secureKeyPath: string, secureCertPath: string ): SwitchBuilder {.raises: [Defect, IOError].} = let key: TLSPrivateKey = getSecureKey(secureKeyPath) @@ -56,7 +56,7 @@ proc withWssTransport*( tlsPrivateKey = key, tlsCertificate = cert, {TLSFlags.NoVerifyHost, TLSFlags.NoVerifyServerName}, # THIS IS INSECURE, NO? - ) + ) ]# proc newWakuSwitch*( privKey = none(crypto.PrivateKey), @@ -115,10 +115,10 @@ proc newWakuSwitch*( if wsAddress.isSome(): b = b.withAddresses(@[wsAddress.get(), address]) - if wssEnabled: + #[ if wssEnabled: b = b.withWssTransport(secureKeyPath, secureCertPath) else: - b = b.withWsTransport() + b = b.withWsTransport() ]# else: b = b.withAddress(address)