In order to make use of the distances returned by `KBucketRef::range` in
a human readable format, one needs to be able to translate the 256 bit in
a `Distance` to a smaller space.
* docs/release.md: Add release documentation
* docs/release.md: Address comments
* docs/release.md: Add annotation -a option
* docs/release: Mention bumping Cargo.toml version
* docs/release.md: Extract name and version with sed
* docs/release.md: Remove instruction for release date in changelog
* Remove temporary peer ID compatibility.
This removes the temporary compatibility mode between
peer IDs using identity hashing and sha256, thus being
the last step in the context of https://github.com/libp2p/rust-libp2p/issues/555.
* Check digest length in PeerId::from_multihash for Identity hash.
* Update core/src/peer_id.rs
Co-authored-by: Toralf Wittner <tw@dtex.org>
* Update core changelog.
* Update core changelog.
Co-authored-by: Toralf Wittner <tw@dtex.org>
* core: remove duplicates when performing address translation
* core: use filter_map instead of flat_map
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Compiling libp2p-kad for `--target wasm32-unknown-unknown` fails with
the cryptic error message `cannot infer type for type `usize``.
Explicitly converting to `usize` solves the issue.
Co-authored-by: Andronik Ordian <write@reusable.software>
* Implement ProtocolsHandler methods in wrappers.
This PR forwards calls to some ProtocolsHandler methods that were
previously not implemented in wrappers such as `MapInEvent`.
It is unclear though how this can be implemented in some handlers
such as `MultiHandler` as the information at hand does not enable
it to decide which handler to forward the call to.
* Add `MultiHandler::inject_listen_ugrade_error`.
* Store addresses of provider records.
So far, provider records are stored without their
addresses and the addresses of provider records are
obtained from the routing table on demand. This has
two shortcomings:
1. We can only return provider records whose provider
peers happen to currently be in the local routing table.
2. The local node never returns itself as a provider for
a key, even if it is indeed a provider.
These issues are addressed here by storing the addresses
together with the provider records, falling back to
addresses from the routing table only for backward-compatibility
with existing implementations of `RecordStore` using persistent
storage.
Resolves https://github.com/libp2p/rust-libp2p/issues/1526.
* Update protocols/kad/src/behaviour.rs
Co-authored-by: Max Inden <mail@max-inden.de>
* Remove negligible use of with_capacity.
* Update changelog.
Co-authored-by: Max Inden <mail@max-inden.de>
* Allow override the yamux connection mode.
* Add `multiplex_ext` to transport `Builder`.
This method exposes the connection info and connected point to a provided
function which creates the upgrade and can base the decision on `PeerId`
or other connection information such as IP address.
* Re-export `yamux::Mode`.
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
The codec impl did not check that it actually read any bytes in
`read_request` and `read_response`. The used `read_one` function
does not error on EOF either, so instead of signalling connection
loss the codec could produce empty `Ping` or `Pong` messages.
* swarm/one_shot: Add test for not keeping alive idle connection
A `OneShotHandler` without any ongoing requests should not keep the
underlying connection alive indefinitely.
* swarm/one_shot: Initialize handler with KeepAlive::Until
The `OneShotHandler` `keep_alive` property is altered on incoming and
outgoing reqeusts. By default it is initialized in `KeepAlive::Yes`. In
case there are no incoming or outgoing requests happening, this state is
never changed and thus the handler keeps the underlying connection alive
indefinitely.
With this commit the handler is initialized with `KeepAlive::Until`. As
before the `keep_alive` timer is updated on incoming requests and set to
`KeepAlive::Yes` on outgoing requests.
* swarm/one_shot: Move KeepAlive logic to poll
A `ProtocolsHandler` can be created before the underlying connection is
established. Thus setting a keep alive timeout might be problematic.
Instead set `keep_alive` to `Yes` at construction and alter it within
`ProtocolsHandler::poll`.
* swarm/CHANGELOG: Add entry for OneShotHandler keep-alive
* Use a single exchange instead of two one_shots.
* Add `Throttled` to libp2p-request-response.
Wraps the existing `RequestResponse` behaviour and applies strict limits
to the number of inbound and outbound requests per peer.
The wrapper is opt-in and if not used, the protocol behaviour of
`RequestResponse` does not change. This PR also does not introduce
an extra protocol, hence the limits applied need to be known a priori
for all nodes which is not always possible or desirable. As mentioned
in #1687 I think that we should eventually augment the protocol with
metadata which allows a more dynamic exchange of requests and responses.
This PR also replaces the two oneshot channels with a single one from the
scambio crate which saves one allocation per request/response. If not
desirable because the crate has seen less testing the first commit could
be reverted.
* Fix rustdoc error.
* Remove some leftovers from development.
* Add docs to `NetworBehaviourAction::{map_in,map_out}`.
* Apply suggestions from code review
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
* Add `ping_protocol_throttled` test.
* Add another test.
* Revert "Use a single exchange instead of two one_shots."
This reverts commit e34e1297d411298f6c69e238aa6c96e0b795d989.
# Conflicts:
# protocols/request-response/Cargo.toml
# protocols/request-response/src/handler/protocol.rs
* Update CHANGELOG.
* Update CHANGELOG.
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
* Refactor the ping protocol.
Such that pings are sent over a single substream, as it is
done in other libp2p implementations. Note that, since each
peer sends its pings over a single, dedicated substream,
every peer that participates in the protocol has effectively
two open substreams.
* Cleanup
* Update ping changelog.
* Update protocols/ping/src/protocol.rs
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
With 826f513 a `StreamMuxer` can notify that the address of a remote
peer changed. This is needed to support the transport protocol QUIC as
remotes can change their IP addresses within the lifetime of a single
connection.
This commit implements the `NetworkBehaviour::inject_address_change`
handler to update the Kademlia routing table accordingly.
* Emit events for active connection close and fix `disconnect()`.
The `Network` does currently not emit events for actively
closed connections, e.g. via `EstablishedConnection::close`
or `ConnectedPeer::disconnect()`. As a result, when actively
closing connections, there will be `ConnectionEstablished`
events emitted without eventually a matching `ConnectionClosed`
event. This seems undesirable and has the consequence that
the `Swarm::ban_peer_id` feature in `libp2p-swarm` does not
result in appropriate calls to `NetworkBehaviour::inject_connection_closed`
and `NetworkBehaviour::inject_disconnected`. Furthermore,
the `disconnect()` functionality in `libp2p-core` is currently
broken as it leaves the `Pool` in an inconsistent state.
This commit does the following:
1. When connection background tasks are dropped
(i.e. removed from the `Manager`), they
always terminate immediately, without attempting
an orderly close of the connection.
2. An orderly close is sent to the background task
of a connection as a regular command. The
background task emits a `Closed` event
before terminating.
3. `Pool::disconnect()` removes all connection
tasks for the affected peer from the `Manager`,
i.e. without an orderly close, thereby also
fixing the discovered state inconsistency
due to not removing the corresponding entries
in the `Pool` itself after removing them from
the `Manager`.
4. A new test is added to `libp2p-swarm` that
exercises the ban/unban functionality and
places assertions on the number and order
of calls to the `NetworkBehaviour`. In that
context some new testing utilities have
been added to `libp2p-swarm`.
This addresses https://github.com/libp2p/rust-libp2p/issues/1584.
* Update swarm/src/lib.rs
Co-authored-by: Toralf Wittner <tw@dtex.org>
* Incorporate some review feedback.
* Adapt to changes in master.
* More verbose panic messages.
* Simplify
There is no need for a `StartClose` future.
* Fix doc links.
* Further small cleanup.
* Update CHANGELOGs and versions.
Co-authored-by: Toralf Wittner <tw@dtex.org>
This adds optional message signing and verification to the gossipsub protocol as
per the libp2p specifications.
In addition this commit:
- Removes the LruCache received cache and simply uses the memcache in it's
place.
- Send subscriptions to all peers
- Prevent invalid messages from being gossiped
- Send grafts when subscriptions are added to the mesh
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Rüdiger Klaehn <rklaehn@protonmail.com>
Co-authored-by: Rüdiger Klaehn <rklaehn@gmail.com>
Signal the end of stream as `None` instead of producing a broken pipe error.
This restores the behaviour prior to PR #1196. I could not find a motivation
for this particular change in the PR and the previous implementation looks
correct to me.
* Add debug instances for MessageCache and GossipSub behaviour
* Manual impl of Debug for GossipsubMessage
* Add pretty printing of protocol_id in debug
* Use hex_fmt instead of hex
* Inline StringOrBytes helper struct
Since it is used only once here
* Limit data of gossipsub msg to 20 bytes
Otherwise they might become very large and useless for debugging
* core-derive: use full qualified name when polling NetworkBehaviour
If the users define a custom poll method also named in `poll` like
`#[behaviour(poll_method = "poll")`, it will cause issues as the wrong
`poll` method being called.
So use full qualified name to avoid ambiguity.
Fixes#1679.
* Update changelog for patch release.
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Roman S. Borschel <roman@parity.io>
* Refactor the bandwidth logging to be less magic
* Apply suggestions from code review
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
* Complete renaming.
* Update changelog.
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: Roman S. Borschel <roman@parity.io>
* 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.