sync up with master
This commit is contained in:
parent
3a53bb1338
commit
5331dc9606
|
@ -91,7 +91,7 @@ when isMainModule:
|
|||
waitFor server.stop()
|
||||
notice "Stopped Codex"
|
||||
|
||||
c_signal(SIGTERM, SIGTERMHandler)
|
||||
c_signal(ansi_c.SIGTERM, SIGTERMHandler)
|
||||
|
||||
waitFor server.start()
|
||||
notice "Exited codex"
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
## This file may not be copied, modified, or distributed except according to
|
||||
## those terms.
|
||||
|
||||
import pkg/upraises
|
||||
push: {.upraises: [].}
|
||||
|
||||
import pkg/chronos
|
||||
import pkg/chronicles
|
||||
import pkg/libp2p
|
||||
|
@ -21,6 +24,8 @@ const
|
|||
MaxMessageSize = 100 * 1 shl 20 # manifest files can be big
|
||||
|
||||
type
|
||||
ConnProvider* = proc(): Future[Connection] {.gcsafe, closure.}
|
||||
|
||||
RPCHandler* = proc(peer: NetworkPeer, msg: Message): Future[void] {.gcsafe.}
|
||||
|
||||
NetworkPeer* = ref object of RootObj
|
||||
|
|
|
@ -12,11 +12,11 @@ import pkg/upraises
|
|||
push: {.upraises: [].}
|
||||
|
||||
import pkg/libp2p/crypto/crypto
|
||||
import pkg/bearssl
|
||||
import pkg/bearssl/rand
|
||||
|
||||
type
|
||||
RngSampleError = object of CatchableError
|
||||
Rng* = ref BrHmacDrbgContext
|
||||
Rng* = ref HmacDrbgContext
|
||||
|
||||
var rng {.threadvar.}: Rng
|
||||
|
||||
|
@ -25,16 +25,15 @@ proc instance*(t: type Rng): Rng =
|
|||
rng = newRng()
|
||||
rng
|
||||
|
||||
# Random helpers: similar as in stdlib, but with BrHmacDrbgContext rng
|
||||
# Random helpers: similar as in stdlib, but with HmacDrbgContext rng
|
||||
# TODO: Move these somewhere else?
|
||||
const randMax = 18_446_744_073_709_551_615'u64
|
||||
|
||||
proc rand*(rng: Rng, max: Natural): int =
|
||||
if max == 0: return 0
|
||||
|
||||
var x: uint64
|
||||
while true:
|
||||
brHmacDrbgGenerate(addr rng[], addr x, csize_t(sizeof(x)))
|
||||
let x = rng[].generate(uint64)
|
||||
if x < randMax - (randMax mod (uint64(max) + 1'u64)): # against modulo bias
|
||||
return int(x mod (uint64(max) + 1'u64))
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
## This file may not be copied, modified, or distributed except according to
|
||||
## those terms.
|
||||
|
||||
{.push raises: [Defect].}
|
||||
import pkg/upraises
|
||||
push: {.upraises: [].}
|
||||
|
||||
import pkg/chronos
|
||||
import pkg/chronicles
|
||||
|
|
|
@ -158,9 +158,6 @@ suite "Network - Senders":
|
|||
done = newFuture[void]()
|
||||
switch1 = newStandardSwitch()
|
||||
switch2 = newStandardSwitch()
|
||||
await switch1.start()
|
||||
await switch2.start()
|
||||
|
||||
network1 = BlockExcNetwork.new(
|
||||
switch = switch1)
|
||||
switch1.mount(network1)
|
||||
|
@ -169,6 +166,9 @@ suite "Network - Senders":
|
|||
switch = switch2)
|
||||
switch2.mount(network2)
|
||||
|
||||
await switch1.start()
|
||||
await switch2.start()
|
||||
|
||||
await switch1.connect(
|
||||
switch2.peerInfo.peerId,
|
||||
switch2.peerInfo.addrs)
|
||||
|
@ -271,8 +271,6 @@ suite "Network - Test Limits":
|
|||
done = newFuture[void]()
|
||||
switch1 = newStandardSwitch()
|
||||
switch2 = newStandardSwitch()
|
||||
await switch1.start()
|
||||
await switch2.start()
|
||||
|
||||
network1 = BlockExcNetwork.new(
|
||||
switch = switch1,
|
||||
|
@ -283,6 +281,9 @@ suite "Network - Test Limits":
|
|||
switch = switch2)
|
||||
switch2.mount(network2)
|
||||
|
||||
await switch1.start()
|
||||
await switch2.start()
|
||||
|
||||
await switch1.connect(
|
||||
switch2.peerInfo.peerId,
|
||||
switch2.peerInfo.addrs)
|
||||
|
|
|
@ -37,12 +37,11 @@ proc corruptBlocks*(
|
|||
manifest: Manifest,
|
||||
blks, bytes: int): Future[seq[int]] {.async.} =
|
||||
var pos: seq[int]
|
||||
while true:
|
||||
if pos.len >= blks:
|
||||
break
|
||||
|
||||
var i = -1
|
||||
if (i = Rng.instance.rand(manifest.len - 1); pos.find(i) >= 0):
|
||||
doAssert blks < manifest.len
|
||||
while pos.len < blks:
|
||||
let i = Rng.instance.rand(manifest.len - 1)
|
||||
if pos.find(i) >= 0:
|
||||
continue
|
||||
|
||||
pos.add(i)
|
||||
|
@ -50,15 +49,12 @@ proc corruptBlocks*(
|
|||
blk = (await store.getBlock(manifest[i])).tryGet()
|
||||
bytePos: seq[int]
|
||||
|
||||
while true:
|
||||
if bytePos.len > bytes:
|
||||
break
|
||||
|
||||
var ii = -1
|
||||
if (ii = Rng.instance.rand(blk.data.len - 1); bytePos.find(ii) >= 0):
|
||||
doAssert bytes < blk.data.len
|
||||
while bytePos.len <= bytes:
|
||||
let ii = Rng.instance.rand(blk.data.len - 1)
|
||||
if bytePos.find(ii) >= 0:
|
||||
continue
|
||||
|
||||
bytePos.add(ii)
|
||||
blk.data[ii] = byte 0
|
||||
|
||||
return pos
|
||||
|
|
Loading…
Reference in New Issue