mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-16 14:39:34 +00:00
* bump nim-libp2p pin to v2.0.0 tag * bump json_rpc to v0.6.1, lsquic to v0.5.1, boringssl to v0.0.8 (latest tags) * add libp2p_mix dep; repoint libp2p/protocols/mix -> libp2p_mix * pin nimble.lock: websock / protobuf_serialization / npeg / jwt * Makefile: add -d:libp2p_quic_support * regenerate nix/deps.nix (adds libp2p_mix, refreshes pins) * migrate rng ref HmacDrbgContext -> libp2p Rng across prod/channels/tests (interface-only; same DRBG) * waku_switch: TransportConfig factory; unified 2.0.0 connection limits (withMaxInOut, withMaxConnections); local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery rename) * call Service.setup() on post-build switch services (2.0.0 split setup/start) * drop libp2p/utils/semaphore -> chronos AsyncSemaphore * add logos_delivery/waku/compat/option_valueor shim (Option[T] valueOr/withValue, dropped upstream) * add std/options where a transitive re-export was removed * add newStandardSwitch shim (libp2p removed it in 2.0.0); mounts yamux+mplex to match prod muxer * PeerId.random(rng); common.rng()/crypto.newRng(); hoist shared rng (instantiation cleanup) * update expectations for 2.0.0 defaults: DEFAULT_PROTOCOLS += /ipfs/id/push/1.0.0; agent "nim-libp2p" * drop relay reboot/reconnect test (asserted a Switch restart capability that is simply not supported) * fix up a few tests that were flaking on MacOS (libp2p upgrade may have exposed these)
97 lines
3.2 KiB
Nim
97 lines
3.2 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
import std/json
|
|
import chronos, chronicles, results, strutils, libp2p/multiaddress, ffi
|
|
import
|
|
logos_delivery/waku/factory/waku,
|
|
logos_delivery/waku/discovery/waku_dnsdisc,
|
|
logos_delivery/waku/discovery/waku_discv5,
|
|
logos_delivery/waku/waku_core/peers,
|
|
logos_delivery/waku/waku_node,
|
|
library/declare_lib
|
|
|
|
proc retrieveBootstrapNodes(
|
|
enrTreeUrl: string, ipDnsServer: string
|
|
): Future[Result[seq[string], string]] {.async.} =
|
|
let dnsNameServers = @[parseIpAddress(ipDnsServer)]
|
|
let discoveredPeers: seq[RemotePeerInfo] = (
|
|
await retrieveDynamicBootstrapNodes(enrTreeUrl, dnsNameServers)
|
|
).valueOr:
|
|
return err("failed discovering peers from DNS: " & $error)
|
|
|
|
var multiAddresses = newSeq[string]()
|
|
|
|
for discPeer in discoveredPeers:
|
|
for address in discPeer.addrs:
|
|
multiAddresses.add($address & "/p2p/" & $discPeer)
|
|
|
|
return ok(multiAddresses)
|
|
|
|
proc updateDiscv5BootstrapNodes(nodes: string, waku: Waku): Result[void, string] =
|
|
waku.wakuDiscv5.updateBootstrapRecords(nodes).isOkOr:
|
|
return err("error in updateDiscv5BootstrapNodes: " & $error)
|
|
return ok()
|
|
|
|
proc performPeerExchangeRequestTo*(
|
|
numPeers: uint64, waku: Waku
|
|
): Future[Result[int, string]] {.async.} =
|
|
let numPeersRecv = (await waku.node.fetchPeerExchangePeers(numPeers)).valueOr:
|
|
return err($error)
|
|
return ok(numPeersRecv)
|
|
|
|
proc waku_discv5_update_bootnodes(
|
|
ctx: ptr FFIContext[Waku],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
bootnodes: cstring,
|
|
) {.ffi.} =
|
|
## Updates the bootnode list used for discovering new peers via DiscoveryV5
|
|
## bootnodes - JSON array containing the bootnode ENRs i.e. `["enr:...", "enr:..."]`
|
|
|
|
updateDiscv5BootstrapNodes($bootnodes, ctx.myLib[]).isOkOr:
|
|
error "UPDATE_DISCV5_BOOTSTRAP_NODES failed", error = error
|
|
return err($error)
|
|
|
|
return ok("discovery request processed correctly")
|
|
|
|
proc waku_dns_discovery(
|
|
ctx: ptr FFIContext[Waku],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
enrTreeUrl: cstring,
|
|
nameDnsServer: cstring,
|
|
timeoutMs: cint,
|
|
) {.ffi.} =
|
|
let nodes = (await retrieveBootstrapNodes($enrTreeUrl, $nameDnsServer)).valueOr:
|
|
error "GET_BOOTSTRAP_NODES failed", error = error
|
|
return err($error)
|
|
|
|
## returns a comma-separated string of bootstrap nodes' multiaddresses
|
|
return ok(nodes.join(","))
|
|
|
|
proc waku_start_discv5(
|
|
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
|
) {.ffi.} =
|
|
(await ctx.myLib[].wakuDiscv5.start()).isOkOr:
|
|
error "START_DISCV5 failed", error = error
|
|
return err("error starting discv5: " & $error)
|
|
|
|
return ok("discv5 started correctly")
|
|
|
|
proc waku_stop_discv5(
|
|
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
|
) {.ffi.} =
|
|
await ctx.myLib[].wakuDiscv5.stop()
|
|
return ok("discv5 stopped correctly")
|
|
|
|
proc waku_peer_exchange_request(
|
|
ctx: ptr FFIContext[Waku],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
numPeers: uint64,
|
|
) {.ffi.} =
|
|
let numValidPeers = (await performPeerExchangeRequestTo(numPeers, ctx.myLib[])).valueOr:
|
|
error "waku_peer_exchange_request failed", error = error
|
|
return err("failed peer exchange: " & $error)
|
|
|
|
return ok($numValidPeers)
|