100 Commits

Author SHA1 Message Date
Max Inden
ca07ce4d64
swarm/behaviour: Remove deprecated NetworkBehaviourEventProcess (#2840)
Removes the `NetworkBehaviourEventProcess` and all its associated logic.

See deprecation pull request https://github.com/libp2p/rust-libp2p/pull/2784.

Find rational in https://github.com/libp2p/rust-libp2p/pull/2751.
2022-08-26 07:08:33 +02:00
Max Inden
4253080a43
*: Prepare v0.47.0 (#2830) 2022-08-22 05:14:04 +02:00
tgmichel
c8066df232
*: Update to if-watch 1.1.1 (#2754) 2022-07-19 09:14:00 +02:00
Thomas Eizinger
1a553db596
core/muxing: Flatten StreamMuxer interface to poll_{inbound,outbound,address_change,close} (#2724)
Instead of having a mix of `poll_event`, `poll_outbound` and `poll_close`, we
flatten the entire interface of `StreamMuxer` into 4 individual functions:

- `poll_inbound`
- `poll_outbound`
- `poll_address_change`
- `poll_close`

This design is closer to the design of other async traits like `AsyncRead` and
`AsyncWrite`. It also allows us to delete the `StreamMuxerEvent`.
2022-07-18 05:20:11 +02:00
Chad Nehemiah
d0da3a0973
swarm/: Set default dial concurrency factor to 8 (#2741) 2022-07-07 11:20:03 +02:00
Max Inden
7df6bae520
*: Prepare v0.46.0 (#2730) 2022-07-05 13:09:58 +02:00
Elena Frank
62622a1bad
core/src/transport: Poll Transport directly, remove Transport::Listener (#2652)
Remove the concept of individual `Transport::Listener` streams from `Transport`.
Instead the `Transport` is polled directly via `Transport::poll`. The
`Transport` is now responsible for driving its listeners.
2022-07-04 04:16:57 +02:00
Thomas Eizinger
eb490c08e9
core/muxing: Force StreamMuxer::Substream to implement Async{Read,Write} (#2707)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-06-23 21:52:11 +10:00
Max Inden
6e1e314872
*: Prepare v0.45.0 (#2662) 2022-05-31 13:12:53 +02:00
Hubert
70d38520fd
*: Activate clippy::style lint group (#2620) 2022-05-03 13:11:48 +02:00
Max Inden
2ad905f35a
{core,swarm}/: Don't require Transport: Clone and take &mut (#2529)
Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods
on `Transport`, e.g. `Transport::dial` would take ownership, requiring
e.g. a `Clone::clone` before calling `Transport::dial`.

The requirement of `Transport` to be `Clone` is no longer needed in
`libp2p-swarm`. E.g.  concurrent dialing can be done without a clone per
dial.

This commit removes the requirement of `Clone` for `Transport` in
`libp2p-swarm`. As a follow-up methods on `Transport` no longer take
ownership, but instead a mutable reference (`&mut self`).

On the one hand this simplifies `libp2p-swarm`, on the other it
simplifies implementations of `Transport`.
2022-04-06 20:23:16 +02:00
Max Inden
f26adbcd84
*: Prepare libp2p v0.44.0 (#2604) 2022-04-04 18:27:41 +02:00
Max Inden
6cc3b4ec52
*: Import libp2p with default-features = false (#2574)
* *: Import `libp2p` with `default-features = false`

While not a win in most cases, it reduces compile time for tests of
individual crates.

* Cargo.toml: Set features for examples
2022-03-22 11:22:17 +01:00
Friedel Ziegelmayer
e2fcc47da6
swarm/src/behaviour: Remove Send bound from NetworkBehaviour (#2535)
The bound is no longer needed across the libp2p-XXX crates.

Co-authored-by: Max Inden <mail@max-inden.de>
2022-02-28 10:27:58 +01:00
Max Inden
b1859464c9
*: Prepare v0.43.0 (#2531) 2022-02-22 14:05:19 +01:00
Max Inden
fd2be38faf
swarm/: Rename ProtocolsHandler to ConnectionHandler (#2527)
A `ProtocolsHandler`, now `ConnectionHandler`, handels a connection, not
a protocol. Thus the name `CONNECTIONHandler` is more appropriate.

Next to the rename of `ProtocolsHandler` this commit renames the `mod
protocols_handler` to `mod handler`. Finally all combinators (e.g.
`ProtocolsHandlerSelect`) are renamed appropriately.
2022-02-21 13:32:24 +01:00
Nazar Mokrynskyi
65cc8994a6
*: Derive Debug and Clone(#2495)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-02-16 16:16:54 +01:00
Divma
dc8433e3fc
swarm/src/behaviour: Merge inject_* paired methods (#2445)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-02-09 16:08:28 +01:00
Volker Mische
a2c93fc766
*: Update multihash and multiaddr (#2469)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-02-03 17:38:41 +01:00
Max Inden
e6ccfbc4e7
*: Prepare v0.42.0 (#2440) 2022-01-27 11:29:09 +01:00
hanabi1224
fad99808ac
*: Update tokio, lru and prost (#2443) 2022-01-20 09:43:32 +01:00
Elena Frank
ddc035170d
protocols/: Fix clippy and fmt warnings (#2433)
* protocols/mdns: fix clippy::to-string-in-format-args

* protocols/gossipsub: fix rustfmt error
2022-01-13 19:35:20 +01:00
dependabot[bot]
446fcaad3d
build(deps): Update if-watch requirement from 0.3.0 to 1.0.0 (#2431)
Updates the requirements on [if-watch](https://github.com/dvc94ch/if-watch) to permit the latest version.
- [Release notes](https://github.com/dvc94ch/if-watch/releases)
- [Commits](https://github.com/dvc94ch/if-watch/commits)

---
updated-dependencies:
- dependency-name: if-watch
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-13 17:30:31 +01:00
David Craven
df2e5a591e
protocols/mdns: Support multiple network interfaces (#2383)
Handling multiple interfaces in mdns. The socket logic was moved into an
instance while the mdns behaviour watches for interface changes and creates new
instances with a dedicated send/recv socket.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-29 19:02:20 +01:00
dependabot[bot]
e15dad5f45
build(deps): Update if-watch requirement from 0.2.0 to 0.3.0 (#2387)
Updates the requirements on [if-watch](https://github.com/dvc94ch/if-watch) to permit the latest version.
- [Release notes](https://github.com/dvc94ch/if-watch/releases)
- [Commits](https://github.com/dvc94ch/if-watch/commits)

---
updated-dependencies:
- dependency-name: if-watch
  dependency-type: direct:production
...

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-12-19 15:48:19 +01:00
Victor Ermolaev
4401ffa8b3
protocols/mdns/: Generate peer expiry and fix IPv6 support (#2359)
Co-authored-by: Victor Ermolaev <victorermolaev@gmail.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-06 16:52:31 +01:00
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
Pancy
f0000d56cd
protocols/mdns: Use a random alphanumeric string for peer name (#2311)
With https://github.com/libp2p/specs/pull/368 the definition of the _peer name_
changed in the mDNS specification.

> peer-name is the case-insensitive unique identifier of the peer, and is less
> than 64 characters.
>
> As the this field doesn't carry any meaning, it is sufficient to ensure the
> uniqueness of this identifier. Peers SHOULD generate a random, lower-case
> alphanumeric string of least 32 characters in length when booting up their
> node. Peers SHOULD NOT use their Peer ID here because a future Peer ID could
> exceed the DNS label limit of 63 characters.

https://github.com/libp2p/specs/blob/master/discovery/mdns.md

This commit adjusts `libp2p-mdns` accordingly.

Also see https://github.com/libp2p/go-libp2p/pull/1222 for the corresponding
change on the Golang side.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-25 20:15:00 +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
a905665b8b
*: Prepare v0.40.0-rc.1 release (#2290) 2021-10-15 11:15:05 +02:00
Roman
b79fd02f0b
*: Fix clippy warnings (#2227) 2021-09-14 15:00:05 +02:00
David Craven
67722c534d
protocols/mdns: Do not fire all timers at the same time. (#2212)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-09-07 19:04:57 +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
David Craven
e1f1af899b
protocols/mdns: Add IPv6 support (#2161)
Signed-off-by: Emil Majchrzak <majchrzakemil@gitlab.com>

Co-authored-by: Emil Majchrzak <majchrzakemil@gitlab.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-08-03 14:55:06 +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
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
Thomas Eizinger
20183c1ea1
*: Fix clippy warnings (#2139)
* Fix needless question mark operator

* Don't convert from u64 to u64

LocalStreamId is already a u64, no need to convert.

* Don't use `.into()` to convert to the same type

* Don't specify lifetime if it can be inferred

* Use `vec!` macro if we immediately push to it

This creates the vector with the appropriate capacity.

* Don't index array when taking a reference is enough

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-16 15:11:25 +02:00
Max Inden
b5c6fa6281
*: Prepare v0.39.0 release (#2132) 2021-07-12 21:24:58 +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
David Craven
8988ac247e
protocols/mdns: Fix discovered event emission. (#2065)
mdns keeps rediscovering nodes. this PR changes that to only emit events for new
nodes it discovered. In addition we make sure to only send a query if it is
really needed. Some logging is added for debugging purposes.
2021-05-06 17:08:29 +02:00
David Craven
29d969be34
protocols/mdns: Fix timely discovery after listening on new address (#2053)
If you start listening after mdns joined a multicast group, the peers may not
discover eachother until the 5min timeout expires.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-04-21 16:07:38 +02:00
Max Inden
42441dbd86
*: Prepare v0.37.0 release (#2049) 2021-04-13 20:15:15 +02:00
Roman S. Borschel
be2fb4ea8a Update mdns changelog. 2021-03-23 09:54:04 +01:00
David Craven
987c244f09
Derive Clone, Debug. (#2007)
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2021-03-23 09:53:06 +01: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