mirror of
https://github.com/logos-storage/logos-storage-nim-dht.git
synced 2026-01-08 16:33:10 +00:00
add random loss
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
527db66a02
commit
e934dd7b96
@ -7,7 +7,7 @@
|
||||
# ChronoSim: simulation/emulation wrapper around Chronos
|
||||
|
||||
import
|
||||
std/[tables, deques],
|
||||
std/[tables, deques, random],
|
||||
chronos,
|
||||
chronicles
|
||||
|
||||
@ -54,6 +54,8 @@ when(emulateDatagram): #enable network emulator
|
||||
proc getLatency(src: TransportAddress, dst: TransportAddress) : Duration =
|
||||
50.milliseconds
|
||||
|
||||
proc getLoss(src: TransportAddress, dst: TransportAddress) : float =
|
||||
0.0
|
||||
proc getLineTime(transp: DatagramTransport, msg: seq[byte]) : Duration =
|
||||
# let bandwith = transp.bandwidth
|
||||
let bandwidth = 100 # Bytes/ms = KB/sec
|
||||
@ -65,6 +67,9 @@ when(emulateDatagram): #enable network emulator
|
||||
#transp.egress.addLast(remote, msg)
|
||||
#await sleepAsync(getLineTime(transp, msg))
|
||||
|
||||
if rand(1.0) < getLoss(transp.local, remote):
|
||||
return
|
||||
|
||||
await sleepAsync(getLatency(transp.local, remote))
|
||||
{.gcsafe.}:
|
||||
network[remote.port].recvFrom(transp.local, msg)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user