42 Commits

Author SHA1 Message Date
Dan Shields
a7ed1d6b6e
*: Migrate to Rust 2021 edition (#2339)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-26 17:34:58 +01:00
Divma
fd417517ca
swarm/: Patch reporting on banned peer connections (#2350)
Don't report events of a connection to the `NetworkBehaviour`, if connection has
been established while the remote peer was banned. Among other guarantees this
upholds that `NetworkBehaviour::inject_event` is never called without a previous
`NetworkBehaviour::inject_connection_established` for said connection.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-26 16:48:12 +01:00
Max Inden
4bd44c812a
*: Prepare v0.41.0 (#2342) 2021-11-16 16:39:42 +01:00
Max Inden
220f84a97f
swarm/: Enable advanced dialing requests (#2317)
Enable advanced dialing requests both on `Swarm` and via
`NetworkBehaviourAction`. Users can now trigger a dial with a specific
set of addresses, optionally extended via
`NetworkBehaviour::addresses_of_peer`. In addition the whole process is
now modelled in a type safe way via the builder pattern.

Example of a `NetworkBehaviour` requesting a dial to a specific peer
with a set of addresses additionally extended through
`NetworkBehaviour::addresses_of_peer`:

```rust
NetworkBehaviourAction::Dial {
    opts: DialOpts::peer_id(peer_id)
              .condition(PeerCondition::Always)
              .addresses(addresses)
              .extend_addresses_through_behaviour()
              .build(),
    handler,
}
```

Example of a user requesting a dial to an unknown peer with a single
address via `Swarm`:

```rust
swarm1.dial(
    DialOpts::unknown_peer_id()
        .address(addr2.clone())
        .build()
)
```
2021-11-15 14:17:23 +01:00
Max Inden
012287ad1e
Merge branch 'libp2p/v0.40' into master (#2324)
* *: Prepare v0.40.0 release (#2323)

* Cargo.toml: Remove rc suffix
2021-11-02 20:40:48 +01:00
Max Inden
ff5d455ccf
*: Enable libp2p to run via wasm32-unknown-unknown in the browser (#2320)
Changes needed to get libp2p to run via `wasm32-unknown-unknown` in the browser
(both main thread and inside web workers).

Replaces wasm-timer with futures-timer and instant.

Co-authored-by: Oliver Wangler <oliver@wngr.de>
2021-10-30 12:41:30 +02:00
Max Inden
a905665b8b
*: Prepare v0.40.0-rc.1 release (#2290) 2021-10-15 11:15:05 +02:00
Max Inden
40c5335e3b
core/: Concurrent dial attempts (#2248)
Concurrently dial address candidates within a single dial attempt.

Main motivation for this feature is to increase success rate on hole punching
(see https://github.com/libp2p/rust-libp2p/issues/1896#issuecomment-885894496
for details). Though, as a nice side effect, as one would expect, it does
improve connection establishment time.

Cleanups and fixes done along the way:

- Merge `pool.rs` and `manager.rs`.

- Instead of manually implementing state machines in `task.rs` use
  `async/await`.

- Fix bug where `NetworkBehaviour::inject_connection_closed` is called without a
  previous `NetworkBehaviour::inject_connection_established` (see
  https://github.com/libp2p/rust-libp2p/issues/2242).

- Return handler to behaviour on incoming connection limit error. Missed in
  https://github.com/libp2p/rust-libp2p/issues/2242.
2021-10-14 18:05:07 +02:00
dependabot[bot]
c0d7d4a9eb
build(deps): Update prost-build requirement from 0.8 to 0.9 (#2288)
Updates the requirements on [prost-build](https://github.com/tokio-rs/prost) to permit the latest version.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: prost-build
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-14 14:44:34 +02:00
dependabot[bot]
3cc102da91
build(deps): Update prost requirement from 0.8 to 0.9 (#2287)
Updates the requirements on [prost](https://github.com/tokio-rs/prost) to permit the latest version.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: prost
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-14 14:16:54 +02:00
Thomas Eizinger
e83e1b3d0b
swarm-derive/: Make event_process = false the default (#2214)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-09-14 15:28:08 +02:00
Roman
b79fd02f0b
*: Fix clippy warnings (#2227) 2021-09-14 15:00:05 +02:00
Thomas Eizinger
c1ae8a046c
protocols/ping: Revise naming of symbols (#2215)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-09-06 16:10:48 +02:00
Max Inden
c161acfb50
*: Dial with handler and return handler on error and closed (#2191)
Require `NetworkBehaviourAction::{DialPeer,DialAddress}` to contain a
`ProtocolsHandler`. This allows a behaviour to attach custom state to its
handler. The behaviour would no longer need to track this state separately
during connection establishment, thus reducing state required in a behaviour.
E.g. in the case of `libp2p-kad` the behaviour can include a `GetRecord` request
in its handler, or e.g. in the case of `libp2p-request-response` the behaviour
can include the first request in the handler.

Return `ProtocolsHandler` on connection error and close. This allows a behaviour
to extract its custom state previously included in the handler on connection
failure and connection closing. E.g. in the case of `libp2p-kad` the behaviour
could extract the attached `GetRecord` from the handler of the failed connection
and then start another connection attempt with a new handler with the same
`GetRecord` or bubble up an error to the user.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-08-31 17:00:51 +02:00
Ruben De Smet
f2905c07f1
*: Make libp2p-core default features optional (#2181)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-08-18 12:08:45 +02:00
Max Inden
f701b24ec0
*: Format with rustfmt (#2188)
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-08-11 13:12:12 +02:00
Max Inden
008561283e
core/: Remove TInEvent and TOutEvent (#2183)
TInEvent and TOutEvent are implied through THandler and thus
superflucious. Both are removed in favor of a derivation through
THandler.
2021-08-11 12:41:28 +02:00
Max Inden
841b09aa69
protocols/relay/tests: Remove unused DummyPollParameters (#2172) 2021-07-31 21:40:50 +02:00
Thomas Eizinger
1e001a2e0e
protocols/ping: Don't force close conn if not supported by remote (#2149)
Don't close connection if ping protocol is unsupported by remote. Previously, a
failed protocol negotation for ping caused a force close of the connection. As a
result, all nodes in a network had to support ping. To allow networks where some
nodes don't support ping, we now emit `PingFailure::Unsupported` once for every
connection on which ping is not supported.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-30 22:21:21 +02:00
Thomas Eizinger
ad90167042
swarm/: Provide additional default impls on NetworkBehaviour (#2150)
Not all implementations of `NetworkBehaviour` need all callbacks.
We've have been adding new callbacks with default implementations
for a while now. There is no reason the initial ones cannot also
be defaulted, thus making it easier create new implementations.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-30 19:48:32 +02:00
Thomas Eizinger
7877929af2
.github/: Enforce no clippy warnings (#2148)
* Fix remaining clippy warnings.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-26 11:22:46 +02:00
Ruben De Smet
371a7dab2c
to/into consistency for PublicKey and PeerId (#2145)
- Change `PublicKey::into_protobuf_encoding` to
  `PublicKey::to_protobuf_encoding`.

- Change `PublicKey::into_peer_id` to `PublicKey::to_peer_id`.

- Change `PeerId::from_public_key(PublicKey)` to
  `PeerId::from_public_key(&PublicKey)`.

- Add `From<&PublicKey> for PeerId`.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-22 22:34:13 +02:00
dependabot[bot]
e1646a524b
build(deps): Update env_logger requirement from 0.8.1 to 0.9.0 (#2141)
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/main/CHANGELOG.md)
- [Commits](https://github.com/env-logger-rs/env_logger/compare/v0.8.3...v0.9.0)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-15 10:43:04 +02:00
Max Inden
b5c6fa6281
*: Prepare v0.39.0 release (#2132) 2021-07-12 21:24:58 +02:00
Elena Frank
99da27bd97
*: Patch prost / prost-build version to v0.8 (#2126) 2021-07-09 14:38:03 +02:00
Elena Frank
a414afd83c
swarm/: include ListenerId in SwarmEvents (#2123)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-08 11:41:33 +02:00
r-zig
f9491e7e81
protocols/relay: Simplify running the relay example (#2080)
Simplify running the relay example with all peers run via docker compose.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-06-30 22:13:36 +02:00
Max Inden
904880f5e9
protocols/kad: Extend emitted events with basic information (#2087)
* Expose kbucket range on RoutingUpdated.

* Expose inbound request information.

* Expose whether routing update is new peer.
2021-06-28 14:14:31 +02:00
Elena Frank
e8fed53598
swarm/: Drive ExpandedSwarm via Stream trait only (#2100)
Change `Stream` implementation of `ExpandedSwarm` to return all
`SwarmEvents` instead of only the `NetworkBehaviour`'s events.

Remove `ExpandedSwarm::next_event`. Users can use `<ExpandedSwarm as
StreamExt>::next` instead.

Remove `ExpandedSwarm::next`. Users can use `<ExpandedSwarm as
StreamExt>::filter_map` instead.
2021-06-14 20:41:44 +02:00
Max Inden
28fe6eda28
*: Use upstream multiaddr crate (#2075)
Use multiaddr instead of parity-multiaddr, removing the latter from the
repository.
2021-05-27 14:04:33 +02:00
Max Inden
43a8ad8fc2
protocols/relay/examples: Add client server instructions (#2060)
Add instructions on how to run a three node example where a listening
relay client listens via a relay server and a dialing relay client dials
the listening relay client via the relay server.
2021-05-10 15:39:56 +02:00
Max Inden
42441dbd86
*: Prepare v0.37.0 release (#2049) 2021-04-13 20:15:15 +02:00
David Craven
05aa794552
Derive debug for RelayConfig. (#2048)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-04-12 22:30:09 +02:00
Max Inden
63512e5f16
swarm/src/lib: Remove Deref and DerefMut impls on Swarm (#1995)
Remove `Deref` and `DerefMut` implementations previously dereferencing
to the `NetworkBehaviour` on `Swarm`. Instead one can access the
`NetworkBehaviour` via `Swarm::behaviour` and `Swarm::behaviour_mut`.
Methods on `Swarm` can now be accessed directly, e.g. via
`my_swarm.local_peer_id()`.

Reasoning: Accessing the `NetworkBehaviour` of a `Swarm` through `Deref`
and `DerefMut` instead of a method call is an unnecessary complication,
especially for newcomers. In addition, `Swarm` is not a smart-pointer
and should thus not make use of `Deref` and `DerefMut`, see documentation
from the standard library below.

> Deref should only be implemented for smart pointers to avoid
confusion.

https://doc.rust-lang.org/std/ops/trait.Deref.html
2021-03-18 14:55:33 +01:00
Roman Borschel
5a45f93fc2
[identify] Implement /ipfs/id/push/1.0.0 alongside some refactoring. (#1999)
* Implement /ipfs/id/push/1.0.0 alongside some refactoring.

  * Implement /ipfs/id/push/1.0.0, i.e. the ability to actively
    push information of the local peer to specific remotes.
  * Make the initial delay as well as the recurring delay
    for the periodic identification requests configurable,
    introducing `IdentifyConfig`.

* Fix test.

* Fix example.

* Update protocols/identify/src/identify.rs

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

* Update protocols/identify/src/identify.rs

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

* Update versions and changelogs.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-03-18 12:47:01 +01:00
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
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
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