Skip to content

Commit

Permalink
Spec-compliant noise handshake payloads (Step 1). (#1658)
Browse files Browse the repository at this point in the history
* Support spec-compliant reading of noise handshake payloads.

See libp2p/rust-libp2p#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.
  • Loading branch information
romanb authored Jul 17, 2020
1 parent 45a53c0 commit 822bfd2
Show file tree
Hide file tree
Showing 7 changed files with 614 additions and 447 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
- [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md)
- [`libp2p-core-derive` CHANGELOG](misc/core-derive/CHANGELOG.md)

# Version 0.22.0 (2020-07-17)

**NOTE**: For a smooth upgrade path from `0.21` to `> 0.22`
on an existing deployment using `libp2p-noise`, this version
must not be skipped!

- Bump `libp2p-noise` dependency to `0.21`.

# Version 0.21.1 (2020-07-02)

- Bump `libp2p-websockets` lower bound.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p"
edition = "2018"
description = "Peer-to-peer networking library"
version = "0.21.1"
version = "0.22.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -68,7 +68,7 @@ libp2p-gossipsub = { version = "0.20.0", path = "./protocols/gossipsub", optiona
libp2p-identify = { version = "0.20.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.21.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.20.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.20.0", path = "protocols/noise", optional = true }
libp2p-noise = { version = "0.21.0", path = "protocols/noise", optional = true }
libp2p-ping = { version = "0.20.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.20.0", path = "protocols/plaintext", optional = true }
libp2p-pnet = { version = "0.19.1", path = "protocols/pnet", optional = true }
Expand Down
11 changes: 11 additions & 0 deletions protocols/noise/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 0.21.0 [2020-07-17]

**NOTE**: For a smooth upgrade path from `0.20` to `> 0.21`
on an existing deployment, this version must not be skipped!

- Add support for reading handshake protobuf frames without
length prefixes in preparation for no longer sending them.
See [issue 1631](https://github.com/libp2p/rust-libp2p/issues/1631).

- Update the `snow` dependency to the latest patch version.

# 0.20.0 [2020-07-01]

- Updated dependencies.
Expand Down
7 changes: 4 additions & 3 deletions protocols/noise/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "libp2p-noise"
description = "Cryptographic handshake protocol using the noise framework."
version = "0.20.0"
version = "0.21.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
edition = "2018"

[dependencies]
bytes = "0.5"
curve25519-dalek = "2.0.0"
futures = "0.3.1"
lazy_static = "1.2"
Expand All @@ -21,10 +22,10 @@ x25519-dalek = "0.6.0"
zeroize = "1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
snow = { version = "0.7.0", features = ["ring-resolver"], default-features = false }
snow = { version = "0.7.1", features = ["ring-resolver"], default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
snow = { version = "0.7.0", features = ["default-resolver"], default-features = false }
snow = { version = "0.7.1", features = ["default-resolver"], default-features = false }

[dev-dependencies]
env_logger = "0.7.1"
Expand Down
Loading

0 comments on commit 822bfd2

Please sign in to comment.