nim-libp2p/libp2p/stream
Jacek Sieka 96d4c44fec
refactor bufferstream to use a queue (#346)
This change modifies how the backpressure algorithm in bufferstream
works - in particular, instead of working byte-by-byte, it will now work
seq-by-seq.

When data arrives, it usually does so in packets - in the current
bufferstream, the packet is read then split into bytes which are fed one
by one to the bufferstream. On the reading side, the bytes are popped of
the bufferstream, again byte by byte, to satisfy `readOnce` requests -
this introduces a lot of synchronization traffic because the checks for
full buffer and for async event handling must be done for every byte.

In this PR, a queue of length 1 is used instead - this means there will
at most exist one "packet" in `pushTo`, one in the queue and one in the
slush buffer that is used to store incomplete reads.

* avoid byte-by-byte copy to buffer, with synchronization in-between
* reuse AsyncQueue synchronization logic instead of rolling own
* avoid writeHandler callback - implement `write` method instead
* simplify EOF signalling by only setting EOF flag in queue reader (and
reset)
* remove BufferStream pipes (unused)
* fixes drainBuffer deadlock when drain is called from within read loop
and thus blocks draining
* fix lpchannel init order
2020-09-10 08:19:13 +02:00
..
bufferstream.nim refactor bufferstream to use a queue (#346) 2020-09-10 08:19:13 +02:00
chronosstream.nim simplify and unify logging (#353) 2020-09-06 10:31:47 +02:00
connection.nim refactor bufferstream to use a queue (#346) 2020-09-10 08:19:13 +02:00
lpstream.nim refactor bufferstream to use a queue (#346) 2020-09-10 08:19:13 +02:00
streamseq.nim logging fixes and small cleanups (#361) 2020-09-09 19:12:08 +02:00