Roman Borschel 5291175f38
Spec-compliant noise handshake payloads (Step 1). (#1658)
* Support spec-compliant reading of noise handshake payloads.

See https://github.com/libp2p/rust-libp2p/issues/1631.

This the first of a three-step process to addressing the issue.
In this step, support for reading noise handshake payloads
without an additional length prefix is added, falling back
to attempting a decoding with length prefix on failure.
Length prefixes are still sent in this step. Hence
interoperability with other libp2p implementations is not
yet achieved after with step.

To achieve a better separation of handshake and transport
I/O, the `NoiseFramed` type has been extracted from
`NoiseOutput`. `NoiseFramed` is a `Sink` and `Stream`
of length-delimited Noise protocol messages. This type
is used in the handshake phase. Once a handshake
completes the underlying Noise session transitions to
transport mode and the `NoiseFramed` is wrapped in
the `NoiseOutput` which provides a regular `AsyncRead`
/ `AsyncWrite` I/O resource on top of the framed
encoding. No new buffers are introduced, they are
just split between `NoiseFramed` and `NoiseOutput`.

The second step involves removing the sending of the
length prefix in a subsequent release.

The third step involves removing the support for reading
length-prefixed protobuf payloads.

* Small cleanup.

* Reuse frame decryption buffer.

Since frames are consumed one-by-one, `NoiseFramed` can have
a `BytesMut` decryption buffer, handing out immutable `Bytes`
views for each decrypted message. Since each view gets fully
consumed and dropped before the next frame is read, the
`BytesMut` decryption buffer in `NoiseFramed` can always
reuse the same buffer, only growing it as necessary.

* Simplify.

* Add missing inner poll_flush().

* Improve nested length detection.

* Avoid unnecessary clearing of send buffers.

Thus reducing the necessary zeroing of send buffers on resize,
as per the previous behaviour.

* Prepare release.
2020-07-17 12:27:30 +02:00
..
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-07-01 15:36:20 +02:00
2020-06-22 11:41:28 +02:00