mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-27 15:03:17 +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)
112 lines
3.1 KiB
Nim
112 lines
3.1 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
{.push raises: [].}
|
|
|
|
import chronicles, std/options, chronos, results, metrics
|
|
|
|
import
|
|
libp2p/crypto/curve25519,
|
|
libp2p/crypto/crypto,
|
|
libp2p_mix,
|
|
libp2p_mix/mix_node,
|
|
libp2p_mix/mix_protocol,
|
|
libp2p_mix/mix_metrics,
|
|
libp2p_mix/delay_strategy,
|
|
libp2p/[multiaddress, peerid],
|
|
eth/common/keys
|
|
|
|
import
|
|
logos_delivery/waku/node/peer_manager,
|
|
logos_delivery/waku/waku_core,
|
|
logos_delivery/waku/waku_enr,
|
|
logos_delivery/waku/node/peer_manager/waku_peer_store
|
|
|
|
logScope:
|
|
topics = "waku mix"
|
|
|
|
const minMixPoolSize = 4
|
|
|
|
type
|
|
WakuMix* = ref object of MixProtocol
|
|
peerManager*: PeerManager
|
|
clusterId: uint16
|
|
pubKey*: Curve25519Key
|
|
|
|
WakuMixResult*[T] = Result[T, string]
|
|
|
|
MixNodePubInfo* = object
|
|
multiAddr*: string
|
|
pubKey*: Curve25519Key
|
|
|
|
proc processBootNodes(
|
|
bootnodes: seq[MixNodePubInfo], peermgr: PeerManager, mix: WakuMix
|
|
) =
|
|
var count = 0
|
|
for node in bootnodes:
|
|
let pInfo = parsePeerInfo(node.multiAddr).valueOr:
|
|
error "Failed to get peer id from multiaddress: ",
|
|
error = error, multiAddr = $node.multiAddr
|
|
continue
|
|
let peerId = pInfo.peerId
|
|
var peerPubKey: crypto.PublicKey
|
|
if not peerId.extractPublicKey(peerPubKey):
|
|
warn "Failed to extract public key from peerId, skipping node", peerId = peerId
|
|
continue
|
|
|
|
if peerPubKey.scheme != PKScheme.Secp256k1:
|
|
warn "Peer public key is not Secp256k1, skipping node",
|
|
peerId = peerId, scheme = peerPubKey.scheme
|
|
continue
|
|
|
|
let multiAddr = MultiAddress.init(node.multiAddr).valueOr:
|
|
error "Failed to parse multiaddress", multiAddr = node.multiAddr, error = error
|
|
continue
|
|
|
|
let mixPubInfo = MixPubInfo.init(peerId, multiAddr, node.pubKey, peerPubKey.skkey)
|
|
mix.nodePool.add(mixPubInfo)
|
|
count.inc()
|
|
|
|
peermgr.addPeer(
|
|
RemotePeerInfo.init(peerId, @[multiAddr], mixPubKey = some(node.pubKey))
|
|
)
|
|
mix_pool_size.set(count)
|
|
info "using mix bootstrap nodes ", count = count
|
|
|
|
proc new*(
|
|
T: typedesc[WakuMix],
|
|
nodeAddr: string,
|
|
peermgr: PeerManager,
|
|
clusterId: uint16,
|
|
mixPrivKey: Curve25519Key,
|
|
bootnodes: seq[MixNodePubInfo],
|
|
): WakuMixResult[T] =
|
|
let mixPubKey = public(mixPrivKey)
|
|
info "mixPubKey", mixPubKey = mixPubKey
|
|
let nodeMultiAddr = MultiAddress.init(nodeAddr).valueOr:
|
|
return err("failed to parse mix node address: " & $nodeAddr & ", error: " & error)
|
|
let localMixNodeInfo = initMixNodeInfo(
|
|
peermgr.switch.peerInfo.peerId, nodeMultiAddr, mixPubKey, mixPrivKey,
|
|
peermgr.switch.peerInfo.publicKey.skkey, peermgr.switch.peerInfo.privateKey.skkey,
|
|
)
|
|
|
|
var m = WakuMix(peerManager: peermgr, clusterId: clusterId, pubKey: mixPubKey)
|
|
procCall MixProtocol(m).init(
|
|
localMixNodeInfo,
|
|
peermgr.switch,
|
|
delayStrategy = Opt.some(
|
|
DelayStrategy(
|
|
ExponentialDelayStrategy.new(meanDelay = 50'u16, rng = crypto.newRng())
|
|
)
|
|
),
|
|
)
|
|
|
|
processBootNodes(bootnodes, peermgr, m)
|
|
|
|
if m.nodePool.len < minMixPoolSize:
|
|
warn "publishing with mix won't work until atleast 3 mix nodes in node pool"
|
|
return ok(m)
|
|
|
|
proc poolSize*(mix: WakuMix): int =
|
|
mix.nodePool.len
|
|
|
|
# Mix Protocol
|