1560 Commits

Author SHA1 Message Date
Roman Borschel
6a1279407e
[noise] Remove (by default) support for receiving legacy handshakes. (#1685)
* Remove (by default) support for receiving legacy noise handshakes.

* Update noise version.
2020-09-01 11:20:57 +02:00
Roman S. Borschel
f2c43527f4 Prepare multiaddr-0.9.2 2020-08-31 17:22:43 +02:00
Roman S. Borschel
1c7f6b1c11 Update libp2p-kad changelog. 2020-08-31 17:19:02 +02:00
Max Inden
0136af5025
protocols/kad: Implement ilog2 for Distance (#1719)
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.
2020-08-28 09:00:07 +02:00
Pierre Krieger
73f596ef32
Re-export the wasm-ext/websocket feature from the frontend crate (#1718) 2020-08-27 11:33:32 +02:00
Max Inden
293f2f83af
docs/release.md: Add release documentation (#1712)
* 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
2020-08-27 11:32:27 +02:00
Roman Borschel
7b415d5e70
Remove temporary peer ID compatibility mode. (#1608)
* 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>
2020-08-26 13:03:35 +02:00
Roman S. Borschel
5f7b7d22ab Update core changelog. 2020-08-24 10:48:36 +02:00
André Silva
b601ed41b1
core: remove duplicates when performing address translation (#1697)
* 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>
2020-08-24 10:46:54 +02:00
Toralf Wittner
0b05b21093
Add ProtocolsHandler::InboundOpenInfo. (#1714)
* Add `ProtocolsHandler::InboundOpenInfo`.

* Update swarm/src/protocols_handler/multi.rs

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

* Update CHANGELOGs and versions.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-08-23 16:57:20 +02:00
Max Inden
740a2e0235
protocols/kad/src/kbuckets: Explicitly convert u8 to usize (#1716)
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>
2020-08-19 17:44:41 +02:00
Max Inden
3d07a05f8b
*: Prepare v0.24.0 release (#1713)
* */CHANGELOG: Update dates

* Cargo.toml: Update to 0.24.0
2020-08-18 17:04:34 +02:00
Roman S. Borschel
d3b1c5d0b0 Update swarm changelog. 2020-08-18 16:28:22 +02:00
Toralf Wittner
21f9447796
Implement ProtocolsHandler methods in wrappers. (#1710)
* 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`.
2020-08-18 16:27:02 +02:00
Max Inden
cbdbf656c0
protocols/mdns: Make libp2p-mdns socket agnostic (#1699)
Allow libp2p-mdns to use either async-std or tokio to drive required UDP
socket.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-08-18 14:51:03 +02:00
Toralf Wittner
b4ad2d6297
Disable RequestResponse::throttled. (#1711)
Can be enabled again after #1706 is resolved.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-08-18 14:29:38 +02:00
Roman Borschel
e1df920703
[kad] Store addresses of provider records. (#1708)
* 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>
2020-08-18 14:14:31 +02:00
Arnaud Lefebvre
269a2ac2a8
Examples: adapt distributed-key-value-store to also GET / PUT providers (#1704)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-08-17 16:30:45 +02:00
Roman S. Borschel
9dd1309040 Changelog updates. 2020-08-17 10:14:44 +02:00
Toralf Wittner
91d50b2723
Custom yamux mode (#1691)
* 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>
2020-08-17 10:07:41 +02:00
Arnaud Lefebvre
d1024d272c
protocols/kad: fix doc for the event emitted by start_providing (#1705) 2020-08-14 16:10:39 +02:00
Roman Borschel
96484fcd5e
Fix connection keep-alive for request-response. (#1700) 2020-08-13 13:13:23 +02:00
Toralf Wittner
7d47ada077
Fix ping test in request-response. (#1702)
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.
2020-08-13 12:49:16 +02:00
Rüdiger Klaehn
0d26f50304
protocols/gossipsub: Add public accessors (#1677)
Co-authored-by: Toralf Wittner <tw@dtex.org>
Co-authored-by: Max Inden <mail@max-inden.de>
2020-08-13 12:10:52 +02:00
Max Inden
e32ff74809
swarm/one_shot: Initialize handler with KeepAlive::Until (#1698)
* 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
2020-08-13 11:18:20 +02:00
Age Manning
9eca739331
protocols/gossipsub/CHANGELOG: Add entry for signing config
Co-authored-by: Toralf Wittner <tw@dtex.org>
2020-08-12 17:59:16 +02:00
Toralf Wittner
30de0b4d64
Add Throttled to libp2p-request-response. (#1696)
* 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>
2020-08-12 16:04:54 +02:00
Roman Borschel
b595972961
[ping] Refactor the ping protocol for conformity. (#1692)
* 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>
2020-08-10 12:54:55 +02:00
Roman S. Borschel
5cd981b875 Update swarm changelog. 2020-08-10 10:13:50 +02:00
Ashley
b6ec95eb77
Add as_ref and as_mut functions to Toggle (#1684) 2020-08-10 10:11:58 +02:00
Guillaume GONI
32df8ea192
add missing feature flag for "noise" to build_tcp_ws_noise_mplex_yamux and build_development_transport (#1693)
* add missing feature flag for noise to build_tcp_ws_noise_mplex_yamux and build_development_transport

* removing useless secio feature flags
2020-08-10 08:29:07 +02:00
Max Inden
5139ec3ace
protocols/kad: Implement NetworkBehaviour::inject_address_change (#1649)
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.
2020-08-06 15:35:24 +02:00
Max Inden
7601514eb8
protocols/kad: Expose kbucket distance range (#1680)
Add `KBucketRef::range` exposing the minimum inclusive and maximum
inclusive `Distance` for the bucket.
2020-08-06 10:20:32 +02:00
Niklas Adolfsson
18390fa38e
[core]: fix typo in CHANGELOG.md (#1688) 2020-08-04 23:13:38 +02:00
Roman Borschel
8e1d4edb8b
[core/swarm] Emit events for active connection close and fix disconnect(). (#1619)
* 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>
2020-08-04 11:30:09 +02:00
Roman S. Borschel
67f1b94907 Bump version. 2020-08-03 14:56:55 +02:00
Roman S. Borschel
48efd4a2dd Set release date. 2020-08-03 14:53:20 +02:00
Roman Borschel
e0e5dfbe50
[libp2p-noise] Disable sending of legacy handshake payloads (by default). (#1669)
* [libp2p-noise] Disable sending of legacy handshake payloads.

* Update build_development_transport() to use libp2p-noise.

* Update feature flags.

* Replace feature flag by config options.

* Cleanup

* Cleanup

* Cleanup
2020-08-03 14:52:34 +02:00
Age Manning
d8ad7bddf5
protocols/gossipsub: Add message signing and verification configuration (#1583)
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>
2020-08-03 10:13:43 +02:00
Toralf Wittner
d0ad105433
memory: Do not return broken pipe error on EOF. (#1683)
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.
2020-07-31 12:20:21 +02:00
folex
3fb829f61b
Merge pull request #28 from fluencelabs/merge_upstream
Merge upstream
2020-07-30 17:14:44 +03:00
folex
8b6a5db985 Merge branch 'rust_master' into fluence_master
# Conflicts:
#	protocols/kad/src/behaviour.rs
#	protocols/kad/src/query.rs
2020-07-30 16:36:51 +03:00
Roman S. Borschel
3ebe916ef3 Update gossipsub changelog. 2020-07-29 09:28:04 +02:00
Rüdiger Klaehn
9662929f38
Debug instance for the gossipsub behaviour (#1673)
* 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
2020-07-29 09:25:53 +02:00
Cheng XU
967f39656a
core-derive: use full qualified name when polling NetworkBehaviour (#1681)
* 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>
2020-07-28 13:26:27 +02:00
Demi Obenour
9178459cc8
Automatic fixes by cargo-fix (#1662) 2020-07-27 22:27:33 +02:00
Pierre Krieger
8a08f72e84
Refactor the bandwidth logging to be less magic (#1670)
* 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>
2020-07-27 11:05:59 +02:00
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
folex
09982bbe7e
Merge pull request #27 from fluencelabs/merge_upstream 2020-07-17 13:24:07 +03:00
folex
30c0a5f51b Merge branch 'rust_master' into fluence_master
# Conflicts:
#	protocols/secio/benches/bench.rs
2020-07-17 13:05:17 +03:00