2025-04-11 17:20:23 +02:00
|
|
|
import std/[options, random], chronos
|
2025-01-22 11:08:23 -05:00
|
|
|
|
2025-01-23 16:13:26 -05:00
|
|
|
import
|
|
|
|
|
waku/[
|
|
|
|
|
node/peer_manager,
|
|
|
|
|
waku_core,
|
|
|
|
|
waku_store_sync/common,
|
|
|
|
|
waku_store_sync/reconciliation,
|
|
|
|
|
waku_store_sync/transfer,
|
|
|
|
|
],
|
|
|
|
|
../testlib/wakucore
|
2025-01-22 11:08:23 -05:00
|
|
|
|
|
|
|
|
randomize()
|
|
|
|
|
|
|
|
|
|
proc randomHash*(rng: var Rand): WakuMessageHash =
|
|
|
|
|
var hash = EmptyWakuMessageHash
|
|
|
|
|
|
|
|
|
|
for i in 0 ..< hash.len:
|
|
|
|
|
hash[i] = rng.rand(uint8)
|
|
|
|
|
|
|
|
|
|
return hash
|
|
|
|
|
|
2025-01-23 16:13:26 -05:00
|
|
|
proc newTestWakuRecon*(
|
2025-01-22 11:08:23 -05:00
|
|
|
switch: Switch,
|
|
|
|
|
idsRx: AsyncQueue[SyncID],
|
|
|
|
|
wantsTx: AsyncQueue[(PeerId, Fingerprint)],
|
|
|
|
|
needsTx: AsyncQueue[(PeerId, Fingerprint)],
|
2025-01-30 08:46:34 -05:00
|
|
|
cluster: uint16 = 1,
|
|
|
|
|
shards: seq[uint16] = @[0, 1, 2, 3, 4, 5, 6, 7],
|
2025-01-22 11:08:23 -05:00
|
|
|
): Future[SyncReconciliation] {.async.} =
|
|
|
|
|
let peerManager = PeerManager.new(switch)
|
|
|
|
|
|
|
|
|
|
let res = await SyncReconciliation.new(
|
2025-01-30 08:46:34 -05:00
|
|
|
cluster = cluster,
|
|
|
|
|
shards = shards,
|
2025-01-22 11:08:23 -05:00
|
|
|
peerManager = peerManager,
|
|
|
|
|
wakuArchive = nil,
|
|
|
|
|
relayJitter = 0.seconds,
|
|
|
|
|
idsRx = idsRx,
|
2025-01-23 16:13:26 -05:00
|
|
|
localWantsTx = wantsTx,
|
|
|
|
|
remoteNeedsTx = needsTx,
|
2025-01-22 11:08:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let proto = res.get()
|
|
|
|
|
|
|
|
|
|
proto.start()
|
|
|
|
|
switch.mount(proto)
|
|
|
|
|
|
2025-01-23 16:13:26 -05:00
|
|
|
return proto
|
2025-01-22 11:08:23 -05:00
|
|
|
|
2025-01-23 16:13:26 -05:00
|
|
|
proc newTestWakuTransfer*(
|
2025-01-22 11:08:23 -05:00
|
|
|
switch: Switch,
|
|
|
|
|
idsTx: AsyncQueue[SyncID],
|
|
|
|
|
wantsRx: AsyncQueue[(PeerId, Fingerprint)],
|
|
|
|
|
needsRx: AsyncQueue[(PeerId, Fingerprint)],
|
|
|
|
|
): SyncTransfer =
|
|
|
|
|
let peerManager = PeerManager.new(switch)
|
|
|
|
|
|
|
|
|
|
let proto = SyncTransfer.new(
|
|
|
|
|
peerManager = peerManager,
|
|
|
|
|
wakuArchive = nil,
|
|
|
|
|
idsTx = idsTx,
|
2025-01-23 16:13:26 -05:00
|
|
|
localWantsRx = wantsRx,
|
|
|
|
|
remoteNeedsRx = needsRx,
|
2025-01-22 11:08:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
proto.start()
|
|
|
|
|
switch.mount(proto)
|
|
|
|
|
|
2025-01-23 16:13:26 -05:00
|
|
|
return proto
|