das: factorize startSampling procedure

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-06-12 12:08:05 +02:00
parent 0083e1e41c
commit 2076bcdfd0
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 9 additions and 3 deletions

View File

@ -144,14 +144,20 @@ when isMainModule:
info "uploaded to DHT", by = 0, pass, time = Moment.now() - startTime
# sample
for n in 1 ..< nodecount:
let startTime = Moment.now()
proc startSampling(n: discv5_protocol.Protocol): seq[Future[DiscResult[seq[byte]]]] =
## Generate random sample and start the sampling process
var futs = newSeq[Future[DiscResult[seq[byte]]]]()
let sample = sample(0 ..< blocksize, samplesize)
debug "starting sampling", by = n, sample
for s in sample:
let fut = nodes[n][0].getValue(segmentIDs[s])
let fut = n.getValue(segmentIDs[s])
futs.add(fut)
return futs
for n in 1 ..< nodecount:
let startTime = Moment.now()
var futs = startSampling(nodes[n][0])
# test is passed if all segments are retrieved in time
let pass = await allFutures(futs).withTimeout(sampling_timeout)