generalize p2p delay

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-05-11 01:36:24 +02:00
parent 43d71d4957
commit dcb6c244c8
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E

View File

@ -45,10 +45,13 @@ when(true): #enable network emulator
# call the callback on remote
asyncCheck transp.callback(transp, remote)
proc getLatency(src: TransportAddress, dst: TransportAddress) : Duration =
50.milliseconds
proc sendTo*[T](transp: DatagramTransport, remote: TransportAddress,
msg: sink seq[T], msglen = -1) {.async.} =
#echo "sending to ", remote
await sleepAsync(50.milliseconds)
await sleepAsync(getLatency(transp.local, remote))
{.gcsafe.}:
network[remote.port].recvFrom(transp.local, msg)