add stub for egress queuing

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

View File

@ -31,6 +31,7 @@ when(true): #enable network emulator
local: TransportAddress # Local address
callback: DatagramCallback # Receive data callback
ingress: Deque[seq[byte]]
egress: Deque[(TransportAddress, seq[byte])] # simple FIFO for now
var network = initTable[Port, DatagramTransport]()
@ -48,9 +49,17 @@ when(true): #enable network emulator
proc getLatency(src: TransportAddress, dst: TransportAddress) : Duration =
50.milliseconds
proc getLineTime(transp: DatagramTransport, msg: seq[byte]) : Duration =
# let bandwith = transp.bandwidth
let bandwidth = 100 # Bytes/ms = KB/sec
(msg.len div bandwidth).milliseconds
proc sendTo*[T](transp: DatagramTransport, remote: TransportAddress,
msg: sink seq[T], msglen = -1) {.async.} =
#echo "sending to ", remote
#transp.egress.addLast(remote, msg)
#await sleepAsync(getLineTime(transp, msg))
await sleepAsync(getLatency(transp.local, remote))
{.gcsafe.}:
network[remote.port].recvFrom(transp.local, msg)