481 Commits

Author SHA1 Message Date
Max Inden
0934b0178d
*: Prepare v0.36.0 release 2021-03-17 15:28:13 +01:00
Roman Borschel
45f07bf863
[libp2p-dns] Implement /dnsaddr resolution. (#1931)
* Implement `/dnsaddr` support on `libp2p-dns`.

To that end, since resolving `/dnsaddr` addresses needs
"fully qualified" multiaddresses when dialing, i.e. those
that end with the `/p2p/...` protocol, we make sure that
dialing always uses such fully qualified addresses by
appending the `/p2p` protocol as necessary. As a side-effect,
this adds support for dialing peers via "fully qualified"
addresses, as an alternative to using a `PeerId` together
with a `Multiaddr` with or without the `/p2p` protocol.

* Adapt libp2p-relay.

* Update versions, changelogs and small cleanups.
2021-03-17 10:53:19 +01:00
Max Inden
c6a21047d7
protocols/relay: Ignore IdentifyEvent::Error (#2001)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2021-03-16 13:22:42 +01:00
dependabot[bot]
9dbc90efe7
Update socket2 requirement from 0.3.19 to 0.4.0 (#1997)
* Update socket2 requirement from 0.3.19 to 0.4.0

Updates the requirements on [socket2](https://github.com/rust-lang/socket2) to permit the latest version.
- [Release notes](https://github.com/rust-lang/socket2/releases)
- [Changelog](https://github.com/rust-lang/socket2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/socket2/compare/v0.3.19...v0.3.19)

Signed-off-by: dependabot[bot] <support@github.com>

* Adapt to API and feature changes.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Roman S. Borschel <roman@parity.io>
2021-03-15 17:33:49 +01:00
dependabot[bot]
375690d396
Update minicbor requirement from 0.7 to 0.8 (#1998)
Updates the requirements on [minicbor](https://gitlab.com/twittner/minicbor) to permit the latest version.
- [Release notes](https://gitlab.com/twittner/minicbor/tags)
- [Changelog](https://gitlab.com/twittner/minicbor/blob/master/CHANGELOG.md)
- [Commits](https://gitlab.com/twittner/minicbor/compare/minicbor-v0.7.0...minicbor-v0.8.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-15 15:17:16 +01:00
Max Inden
d792998497
*: Require smallvec >= 1.6.1 (#1994)
Versions <1.6.1 are vulnerable to a buffer overflow. See
https://rustsec.org/advisories/RUSTSEC-2021-0003.html for details.
2021-03-15 12:31:21 +01:00
dependabot[bot]
f6bc807055
Update env_logger requirement from 0.7.1 to 0.8.3 (#1992)
Updates the requirements on [env_logger](https://github.com/env-logger-rs/env_logger) to permit the latest version.
- [Release notes](https://github.com/env-logger-rs/env_logger/releases)
- [Changelog](https://github.com/env-logger-rs/env_logger/blob/master/CHANGELOG.md)
- [Commits](https://github.com/env-logger-rs/env_logger/commits/v0.8.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-03-12 15:32:35 +01:00
Max Inden
e9e366cbe8
protocols/kad/tests: Ignore Kademlia routing update event (#1993)
In the `libp2p-relay` Kademlia discovery test, ignore Kademlia routing
update events when waiting for a ping from the destination node.
2021-03-11 18:16:33 +01:00
Max Inden
0c412fbc1c
protocols/req-resp: Panic in inbound upgrade when handler dropped (#1990)
An inbound upgrade should not be polled after the corresponding handler
has been dropped. Enforce this assumption by panicing in such case.
2021-03-11 16:54:18 +01:00
Max Inden
2f9c1759e6
protocols/relay: Implement circuit relay specification (#1838)
This commit implements the [libp2p circuit
relay](https://github.com/libp2p/specs/tree/master/relay) specification. It is
based on previous work from https://github.com/libp2p/rust-libp2p/pull/1134.

Instead of altering the `Transport` trait, the approach taken in this commit
is to wrap an existing implementation of `Transport` allowing one to:

- Intercept `dial` requests with a relayed address.

- Inject incoming relayed connections with the local node being the destination.

- Intercept `listen_on` requests pointing to a relay, ensuring to keep a
  constant connection to the relay, waiting for incoming requests with the local
  node being the destination.

More concretely one would wrap an existing `Transport` implementation as seen
below, allowing the `Relay` behaviour and the `RelayTransport` to communicate
via channels.

### Example

```rust
let (relay_transport, relay_behaviour) = new_transport_and_behaviour(
    RelayConfig::default(),
    MemoryTransport::default(),
);

let transport = relay_transport
    .upgrade(upgrade::Version::V1)
    .authenticate(plaintext)
    .multiplex(YamuxConfig::default())
    .boxed();

let mut swarm = Swarm::new(transport, relay_behaviour, local_peer_id);

let relay_addr = Multiaddr::from_str("/memory/1234").unwrap()
    .with(Protocol::P2p(PeerId::random().into()))
    .with(Protocol::P2pCircuit);
let dst_addr = relay_addr.clone().with(Protocol::Memory(5678));

// Listen for incoming connections via relay node (1234).
Swarm::listen_on(&mut swarm, relay_addr).unwrap();

// Dial node (5678) via relay node (1234).
Swarm::dial_addr(&mut swarm, dst_addr).unwrap();
```

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: David Craven <david@craven.ch>
2021-03-11 16:07:59 +01:00
Roman Borschel
f48bb15fa7
[kad] Provide a targeted store operation. (#1988)
* Add `Kademlia::put_record_to` for storing a record at specific nodes,
e.g. for write-back caching after a successful read. In that context,
peers that were queried in a successful `Kademlia::get_record` operation but
did not return a record are now returned in the `GetRecordOk::no_record`
list of peer IDs.

Closes https://github.com/libp2p/rust-libp2p/issues/1577.

* Update protocols/kad/src/behaviour.rs

Co-authored-by: Max Inden <mail@max-inden.de>

* Refine implementation.

Rather than returning the peers that are cache candidates
in a `Vec` in an arbitrary order, use a `BTreeMap`. Furthermore,
make the caching configurable, being enabled by default with
`max_peers` of 1. By configuring it with `max_peers` > 1 it is
now also possible to control at how many nodes the record is cached
automatically after a lookup with quorum 1. When enabled,
successful lookups will always return `cache_candidates`, which
can be used explicitly with `Kademlia::put_record_to` after
lookups with a quorum > 1.

* Re-export KademliaCaching

* Update protocols/kad/CHANGELOG.md

Co-authored-by: Max Inden <mail@max-inden.de>

* Clarify changelog.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-03-09 18:35:43 +01:00
Max Inden
67c465c726
protocols/request-response: Update CHANGELOG.md 2021-03-09 17:54:23 +01:00
Thomas Eizinger
ed6f972162
protocols/request-response: Close response stream even if response cannot be sent (#1987)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-03-09 17:50:57 +01:00
David Craven
b727efee13
Don't poll network unnecessarily. (#1977)
* Don't poll network unnecessarily.

* Fix ci.

* Damn tokio.

* Address review comments.

* Update deps.

* Don't drop packet if socket is not writable.

* Increase TTL and rename to `query_interval`.

* Update CHANGELOG.

Co-authored-by: Roman S. Borschel <roman@parity.io>
2021-03-02 10:18:24 +01:00
Pierre Krieger
b81100c2f6
Parsing mDNS packet failure: warn -> debug (#1978)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2021-02-25 15:41:47 +01:00
Roman Borschel
7dd42fcaaf
[swarm] Remove substream-specific protocol negotiation version. (#1962)
* Remove substream-specific protocol negotiation version.

Remove the option for a substream-specific multistream select protocol override.
The override at this granularity is no longer deemed useful, in particular because
it can usually not be configured for existing protocols like `libp2p-kad` and others.
There is a `Swarm`-scoped configuration for this version available since
[1858](https://github.com/libp2p/rust-libp2p/pull/1858).

* Update protocol crate versions and changelogs.

* Clean up documentation.
2021-02-25 11:35:52 +01:00
Roman Borschel
cda7c3504e
Prepare v0.35 (#1957) 2021-02-15 20:06:50 +01:00
Max Inden
26f6b96d1e
*: Require at least if-watch v0.1.8 (#1956) 2021-02-15 16:11:30 +01:00
Roman Borschel
6499e924a3
Make clippy "happy". (#1950)
* Make clippy "happy".

Address all clippy complaints that are not purely stylistic (or even
have corner cases with false positives). Ignore all "style" and "pedantic" lints.

* Fix tests.

* Undo unnecessary API change.
2021-02-15 11:59:51 +01:00
dependabot[bot]
639e5c678e
Update unsigned-varint and asynchronous-codec (#1946)
* Update unsigned-varint requirement from 0.6 to 0.7

Updates the requirements on [unsigned-varint](https://github.com/paritytech/unsigned-varint) to permit the latest version.
- [Release notes](https://github.com/paritytech/unsigned-varint/releases)
- [Changelog](https://github.com/paritytech/unsigned-varint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/paritytech/unsigned-varint/compare/v0.6.0...v0.7.0)

Signed-off-by: dependabot[bot] <support@github.com>

* *: Update to asynchronous-codec v0.6

* transports/plaintext: Use Framed::into_parts

* *: Update cargo tomls and changelogs

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-02-13 20:15:14 +01:00
Tejas Sanap
40ce05f37e
protocols/request-response: Test is_pending_outbound (#1938)
Signed-off-by: Tejas Sanap <sanap.tejas@gmail.com>
2021-02-10 18:03:44 +01:00
Roman Borschel
d94d53abbb
Move some crates. (#1941)
Move transport upgrade protocols from `protocols/`
to `transports/`, such that only "application protocols"
that depend on `libp2p-swarm` remain in `protocols/`,
whereas there is no such dependency in `transports/`
outside of integration tests.

Tweak README and top-level CHANGELOG.
2021-02-01 16:37:19 +01:00
Roman Borschel
2ecf42a2bf
[libp2p-secio] Remove crate. (#1940)
* Remove the SECIO transport protocol.

* Remove stray mentions of secio.
2021-02-01 14:39:44 +01:00
Max Inden
1a01dd16cb
protocols/req-resp: Document uniqueness of RequestIds (#1943) 2021-02-01 14:32:47 +01:00
Roman Borschel
6d0773b68e
[libp2p-deflate] Ensure read buffer is initialised. (#1933)
* Ensure read buffer is initialised.

* Prepare libp2p-deflate-0.27.1.
2021-01-27 13:29:30 +01:00
Max Inden
6400719ae9
protocols/request-response: Add forgotten changelog entry 2021-01-21 15:40:26 +01:00
Max Inden
25ea8b67ff
*: Update changelogs and cargo tomls for req-resp patch 2021-01-21 14:36:58 +01:00
Tejas Sanap
5d22e30cc9
protocols/req-resp: Make is_pending_outbound return true on pending connection (#1928)
`is_pending_outbound` should return true if the connection
to the mentioned peer hasn't been established, yet.

Closes issue: #1885

Signed-off-by: Tejas Sanap <sanap.tejas@gmail.com>
2021-01-21 14:34:58 +01:00
Max Inden
bbd3df64ed
*: Update changelogs and cargo tomls for gossipsub change 2021-01-20 10:50:23 +01:00
Age Manning
eac43d144f
protocols/gossipsub: Prevent non-published messages being added to caches (#1930)
Currently, Gossipsub messages may not be published on a topic if there are no
subscribed peers on that topic, however they are being added to a duplicate
cache. If the messages are content-addressed, this prevents the user from
attempting to republish the message in the future.

This commit modifies the logic such that messages are only added to the caches
(duplicate, memcache and published_messages) if the message could be published
to at least one peer.

Previously, a failed publish would be added the memcache. This meant that the
router would gossip about a failed publish, such that if a peer joined the topic
after the failed publish (but within the gossip history time window) the message
could still be propagated to the newly connected peers. With this PR, a failed
publish now definitively indicates the message will not be published on the
network and the user is required to re-submit at a later time, once sufficient
peers exist on the topic.
2021-01-20 10:47:05 +01:00
wackbyte
75b5fdfbca
Fix a typo in gossipsub (#1921) 2021-01-13 08:44:07 +01:00
Max Inden
9aaa624147
protocols/gossipsub/Cargo.toml: Fix feature name typo 2021-01-12 21:07:18 +01:00
Max Inden
db02cfae37
*: Prepare v0.34.0 release (#1918)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2021-01-12 20:33:43 +01:00
Max Inden
a10f4e2879
*: Update to tokio v1.0.1 (#1919)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2021-01-12 15:50:24 +01:00
Max Inden
477f7ae6c4
*: Update to prost-build v0.7 (#1917) 2021-01-12 14:41:07 +01:00
dependabot[bot]
7367927bd8
Update uint requirement from 0.8 to 0.9 (#1915)
Updates the requirements on [uint](https://github.com/paritytech/parity-common) to permit the latest version.
- [Release notes](https://github.com/paritytech/parity-common/releases)
- [Commits](https://github.com/paritytech/parity-common/compare/uint-v0.8.3...uint-v0.9.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-01-12 13:53:51 +01:00
Roman Borschel
ec0f8a3150
[tcp] Port-reuse, async-io, if-watch (#1887)
* Update tomls.

* Let transports decide when to translate.

* Improve tcp transport.

* Update stuff.

* Remove background task. Enhance documentation.

To avoid spawning a background task and thread within
`TcpConfig::new()`, with communication via unbounded channels,
a `TcpConfig` now keeps track of the listening addresses
for port reuse in an `Arc<RwLock>`. Furthermore, an `IfWatcher`
is only used by a `TcpListenStream` if it listens on any interface
and directly polls the `IfWatcher` both for initialisation and
new events.

Includes some documentation and test enhancements.

* Reintroduce feature flags for tokio vs async-io.

To avoid having an extra reactor thread running for tokio
users and to make sure all TCP I/O uses the mio-based
tokio reactor.

Thereby run tests with both backends.

* Add missing files.

* Fix docsrs attributes.

* Update transports/tcp/src/lib.rs

Co-authored-by: Max Inden <mail@max-inden.de>

* Restore chat-tokio example.

* Forward poll_write_vectored for tokio's AsyncWrite.

* Update changelogs.

Co-authored-by: David Craven <david@craven.ch>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-01-12 13:35:11 +01:00
Max Inden
c98b9ef407
*: Switch futures_codec to asynchronous-codec (#1908)
`futures-codec` has not been updated in the recent months. It still
depends on `bytes` `v0.5` preventing all downstream dependencies to
upgrade to `bytes` `v1.0`.

This commit replaces `futures_codec` in favor of `asynchronous-codec`
The latter is a fully upgraded fork of the former.

In addition this commit upgrades:

- bytes to v1
- unsigned-varint to v0.6.0
- prost to v0.7
2021-01-12 12:48:37 +01:00
Max Inden
5be6a8bb72
protocols/kad: Prepare v0.27.1 patch release 2021-01-11 12:26:04 +01:00
Ivan Zderadicka
6538745b64
protocols/kad: Add From impl for kbucket::Key (#1909)
- From<record::Key>
- From<Vec<u8>

This will enable to use additional types in kad.get_closest_peers as it was
possible in pre 0.33 version.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-01-11 12:23:36 +01:00
Age Manning
df7e73ec47
protocols/gossipsub: Add Gossipsub v1.1 support
This commit upgrades the current gossipsub implementation to support the [v1.1
spec](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md).

It adds a number of features, bug fixes and performance improvements. 

Besides support for all new 1.1 features, other improvements that are of particular note: 

- Improved duplicate LRU-time cache (this was previously a severe bottleneck for
  large message throughput topics)
- Extended message validation configuration options
- Arbitrary topics (users can now implement their own hashing schemes)
- Improved message validation handling - Invalid messages are no longer dropped
  but sent to the behaviour for application-level processing (including scoring)
- Support for floodsub, gossipsub v1 and gossipsub v2
- Protobuf encoding has been shifted into the behaviour. This has permitted two
  improvements:
     1. Message size verification during publishing (report to the user if the
        message is too large before attempting to send).
     2. Message fragmentation. If an RPC is too large it is fragmented into its
        sub components and sent in smaller chunks.

Additional Notes

The peer eXchange protocol defined in the v1.1 spec is inactive in its current
form. The current implementation permits sending `PeerId` in `PRUNE` messages,
however a `PeerId` is not sufficient to form a new connection to a peer. A
`Signed Address Record` is required to safely transmit peer identity
information. Once these are confirmed (https://github.com/libp2p/specs/pull/217)
a future PR will implement these and make PX usable.

Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Rüdiger Klaehn <rklaehn@protonmail.com>
Co-authored-by: blacktemplar <blacktemplar@a1.net>
Co-authored-by: Rüdiger Klaehn <rklaehn@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Roman S. Borschel <roman@parity.io>
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: David Craven <david@craven.ch>
2021-01-07 08:19:31 +01:00
Max Inden
d918e9a79d
*: Update changelogs and cargo tomls for new reqresp release 2021-01-04 18:51:05 +01:00
David Craven
6a85eb46fc
Re-export throttled-specific response channel (#1902) 2021-01-04 18:45:01 +01:00
Max Inden
dd9f56e7f9
*CHANGELOG.md: Prepare v0.33.0 release (#1895) 2020-12-18 10:03:20 +01:00
Max Inden
22817b5d2b
swarm: Remove NotifyHandler::All (#1880)
Remove `NotifyHandler::All` thus removing the requirement for events
send from a `NetworkBehaviour` to a `ProtocolsHandler` to be `Clone`. An
implementor of `NetworkBehaviour` can still notify all
`ProtocolHandler`s for a given peer by emitting one `NotifyHandler`
event per connection to that peer.
2020-12-17 11:01:45 +01:00
dependabot[bot]
6c970f0dda
Update pin-project requirement from 0.4.17 to 1.0.2 (#1894)
Updates the requirements on [pin-project](https://github.com/taiki-e/pin-project) to permit the latest version.
- [Release notes](https://github.com/taiki-e/pin-project/releases)
- [Changelog](https://github.com/taiki-e/pin-project/blob/master/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/pin-project/commits/v1.0.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-12-16 17:50:45 +01:00
Max Inden
447b2d315d
*: Update Cargo tomls and changelogs for libp2p-pnet v0.20.0 2020-12-16 17:02:14 +01:00
elenaf9
80a1ac845e
fix(pns): patch salsa20 dependency (#1892)
Co-authored-by: Max Inden <mail@max-inden.de>
2020-12-16 16:56:49 +01:00
Max Inden
0968b049fe
protocols/request-response: Derive Clone for {Inbound,Outbound}Failure (#1891) 2020-12-16 16:38:45 +01:00
Max Inden
3af5ba45f3
protocols/request-response: Emit InboundFailure::ConnectionClosed (#1886)
A user of libp2p-request-response is guaranteed to receive an additional event
after receiving a request via `RequestResponseEvent::Message`.

After receiving the request:

- If the user responds in time and the connection is still alive, the
user can expect a `ResponseSent`.

- If the user drops the response channel, the user can expect an
`InboundFailure::ResponseOmission`.

- If the user does not respond in time, the user can expect an
`InboundFailure::Timeout`.

Thus far the user did not receive an event when the connection to the
peer closes. With this commit:

- If the connection to the peer closes before the users calls
`send_response` or after the user calls `send_response` but before the
response can be send on the network, the user can expect an
`InboundFailure::ConnectionClosed`.
2020-12-16 16:03:35 +01:00