925 Commits

Author SHA1 Message Date
Anton
9f7145912a
feat(swarm)!: report connections to our own PeerId in separate error (#3377)
Previously, inbound connections that happened to resolve to our own `PeerId` were reported as `WrongPeerId`. With this patch, we now report those in a dedicated `LocalPeerId` error.

Related: #3205.
2023-01-26 07:20:23 +00:00
Thomas Eizinger
a25ab7e444
refactor(gossipsub): use dummy handler instead of calling new_handler (#3384)
The gossipsub tests are calling lifecycle functions of the `NetworkBehaviour` that aren't meant to be called outside of `Swarm`. This already surfaced as a problem in https://github.com/libp2p/rust-libp2p/pull/3327 and it is coming up again in https://github.com/libp2p/rust-libp2p/pull/3254 where `new_handler` gets deprecated.

Try to mitigate that by constructing a dummy handler instead. Functionally, there is no difference as in both cases, the given handler has never seen a connection.
2023-01-25 11:51:51 +00:00
Thomas Eizinger
d3dc398134
refactor(relay): directly store actions instead of events (#3372)
Storing `NetworkBehaviourAction`s within the behaviour is more flexible than only storing `OutEvent`s. Additionally, I find expression-oriented code easier to reason about because it typically doesn't contain side-effects.
2023-01-24 21:00:13 +00:00
Nazar Mokrynskyi
520523b696
feat(kad): Limit number of active outbound streams (#3287)
Limit number of active outbound streams to not exceed configured number of streams.

Resolves https://github.com/libp2p/rust-libp2p/issues/3236.
2023-01-24 18:22:35 +00:00
João Oliveira
9e1f775478
fix(autonat): Skip unparsable multiaddr (#3363)
With this commit `libp2p-autonat` no longer discards the whole remote payload in case an addr is unparsable, but instead logs the failure and skips the unparsable multiaddr.

See libp2p#3244 for details.
2023-01-24 08:49:59 +00:00
Thomas Eizinger
778f7a2d1a
feat(core)!: make ConnectionIds globally unique (#3327)
Instead of offering a public constructor, users are now no longer able to construct `ConnectionId`s at all. They only public API exposed are the derived traits. Internally, `ConnectionId`s are monotonically incremented using a static atomic counter, thus no two connections will ever get assigned the same ID.
2023-01-23 16:29:41 +00:00
Thomas Eizinger
4b41f5a994
refactor(core)!: remove EitherOutput (#3341)
The trick with this one is to use `futures::Either` everywhere where we may wrap something that implements any of the `futures` traits. This includes the output of `EitherFuture` itself. We also need to implement `StreamMuxer` on `future::Either` because `StreamMuxer`s may be the the `Output` of `InboundUpgrade`.
2023-01-23 12:31:30 +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
Thomas Eizinger
db2cd43826
refactor(core)!: remove EitherUpgrade (#3339)
We don't need to define our own type here, we can simply implement `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`.
2023-01-18 02:35:07 +00:00
Thomas Eizinger
8cd14e6a3a
refactor(relay): introduce Handler::new functions (#3334) 2023-01-18 01:29:43 +00:00
Thomas Eizinger
f4fed3880b
refactor(core)!: remove EitherError in favor of either::Either (#3337)
Defining our own `EitherError` type has no value now that `Either` provides the same implementation.

Related: https://github.com/libp2p/rust-libp2p/issues/3271
2023-01-17 23:05:59 +00:00
Thomas Eizinger
e3c7023350
fix(gossipsub): allow clippy beta lint (#3321)
It doesn't appear that https://github.com/rust-lang/rust-clippy/issues/10061 is going to be fixed any time soon. In the meantime, our CI is "red" which is misleading because we purposely don't require this CI check. It will however hit stable in ~ 2 weeks at which point our required clippy CI check will fail.

Suppress clippy lint with an `allow` to make it pass.
2023-01-13 12:28:04 +00:00
João Oliveira
4c65c7d7c7
refactor(swarm): remove deprecated inject calls (#3264)
Finishes work first started with https://github.com/libp2p/rust-libp2p/issues/2832
2023-01-12 11:21:02 +00:00
Max Inden
3cc824796d
fix(dcutr): Skip unparsable multiaddr (#3320)
With this commit `libp2p-dcutr` no longer discards the whole remote payload in case an addr is unparsable, but instead logs the failure and skips the unparsable multiaddr.

See https://github.com/libp2p/rust-libp2p/issues/3244 for details.
2023-01-12 08:46:31 +00:00
Thomas Eizinger
1b6c915813
refactor(gossipsub): remove unnecessary trait bounds (#3317)
Trait bounds on struct declarations should be avoided as much as possible because they creep into every reference of the type. To supply default type parameters, we don't need the trait bounds.
2023-01-11 09:53:20 +00:00
Elena Frank
87dc7b6e51
fix(autonat): update examples (#3310)
Fix AutoNAT examples that became outdated due to #2959 and #2618.
2023-01-10 17:33:20 +00:00
João Oliveira
20ce07c7d3
refactor(dcutr): remove ActionBuilder. (#3304)
addresses #3299
2023-01-10 03:43:59 +00:00
dependabot[bot]
a124258851
deps: update lru requirement from 0.8.0 to 0.9.0 (#3294) 2023-01-04 19:09:43 +00:00
Elena Frank
30640968ac
fix: typo in ExternalAddresses::on_swarm_event (#3297)
Fix typo `swarn` -> `swarm`.
2023-01-04 16:41:34 +00:00
Max Inden
2621528639
chore(metrics): Upgrade to prometheus-client v0.19.0 (#3207) 2023-01-03 19:42:32 +00:00
João Oliveira
9c96bbb54b
refactor(relay): revise public API to follow naming convention (#3238)
Continues addressing https://github.com/libp2p/rust-libp2p/issues/2217.
2023-01-02 20:21:46 +00:00
Max Inden
56b3b8fe5a
fix(kad): Skip invalid multiaddr (#3284)
With this commit `libp2p-kad` no longer discards the whole peer payload in case an addr is invalid, but instead logs the failure, skips the invalid multiaddr and parses the remaining payload.

See https://github.com/libp2p/rust-libp2p/issues/3244 for details.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2022-12-27 11:59:52 +00:00
Max Inden
e4d67c504d
fix(identify): Don't fail on unknown multiaddr protocol (#3279)
With this commit `libp2p-identify` no longer discards the whole identify payload in case a listen addr of the remote node is invalid, but instead logs the failure, skips the invalid multiaddr and parses the remaining identify payload.

This is especially relevant when rolling out a new protocol to a live network. Say that most nodes of a network run on an implementation version v1. Say that the `multiaddr` implementation is not aware of the `webrtc/` protocol. Say that a new version (v2) is rolled out to the network with support for the `webrtc/` protocol, listening via `webrtc/` by default. In such case all v1 nodes would discard all identify payloads of v2 nodes, given that the v2 identify payloads would contain the `webrtc/` protocol in their `listen_addr` addresses.

See https://github.com/libp2p/rust-libp2p/issues/3244 for details.
2022-12-24 13:20:55 +00:00
StemCll
aca3454c91
refactor(gossipsub): remove derive-builder dev-dependency (#3270)
Remove the `derive_builder` dev-dependency in gossipsub. We can manually implement the builder functionality on top of the `Default` instance of `InjectNodes`.

Resolved #3228.
2022-12-22 23:47:23 +00:00
Thomas Eizinger
1765ae0395
feat(kademlia)!: use GATs on RecordStore trait (#3239)
Previously, we applied a lifetime onto the entire `RecordStore` to workaround Rust not having GATs. With Rust 1.65.0 we now have GATs so we can remove this workaround.

Related https://github.com/libp2p/rust-libp2p/issues/3240. Without this change, we would have to specify HRTB in various places.
2022-12-22 16:17:59 +00:00
dependabot[bot]
1b4624f74a
deps: Update base64 requirement from 0.13.0 to 0.20.0 (#3226) 2022-12-21 03:35:25 +00:00
Pasha Podolsky
929cbb4670
deps!: Update multiaddr & multihash to 0.17.0 (#3196) 2022-12-20 08:52:08 +00:00
Thomas Eizinger
93335b8818
refactor(dcutr): reshape public API to follow naming guidelines (#3214)
With this patch, the naming of types follows the guidelines discussed in #2217.
2022-12-20 05:03:40 +00:00
Thomas Eizinger
88fa8e66b8
refactor(gossipsub): don't store messages within Arc (#3243)
Currently, we store messages to be sent to the `ConnectionHandler` in an `Arc`. However, we never actually clone these messages as we can see with this patch, hence we remove this wrapping.

Related: https://github.com/libp2p/rust-libp2p/pull/3242
2022-12-20 00:59:25 +00:00
Nazar Mokrynskyi
fbd4192e2a
fix(kademlia): downgrade reusable stream dropping warning to debug log (#3234)
There is nothing wrong about being near the edge of the concurrency Kademlia allows. If there was an older stream about to be reused, it doesn't mean there was anything wrong to warn about.
2022-12-19 12:54:39 +00:00
Nick Loadholtes
2dd188e897
feat(floodsub): make use of prost-codec (#3224)
This patch addresses #2500 for the `libp2p-floodsub` crate.

For this PR the existing code was upgraded to use `Framed` with the `prost_codec::Codec` as the standard codec for handling the RPC message format serialization/deserialization.
2022-12-19 11:41:38 +00:00
Thomas Eizinger
8c139f2d3b
chore: apply suggestions from beta clippy (#3251) 2022-12-17 02:01:45 +00:00
Thomas Eizinger
f6f42968e2
refactor(autonat): buffer entire actions instead of events (#3241)
Previously, we used to buffer events separately and emit actions directly. That is unnecessary. We can have a single place where we return from the `poll` loop and shove all actions into the same buffer.
2022-12-15 16:22:55 +00:00
Hannes
d79c93abdb
chore: Implement latest clippy warnings (#3220)
As I do frequently, I corrected for the latest clippy warnings. This will make sure the CI won't complain in the future. We could automate this btw and maybe run the nightly version of clippy.
2022-12-14 15:45:04 +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
João Oliveira
f80c7141ab
feat: move Identify I/O from NetworkBehaviour to ConnectionHandler (#3208)
Addresses #2885
2022-12-13 20:24:31 +00:00
João Oliveira
f828db60cb
refactor(request-response): revise public API to follow naming convention (#3159) 2022-12-13 12:11:42 +00:00
Thomas Eizinger
bffe4153bc
fix(dcutr): rename error types to bypass cargo-semver-checks hickup (#3213)
`cargo semver-checks` is still missing features in regards to properly detecting renamed exports. To make our CI pass again, we remove the renamed export, replace it with type-aliases and deprecate them to point users types exported under a module which now follows the conventions set in #2217.
2022-12-13 04:14:57 +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
John Turpish
f8f19baad0
time to establish connection (#3134)
Implementing #2745 , adding  a metric to break down time from connection pending to connection established, per protocol stack.

````
$curl -s http://127.0.0.1:42183/metrics | grep nt_duration
# HELP libp2p_swarm_connection_establishment_duration Time it took (locally) to finish establishing connections.
# TYPE libp2p_swarm_connection_establishment_duration histogram
libp2p_swarm_connection_establishment_duration_sum{role="Listener",protocols="/ip4/tcp"} 0.007
libp2p_swarm_connection_establishment_duration_count{role="Listener",protocols="/ip4/tcp"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.001"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.002"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.004"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.008"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.016"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.032"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.064"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.128"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.256"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="0.512"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Listener",protocols="/ip4/tcp",le="+Inf"} 1

lbl@chomp:~lbl
$curl -s http://127.0.0.1:34283/metrics | grep nt_duration
# HELP libp2p_swarm_connection_establishment_duration Time it took (locally) to finish establishing connections.
# TYPE libp2p_swarm_connection_establishment_duration histogram
libp2p_swarm_connection_establishment_duration_sum{role="Dialer",protocols="/ip4/tcp"} 0.009
libp2p_swarm_connection_establishment_duration_count{role="Dialer",protocols="/ip4/tcp"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.001"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.002"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.004"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.008"} 0
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.016"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.032"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.064"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.128"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.256"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="0.512"} 1
libp2p_swarm_connection_establishment_duration_bucket{role="Dialer",protocols="/ip4/tcp",le="+Inf"} 1
````
2022-12-12 14:40:36 +00:00
Max Inden
7c10942058
chore: Bump libp2p-swarm dependents (#3225)
Follow-up to https://github.com/libp2p/rust-libp2p/pull/3170#issuecomment-1344847006
2022-12-12 11:30:23 +00:00
Hannes
8cb79f4c79
chore(swarm): Remove deprecated functions (#3170)
Remove functions deprecated in 0.41.0.
2022-12-09 15:44:08 +01:00
dependabot[bot]
c5f5b80c5e
build(deps): Update env_logger requirement from 0.9.0 to 0.10.0 (#3166)
Updates the requirements on [env_logger](https://github.com/rust-cli/env_logger) to permit the latest version.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.9.0...v0.10.0)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-02 18:06:09 +01:00
Max Inden
87308f0bc8
chore: Prepare rust-libp2p v0.50.0 release (#3163) 2022-11-25 09:37:55 +00:00
Friedel Ziegelmayer
a99718162b
protocols/kad: Improve options to efficiently retrieve (#2712) 2022-11-25 08:29:46 +00:00
Thomas Eizinger
2a5a5180e9
fix(kad): Don't wait for behaviour after receiving AddProvider (#3152)
Previously, we would erroneously always go into the `WaitingUser` (now called `WaitingBehaviour`) state after receiving a message on an inbound stream. However, the `AddProvider` message does not warrant a "response" from the behaviour. Thus, any incoming `AddProvider` message would result in a stale substream that would eventually be dropped as soon as more than 32 inbound streams have been opened.

With this patch, we inline the message handling into the upper match block and perform the correct state transition upon each message. For `AddProvider`, we go back into `WaitingMessage` because the spec mandates that we need to be ready to receive more messages on an inbound stream.

Fixes #3048.
2022-11-23 17:46:43 +00:00
Thomas Eizinger
0c85839dab
.github/workflows: Refactor CI jobs (#3090)
We refactor our continuous integration workflow with the following goals in mind:

- Run as few jobs as possible
- Have the jobs finish as fast as possible
- Have the jobs redo as little work as possible

There are only so many jobs that GitHub Actions will run in parallel.
Thus, it makes sense to not create massive matrices but instead group
things together meaningfully.

The new `test` job will:

- Run once for each crate
- Ensure that the crate compiles on its specified MSRV
- Ensure that the tests pass
- Ensure that there are no semver violations

This is an improvement to before because we are running all of these
in parallel which speeds up execution and highlights more errors at
once. Previously, tests run later in the pipeline would not get run
at all until you make sure the "first" one passes.

We also previously did not verify the MSRV of each crate, making the
setting in the `Cargo.toml` rather pointless.

The new `cross` job supersedes the existing `wasm` job.

This is an improvement because we now also compile the crate for
windows and MacOS. Something that wasn't checked before.
We assume that checking MSRV and the tests under Linux is good enough.
Hence, this job only checks for compile-errors.

The new `feature_matrix` ensures we compile correctly with certain feature combinations.

`libp2p` exposes a fair few feature-flags. Some of the combinations
are worth checking independently. For the moment, this concerns only
the executor related transports together with the executor flags but
this list can easily be extended.

The new `clippy` job runs for `stable` and `beta` rust.

Clippy gets continuously extended with new lints. Up until now, we would only
learn about those as soon as a new version of Rust is released and CI would
run the new lints. This leads to unrelated failures in CI. Running clippy on with `beta`
Rust gives us a heads-up of 6 weeks before these lints land on stable.

Fixes #2951.
2022-11-18 11:04:16 +00:00
João Oliveira
08510dd523
mdns: update if-watch to 3.0.0 (#3096) 2022-11-18 01:12:23 +00:00
João Oliveira
7803524a76
swarm/handler: replace inject_* methods (#3085)
Previously, we had one callback for each kind of message that a `ConnectionHandler` would receive from either its `NetworkBehaviour` or the connection itself.

With this patch, we combine these functions, resulting in two callbacks:

- `on_behaviour_event`
- `on_connection_event`

Resolves #3080.
2022-11-17 17:19:36 +00:00
Thomas Eizinger
6d49bf4a53
fix: Allow libp2p-mdns to compile without feature-flags (#3131)
Currently, `libp2p-mdns` fails to compile unless we enable the `tokio` runtime feature flag. This is caused by missing `cfg` statements upstream. See https://github.com/bluejekyll/trust-dns/issues/1830.

Until this is fixed upstream, we temporarily enable the `tokio-runtime` feature of `trust-dns-proto`.
2022-11-17 12:06:30 +00:00