mirror of
https://github.com/logos-storage/logos-storage-nim-dht.git
synced 2026-01-05 23:13:10 +00:00
generate segments systematically
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
b2774465f0
commit
0083e1e41c
12
das/das.nim
12
das/das.nim
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
std/[options, sequtils, random],
|
std/[options, sequtils, random, math],
|
||||||
asynctest,
|
asynctest,
|
||||||
bearssl/rand,
|
bearssl/rand,
|
||||||
chronicles,
|
chronicles,
|
||||||
@ -64,7 +64,14 @@ proc toNodeId(data: openArray[byte]): NodeId =
|
|||||||
|
|
||||||
proc segmentData(s: int, segmentsize: int) : seq[byte] =
|
proc segmentData(s: int, segmentsize: int) : seq[byte] =
|
||||||
result = newSeq[byte](segmentsize)
|
result = newSeq[byte](segmentsize)
|
||||||
result[0] = byte(s mod 256)
|
var
|
||||||
|
r = s
|
||||||
|
i = 0
|
||||||
|
while r > 0:
|
||||||
|
assert(i<segmentsize)
|
||||||
|
result[i] = byte(r mod 256)
|
||||||
|
r = r div 256
|
||||||
|
i+=1
|
||||||
|
|
||||||
proc sample(s: Slice[int], len: int): seq[int] =
|
proc sample(s: Slice[int], len: int): seq[int] =
|
||||||
# random sample without replacement
|
# random sample without replacement
|
||||||
@ -99,6 +106,7 @@ when isMainModule:
|
|||||||
samplesize = 3
|
samplesize = 3
|
||||||
upload_timeout = 5.seconds
|
upload_timeout = 5.seconds
|
||||||
sampling_timeout = 5.seconds
|
sampling_timeout = 5.seconds
|
||||||
|
assert(log2(blocksize.float).ceil.int <= segmentsize * 8 )
|
||||||
|
|
||||||
var
|
var
|
||||||
rng: ref HmacDrbgContext
|
rng: ref HmacDrbgContext
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user