use exit==dest approach for mix (#3642)

This commit is contained in:
Prem Chaitanya Prathi 2025-11-22 08:11:05 +05:30 committed by GitHub
parent b0cd75f4cb
commit 088e3108c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 23 additions and 11 deletions

View File

@ -143,6 +143,9 @@ ifeq ($(USE_LIBBACKTRACE), 0)
NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace
endif endif
# enable experimental exit is dest feature in libp2p mix
NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest
libbacktrace: libbacktrace:
+ $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0 + $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0

View File

@ -82,6 +82,8 @@ type
PrivateKey* = crypto.PrivateKey PrivateKey* = crypto.PrivateKey
Topic* = waku_core.PubsubTopic Topic* = waku_core.PubsubTopic
const MinMixNodePoolSize = 4
##################### #####################
## chat2 protobufs ## ## chat2 protobufs ##
##################### #####################
@ -592,6 +594,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
node.peerManager.addServicePeer(servicePeerInfo, WakuLightpushCodec) node.peerManager.addServicePeer(servicePeerInfo, WakuLightpushCodec)
node.peerManager.addServicePeer(servicePeerInfo, WakuPeerExchangeCodec) node.peerManager.addServicePeer(servicePeerInfo, WakuPeerExchangeCodec)
#node.peerManager.addServicePeer(servicePeerInfo, WakuRendezVousCodec)
# Start maintaining subscription # Start maintaining subscription
asyncSpawn maintainSubscription( asyncSpawn maintainSubscription(
@ -599,12 +602,12 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
) )
echo "waiting for mix nodes to be discovered..." echo "waiting for mix nodes to be discovered..."
while true: while true:
if node.getMixNodePoolSize() >= 3: if node.getMixNodePoolSize() >= MinMixNodePoolSize:
break break
discard await node.fetchPeerExchangePeers() discard await node.fetchPeerExchangePeers()
await sleepAsync(1000) await sleepAsync(1000)
while node.getMixNodePoolSize() < 3: while node.getMixNodePoolSize() < MinMixNodePoolSize:
info "waiting for mix nodes to be discovered", info "waiting for mix nodes to be discovered",
currentpoolSize = node.getMixNodePoolSize() currentpoolSize = node.getMixNodePoolSize()
await sleepAsync(1000) await sleepAsync(1000)

View File

@ -144,7 +144,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.}
conn = connOpt.get() conn = connOpt.get()
else: else:
conn = node.wakuMix.toConnection( conn = node.wakuMix.toConnection(
MixDestination.init(dPeerId, pxPeerInfo.addrs[0]), # destination lightpush peer MixDestination.exitNode(dPeerId), # destination lightpush peer
WakuLightPushCodec, # protocol codec which will be used over the mix connection WakuLightPushCodec, # protocol codec which will be used over the mix connection
MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))), MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))),
# mix parameters indicating we expect a single reply # mix parameters indicating we expect a single reply
@ -163,6 +163,9 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.}
ephemeral: true, # tell store nodes to not store it ephemeral: true, # tell store nodes to not store it
timestamp: getNowInNanosecondTime(), timestamp: getNowInNanosecondTime(),
) # current timestamp ) # current timestamp
let res = await node.wakuLightpushClient.publishWithConn(
LightpushPubsubTopic, message, conn, dPeerId
)
let startTime = getNowInNanosecondTime() let startTime = getNowInNanosecondTime()

View File

@ -1,6 +1,6 @@
log-level = "INFO" log-level = "INFO"
relay = true relay = true
#mix = true mix = true
filter = true filter = true
store = false store = false
lightpush = true lightpush = true
@ -18,7 +18,7 @@ num-shards-in-network = 1
shard = [0] shard = [0]
agent-string = "nwaku-mix" agent-string = "nwaku-mix"
nodekey = "f98e3fba96c32e8d1967d460f1b79457380e1a895f7971cecc8528abe733781a" nodekey = "f98e3fba96c32e8d1967d460f1b79457380e1a895f7971cecc8528abe733781a"
#mixkey = "a87db88246ec0eedda347b9b643864bee3d6933eb15ba41e6d58cb678d813258" mixkey = "a87db88246ec0eedda347b9b643864bee3d6933eb15ba41e6d58cb678d813258"
rendezvous = true rendezvous = true
listen-address = "127.0.0.1" listen-address = "127.0.0.1"
nat = "extip:127.0.0.1" nat = "extip:127.0.0.1"

View File

@ -199,7 +199,7 @@ proc lightpushPublishHandler(
if mixify: #indicates we want to use mix to send the message if mixify: #indicates we want to use mix to send the message
#TODO: How to handle multiple addresses? #TODO: How to handle multiple addresses?
let conn = node.wakuMix.toConnection( let conn = node.wakuMix.toConnection(
MixDestination.init(peer.peerId, peer.addrs[0]), MixDestination.exitNode(peer.peerId),
WakuLightPushCodec, WakuLightPushCodec,
MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))), MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))),
# indicating we only want a single path to be used for reply hence numSurbs = 1 # indicating we only want a single path to be used for reply hence numSurbs = 1

View File

@ -21,7 +21,7 @@ import
logScope: logScope:
topics = "waku mix" topics = "waku mix"
const mixMixPoolSize = 3 const minMixPoolSize = 4
type type
WakuMix* = ref object of MixProtocol WakuMix* = ref object of MixProtocol
@ -181,12 +181,12 @@ proc new*(
peermgr.switch.peerInfo.peerId, nodeMultiAddr, mixPubKey, mixPrivKey, peermgr.switch.peerInfo.peerId, nodeMultiAddr, mixPubKey, mixPrivKey,
peermgr.switch.peerInfo.publicKey.skkey, peermgr.switch.peerInfo.privateKey.skkey, peermgr.switch.peerInfo.publicKey.skkey, peermgr.switch.peerInfo.privateKey.skkey,
) )
if bootnodes.len < mixMixPoolSize: if bootnodes.len < minMixPoolSize:
warn "publishing with mix won't work until there are 3 mix nodes in node pool" warn "publishing with mix won't work until atleast 3 mix nodes in node pool"
let initTable = processBootNodes(bootnodes, peermgr) let initTable = processBootNodes(bootnodes, peermgr)
if len(initTable) < mixMixPoolSize: if len(initTable) < minMixPoolSize:
warn "publishing with mix won't work until there are 3 mix nodes in node pool" warn "publishing with mix won't work until atleast 3 mix nodes in node pool"
var m = WakuMix(peerManager: peermgr, clusterId: clusterId, pubKey: mixPubKey) var m = WakuMix(peerManager: peermgr, clusterId: clusterId, pubKey: mixPubKey)
procCall MixProtocol(m).init(localMixNodeInfo, initTable, peermgr.switch) procCall MixProtocol(m).init(localMixNodeInfo, initTable, peermgr.switch)
return ok(m) return ok(m)

View File

@ -234,4 +234,7 @@ proc stopWait*(self: WakuRendezVous) {.async: (raises: []).} =
# Stop the parent GenericRendezVous (stops the register deletion loop) # Stop the parent GenericRendezVous (stops the register deletion loop)
await GenericRendezVous[WakuPeerRecord](self).stop() await GenericRendezVous[WakuPeerRecord](self).stop()
# Stop the parent GenericRendezVous (stops the register deletion loop)
await GenericRendezVous[WakuPeerRecord](self).stop()
info "waku rendezvous discovery stopped" info "waku rendezvous discovery stopped"