174 Commits

Author SHA1 Message Date
dependabot[bot]
d6351eead7
deps: bump if-watch from 3.0.1 to 3.1.0
Pull-Request: #4635.
2023-10-13 06:10:06 +00:00
dependabot[bot]
3ae72557ab
deps: bump tokio from 1.32.0 to 1.33.0
Pull-Request: #4615.
2023-10-10 05:17:02 +00:00
Binston Sukhael Cardoza
0e9d339bd2
ci: use workspace inheritance to enforce lints in all crates
Starting with nightly-2023-09-10, the `[lints]` section in `Cargo.toml` files is stable. Together with workspace inheritance, this can be used to declare all lints we want to enforce in a single place.

Resolves: #4484.

Pull-Request: #4575.
2023-10-09 02:20:46 +00:00
dependabot[bot]
94432d83ad
deps: bump smallvec from 1.11.0 to 1.11.1
Pull-Request: #4551.
2023-09-25 08:33:29 +00:00
dependabot[bot]
8a523f950f
deps: bump socket2 from 0.5.3 to 0.5.4
Pull-Request: #4513.
2023-09-18 09:17:45 +00:00
João Oliveira
50b8b637cf
deps: bump trust-dns-proto from 0.22.0 to 0.23.0
On https://github.com/libp2p/rust-libp2p/pull/3102 we left the `tokio-runtime` feature because of https://github.com/bluejekyll/trust-dns/issues/1830, meanwhile https://github.com/bluejekyll/trust-dns/pull/1831 was merged and `0.23.0` was released with it, so we no longer require the `tokio-runtime` feature.

Pull-Request: #4418.
2023-09-04 06:57:49 +00:00
dependabot[bot]
76797f8ad0
deps: bump tokio from 1.31.0 to 1.32.0
Pull-Request: #4356.
2023-08-21 09:16:26 +00:00
dependabot[bot]
2c4c961d69
deps: bump log from 0.4.19 to 0.4.20
Pull-Request: #4322.
2023-08-14 10:16:13 +00:00
dependabot[bot]
a4b8ff4673
deps: bump tokio from 1.29.1 to 1.31.0
Pull-Request: #4318.
2023-08-14 09:00:31 +00:00
dependabot[bot]
a92a801cce
deps: bump smallvec from 1.10.0 to 1.11.0
Pull-Request: #4171.
2023-07-11 08:58:09 +00:00
dependabot[bot]
185cb4a2e3
deps: bump tokio from 1.28.2 to 1.29.1
Pull-Request: #4148.
2023-07-10 09:31:15 +00:00
Thomas Eizinger
d5475fccde
fix(test): only listen on 127.0.0.1 for ephemeral swarm
This resolves an issue where our tests were depending on the number of network interfaces available on the local machine.

Related #4110.

Pull-Request: #4122.


  
Co-Authored-By: Thomas Eizinger <thomas@eizinger.io>
2023-06-27 01:21:47 +00:00
Thomas Eizinger
78c150d0df
chore: don't use workspace inheritance for dev-dependencies
Using workspace inheritance breaks `cargo release` because it cannot resolve that the dev-dependencies should only use a `path` and not a version.

Pull-Request: #4097.


  
Co-Authored-By: Thomas Eizinger <thomas@eizinger.io>
2023-06-20 12:24:28 +00:00
Max Inden
8776fa8766
chore: prepare libp2p v0.52.0 release
Pull-Request: #4053.


  
Co-Authored-By: Max Inden <mail@max-inden.de>
  

  
Co-Authored-By: Thomas Eizinger <thomas@eizinger.io>
2023-06-19 11:49:39 +00:00
dependabot[bot]
d263ee67a9
deps: bump log from 0.4.18 to 0.4.19
Pull-Request: #4058.
2023-06-13 10:29:36 +00:00
Thomas Eizinger
ed14630672
feat: leverage type-safe /p2p in multiaddr
This updates `multiaddr` to version `0.19`.

Depends-On: #3656.
Depends-On: https://github.com/multiformats/rust-multiaddr/pull/83.
Resolves: #4039.

Pull-Request: #4037.
2023-06-08 01:38:18 +00:00
dependabot[bot]
34d87a8208
deps: bump log from 0.4.17 to 0.4.18
Pull-Request: #4000.
2023-05-29 10:17:23 +00:00
Philippe Jalaber
67b26cce4f
feat(mdns): adaptive initial interval peer discovery
Peer discovery with mDNS can be very slow, particularly if the first mDNS query is lost. This patch resolves it by adjusting the timer with an adaptive initial interval. We start with a very short timer (500 ms). If a peer is discovered before the end of the timer, then the timer is reset to the normal query interval value (300s), otherwise the timer's value is multiplied by 2 until it reaches the normal query interval value.

Related: https://github.com/libp2p/rust-libp2p/pull/3323.
Resolves: https://github.com/libp2p/rust-libp2p/issues/3319.

Pull-Request: #3975.
2023-05-25 04:09:24 +00:00
Thomas Eizinger
5e8f2e82e4
feat(swarm): replace address scoring with explicit candidates
Previously, a `NetworkBehaviour` could report an `AddressScore` for an external address. This score was a `u32` and addresses would be ranked amongst those.

In reality, an address is either confirmed to be publicly reachable (via a protocol such as AutoNAT) or merely represents a candidate that might be an external address. In a way, addresses are guilty (private) until proven innocent (publicly reachable).

When a `NetworkBehaviour` reports an address candidate, we perform address translation on it to potentially correct for ephemeral ports of TCP. These candidates are then injected back into the `NetworkBehaviour`. Protocols such as AutoNAT can use these addresses as a source for probing their NAT status. Once confirmed, they can emit a `ToSwarm::ExternalAddrConfirmed` event which again will be passed to all `NetworkBehaviour`s.

This simplified approach will allow us implement Kademlia's client-mode (https://github.com/libp2p/rust-libp2p/issues/2032) without additional configuration options: As soon as an address is reported as publicly reachable, we can activate server-mode for that connection.

Related: https://github.com/libp2p/rust-libp2p/pull/3877.
Related: https://github.com/libp2p/rust-libp2p/issues/3953.
Related: https://github.com/libp2p/rust-libp2p/issues/2032.
Related: https://github.com/libp2p/go-libp2p/issues/2229.

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

Pull-Request: #3954.
2023-05-24 07:52:16 +00:00
dependabot[bot]
382b358c65
deps: bump data-encoding from 2.3.3 to 2.4.0
Pull-Request: #3972.
2023-05-22 18:10:10 +00:00
dependabot[bot]
3021814e6b
deps: bump socket2 from 0.5.2 to 0.5.3
Pull-Request: #3934.
2023-05-15 17:30:19 +00:00
Thomas Coratger
6e36e8aa35
feat(swarm): rename associated types for message passing
Previously, the associated types on `NetworkBehaviour` and `ConnectionHandler` carried generic names like `InEvent` and `OutEvent`. These names are _correct_ in that `OutEvent`s are passed out and `InEvent`s are passed in but they don't help users understand how these types are used.

In theory, a `ConnectionHandler` could be used separately from `NetworkBehaviour`s but that is highly unlikely. Thus, we rename these associated types to indicate, where the message is going to be sent to:

- `NetworkBehaviour::OutEvent` is renamed to `ToSwarm`: It describes the message(s) a `NetworkBehaviour` can emit to the `Swarm`. The user is going to receive those in `SwarmEvent::Behaviour`.
- `ConnectionHandler::InEvent` is renamed to `FromBehaviour`: It describes the message(s) a `ConnectionHandler` can receive from its behaviour via `ConnectionHandler::on_swarm_event`. The `NetworkBehaviour` can send it via the `ToSwarm::NotifyHandler` command.
- `ConnectionHandler::OutEvent` is renamed to `ToBehaviour`: It describes the message(s) a `ConnectionHandler` can send back to the behaviour via the now also renamed `ConnectionHandlerEvent::NotifyBehaviour` (previously `ConnectionHandlerEvent::Custom`)

Resolves: #2854.

Pull-Request: #3848.
2023-05-14 10:58:08 +00:00
dependabot[bot]
30d0f598ef
deps: bump socket2 from 0.4.9 to 0.5.2
Pull-Request: #3873.
2023-05-03 09:00:15 +00:00
Hannes
30d2c75206
chore(mdns): remove deprecated items
Related: https://github.com/libp2p/rust-libp2p/issues/3647.

Pull-Request: #3699.
2023-05-02 11:32:28 +00:00
DrHuangMHT
02d87155a5
feat(mdns): change mdns::Event to hold Vec
In previous PR #3606 we've made `mdns::Event` `Clone`, but cloning single-use iterators doesn't sound right. Also you have to create an iterator from the actual data returned before putting it into events. So in this PR the iterators are replaced by `Vec`, as it's the type the data originally come from.



Related #3612.

Pull-Request: #3621.
2023-05-02 11:13:41 +00:00
Thomas Eizinger
996b5c8bd0
chore: leverage cargo's workspace inheritance
Previously, we would specify the version and path of our workspace dependencies in each of our crates. This is error prone as https://github.com/libp2p/rust-libp2p/pull/3658#discussion_r1153278072 for example shows. Problems like these happened in the past too.

There is no need for us to ever depend on a earlier version than the most current one in our crates. It thus makes sense that we manage this version in a single place.

Cargo supports a feature called "workspace inheritance" which allows us to share a dependency declaration across a workspace and inherit it with `{ workspace = true }`.

We do this for all our workspace dependencies and for the MSRV.

Resolves #3787.

Pull-Request: #3715.
2023-05-02 09:14:14 +00:00
dependabot[bot]
8a0e61e3ac
deps: bump tokio from 1.27.0 to 1.28.0
Pull-Request: #3834.
2023-04-28 10:49:08 +00:00
Thomas Eizinger
135942d319
chore: enforce unreachable_pub lint
The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult.

We should strive for most items being `pub(crate)`. This lint helps us enforce that.

Pull-Request: #3735.
2023-04-26 07:31:56 +00:00
dependabot[bot]
23c3d24610
deps: bump if-watch from 3.0.0 to 3.0.1
Pull-Request: #3730.
2023-04-09 14:27:58 +00:00
Thomas Eizinger
451c64a8b8
fix: specify correct libp2p-swarm dependency
With https://github.com/libp2p/rust-libp2p/pull/3658, these crates depend on the `0.42.1` release to access the new `ToSwarm` type. With the currently specified version, a user could theoretically run into a compile error if they pin `libp2p-swarm` to `0.42.0` in their lockfile but update to the latest patch release of one of these crates.

Pull-Request: #3711.
2023-04-05 19:44:32 +00:00
dependabot[bot]
17dd72755d
deps: bump tokio from 1.26.0 to 1.27.0
Pull-Request: #3729.
2023-04-05 14:37:42 +00:00
dependabot[bot]
0ff0ef7a35
deps: bump futures from 0.3.27 to 0.3.28
Pull-Request: #3725.
2023-04-03 14:43:42 +00:00
Max Inden
d7396706d0
fix(changelog): Make release heading levels consistent
See `##` for release headings everywhere. This is consistent with markdown conventions of one `#` per document and in line with https://keepachangelog.com/.

See report in https://github.com/libp2p/rust-libp2p/issues/3531.

Pull-Request: #3561.
2023-03-30 21:04:01 +00:00
Max Inden
486ac8baf2
chore: prepare libp2p v0.51.2
Depends-On: #3693.

Pull-Request: #3694.
2023-03-29 13:04:18 +00:00
dependabot[bot]
ce55601683
deps: bump async-io from 1.12.0 to 1.13.0
Pull-Request: #3683.
2023-03-29 10:59:41 +00:00
Thomas Eizinger
dcbc04e89e
feat(swarm): rename NetworkBehaviourAction to ToSwarm
Resolves #3123.

Pull-Request: #3658.
2023-03-24 13:43:49 +00:00
DrHuangMHT
9d05c619e8
feat: derive Clone for mdns::Event
Derive trait `Clone` for `mdns::Event`. This makes cloning its contents without destroying type information possible.



Related #3593.

Pull-Request: #3606.
2023-03-13 17:17:03 +00:00
dependabot[bot]
9d0ec7e074
deps: bump futures from 0.3.26 to 0.3.27
Pull-Request: #3597.
2023-03-13 11:35:04 +00:00
Thomas Eizinger
2a14df25eb
feat: introduce libp2p-identity crate
This patch combines the `libp2p_core::identity` and `libp2p_core::peer_id` modules into a new crate: `libp2p-identity`.

Resolves https://github.com/libp2p/rust-libp2p/issues/3349.

Pull-Request: #3350.
2023-03-12 15:46:58 +01:00
Thomas Eizinger
7069d78ee3
test: introduce libp2p-swarm-test
This patch-set introduces `libp2p-swarm-test`. It provides utilities for quick and safe bootstrapping of tests for `NetworkBehaviour`s. The main design features are:

- Everything has timeouts
- APIs don't get in your way
- Minimal boilerplate

Closes #2884.

Pull-Request: #2888.
2023-03-08 09:36:35 +00:00
Max Inden
71015ee16f
docs: prepare v0.51.0
A large release with lots of changes I am looking forward to. Sorry for the long release cadence.

Anything folks would like to see included that is not yet in `master`? As usual I would like to only block on bug fixes.

Pull-Request: #3491.
2023-02-24 10:42:29 +00:00
Thomas Eizinger
19a554965f
feat(swarm)!: allow NetworkBehaviours to manage connections
Previously, a `ConnectionHandler` was immediately requested from the `NetworkBehaviour` as soon as a new dial was initiated or a new incoming connection accepted.

With this patch, we delay the creation of the handler until the connection is actually established and fully upgraded, i.e authenticated and multiplexed.

As a consequence, `NetworkBehaviour::new_handler` is now deprecated in favor of a new set of callbacks:

- `NetworkBehaviour::handle_pending_inbound_connection`
- `NetworkBehaviour::handle_pending_outbound_connection`
- `NetworkBehaviour::handle_established_inbound_connection`
- `NetworkBehaviour::handle_established_outbound_connection`

All callbacks are fallible, allowing the `NetworkBehaviour` to abort the connection either immediately or after it is fully established. All callbacks also receive a `ConnectionId` parameter which uniquely identifies the connection. For example, in case a `NetworkBehaviour` issues a dial via `NetworkBehaviourAction::Dial`, it can unambiguously detect this dial in these lifecycle callbacks via the `ConnectionId`.

Finally, `NetworkBehaviour::handle_pending_outbound_connection` also replaces `NetworkBehaviour::addresses_of_peer` by allowing the behaviour to return more addresses to be used for the dial.

Resolves #2824.

Pull-Request: #3254.
2023-02-23 23:43:33 +00:00
Thomas Eizinger
caed1fe2c7
refactor(swarm)!: remove handler from NetworkBehaviourAction::Dial (#3328)
We create the `ConnectionId` for the new connection as part of `DialOpts`. This allows `NetworkBehaviour`s to accurately track state regarding their own dial attempts.

This patch is the main enabler of https://github.com/libp2p/rust-libp2p/pull/3254. Removing the `handler` field will allow us to deprecate the `NetworkBehaviour::new_handler` function in favor of four new ones that give more control over the connection lifecycle.
2023-02-14 01:09:29 +00:00
dependabot[bot]
0c94237e16
deps: bump futures from 0.3.25 to 0.3.26 (#3405) 2023-01-31 23:34:17 +00:00
Fina
e2b3c1190a
fix(mdns): Don't expire mDNS nodes on connection close (#3367)
mDNS records should not be expiring when an unrelated connection timeout with said peer is reached.

Fixes #3309.
2023-01-27 04:02:20 +00:00
Thomas Eizinger
4de54f00f9
refactor: expose and use THandlerOutEvent type alias (#3368)
Previously, we used the full reference to the `OutEvent` of the `ConnectionHandler` in all implementations of `NetworkBehaviour`. Not only is this very verbose, it is also more brittle to changes. With the current implementation plan for #2824, we will be removing the `IntoConnectionHandler` abstraction. Using a type-alias to refer to the `OutEvent` makes the migration much easier.
2023-01-26 11:55:02 +00:00
Thomas Eizinger
475dc80a07
refactor!: Move ConnectionId and PendingPoint to libp2p-swarm (#3346)
Both of these are only needed as part of `libp2p-swarm`. Them residing in `libp2p-core` is a left-over from when `libp2p-core` still contained `Pool`.
2023-01-18 08:56:32 +00:00
Pasha Podolsky
929cbb4670
deps!: Update multiaddr & multihash to 0.17.0 (#3196) 2022-12-20 08:52:08 +00:00
Thomas Eizinger
be3ec6c62b
refactor(swarm)!: deprecate PollParameters where possible (#3153)
This patch deprecates 3 out of 4 functions on `PollParameters`:

- `local_peer_id`
- `listened_addresses`
- `external_addresses`

The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`:

- `ExternalAddresses`
- `ListenAddresses`

A node's `PeerId` is always known to the caller, thus we can require them to pass it in.

Related: #3124.
2022-12-14 00:50:08 +00:00
Thomas Eizinger
d7363a53d3
fix: Remove circular dependencies across workspace (#3023)
Circular dependencies are problematic in several ways:

- They result in cognitive overhead for developers, in trying to figure out what depends on what.
- They present `cargo` with limits in what order the crates can be compiled in.
- They invalidate build caches unnecessarily thus forcing `cargo` to rebuild certain crates.
- They cause problems with tooling such as `release-please`.

To actually break the circular dependencies, this patch inlines the uses of `development_transport` in the examples and tests for all sub-crates. This is only meant to be a short-term fix until https://github.com/libp2p/rust-libp2p/issues/3111 and https://github.com/libp2p/rust-libp2p/pull/2888 are fixed.

To ensure we don't accidentally reintroduce this dependency, we add a basic CI that queries `cargo metadata` using `jq`.

Resolves https://github.com/libp2p/rust-libp2p/issues/3053.
Fixes https://github.com/libp2p/rust-libp2p/issues/3223.
Related: https://github.com/libp2p/rust-libp2p/pull/2918#discussion_r976514245
Related: https://github.com/googleapis/release-please/issues/1662
2022-12-12 20:58:01 +00:00