1968 Commits

Author SHA1 Message Date
Hannes
76dba1773b
fix(swarm): Make executors pub and add convenience constructors for SwarmBuilder (#3155)
Addresses issues raised here: https://github.com/libp2p/rust-libp2p/pull/3097#discussion_r1026526312
2022-11-23 18:19:22 +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
Anton Kaliaev
babacc5555
fix(webrtc): Don't append /p2p to listen addresses (#3154)
This aligns with what other transports do.

Related: https://github.com/libp2p/rust-libp2p/pull/2622#discussion_r1024844957.
2022-11-23 16:33:36 +00:00
Michael G
b99a2137ac
docs(swarm): Reword Swarm top-level doc string (#3132) 2022-11-23 02:16:40 +00:00
Thomas Eizinger
2c96d644f9
feat: Better error reporting when features are disabled (#2972)
In case support for e.g. RSA keys is disabled at compile-time, we will now print a better error message. For example:

> Failed to dial Some(PeerId("QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt")): Failed to negotiate transport protocol(s): [(/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt): : Handshake failed: Handshake failed: Invalid public key: Key decoding error: RSA keys are unsupported)]

Fixes #2971.
2022-11-23 00:51:47 +00:00
Predrag Gruevski
9b182778e1
chore(ci): Add --locked flag to cargo install step (#3129)
This PR tweaks the installation of `cargo-semver-checks` to make it use the `--locked` flag.

Installing binaries with their locked dependency versions makes it less likely that you might run into issues caused by bugs in dependency libraries, since your installed dependency versions match the versions used in the binary's own test environment.

This is a recommendation that applies to most Rust binary tools. For example, here's cargo-nextest recommending the same: https://nexte.st/book/installing-from-source.html#installing-from-cratesio
2022-11-20 21:48:24 +00:00
Thomas Eizinger
8678dc7569
chore(meta): Remove unnecessary quic module (#3139) 2022-11-18 19:40:10 +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
Thomas Eizinger
05c079422e
fix(webrtc): Don't emit addresses from other interfaces (#3142)
Previously, we would always run `IfWatcher`, even if we were only listening on a specific interface. This patch fixes this behaviour and aligns it with how `libp2p-quic` operates.
2022-11-18 10:24:46 +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
João Oliveira
3df3c88f3d
swarm/behaviour: Replace inject_* with on_event (#3011) 2022-11-17 09:28:40 +00:00
Anton Kaliaev
a714864885
feat: Add WebRTC transport (#2622)
Hey 👋 This is a WebRTC transport implemented in accordance w/ the [spec](https://github.com/libp2p/specs/pull/412). It's based on the [webrtc-rs](https://github.com/webrtc-rs/webrtc) library.

Resolves: #1066.
2022-11-17 05:17:31 +00:00
Thomas Eizinger
43fdfe27ea
chore(mergify): Don't ask dependabot to resolve conflicts (#3122) 2022-11-16 10:28:03 +11:00
John Turpish
69efe63229
misc/metrics: Add protocols label to address-specific metrics (#2982)
Previously, we would only track the metrics like the number of open connections. With this patch, we extend these metrics with a `protocols` label that contains a "protocol stack". A protocol stack is a multi-address with all variable parts removed. For example, `/ip4/127.0.0.1/tcp/1234` turns into `/ip4/tcp`.

Resolves https://github.com/libp2p/rust-libp2p/issues/2758.
2022-11-15 20:45:14 +00:00
Hannes
d5ea93dd71
feat(swarm): Make executor for connection tasks explicit (#3097)
Previously, the executor for connection tasks silently defaulted to a `futures::executor::ThreadPool`. This causes issues such as https://github.com/libp2p/rust-libp2p/issues/2230.

With this patch, we force the user to choose, which executor they want to run the connection tasks on which results in overall simpler API with less footguns.

Closes #3068.
2022-11-15 14:26:03 +00:00
Roland Kuhn
d8fe7bf49f
transports/tcp: Update if-watch to v3.0.0 (#3101)
Update to `if-watch` version 3.0.0 and pass through features, such that `libp2p-tcp/async-io` selects `if-watch/smol` and `libp2p-tcp/tokio` brings in `if-watch/tokio`.
The mDNS part is already done in #3096.
2022-11-15 12:34:38 +00:00
Matthias Beyer
ca8bcd8288
core: Expose peer_id::ParseError (#3113) 2022-11-15 11:58:42 +00:00
Thomas Eizinger
9dadf5c830
muxers/yamux: Mitigation of unnecessary stream drops (#3071) 2022-11-15 10:40:55 +00:00
yojoe
368705a146
docs(core): Document byte format of PeerId (#3084)
PeerId data is more than just a multihash of the public key.

See discussion: https://github.com/libp2p/rust-libp2p/discussions/3079
2022-11-15 01:22:11 +00:00
João Oliveira
5f196dd231
refactor(mdns): Parse messages using trust-dns-proto instead of dns-parse (#3102) 2022-11-14 22:35:18 +00:00
Thomas Eizinger
5b3612bb29
test: Remove dialer_can_receive stream muxer test (#3108)
Various muxer implementations struggle to fulfill this test. In practice, it doesn't matter much because we always run `multistream-select` on top of a newly negotiated stream so we never end up actually reading from a stream that we have never written to.

Relevant discussion: https://github.com/kpp/rust-libp2p/pull/27#discussion_r1012128418
2022-11-14 21:09:19 +00:00
Roman
0f5c491d91
feat(transports/quic): Add implementation based on quinn-proto (#2289)
Co-authored-by: Demi Marie Obenour <demiobenour@gmail.com>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: David Craven <david@craven.ch>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: elenaf9 <elena.frank@protonmail.com>
Co-authored-by: Marco Munizaga <marco@marcopolo.io>
2022-11-14 13:12:16 +01:00
Hannes
7daa0c1145
*: Remove lazy_static in favor of once_cell (#3110) 2022-11-14 04:24:52 +00:00
Elena Frank
8b378d56d3
deps: Update to multiaddr v0.16.0 (#3117) 2022-11-13 23:38:27 +01:00
Matthias Beyer
e2737c7b71
protocols/kad: Expose NoKnownPeers (#3114) 2022-11-13 22:08:28 +00:00
Thomas Eizinger
cafa73444b
.github/: Use Description for commit message and add Notes (#3082) 2022-11-13 20:01:24 +01:00
Thomas Eizinger
afb777e937
swarm-derive: Add prelude configuration option to NetworkBehaviour macro (#3055)
Currently, our `NetworkBehaviour` derive macro depends on the `libp2p` crate to be in scope. This prevents standalone usage which forces us to depend on `libp2p` in all our tests where we want to derive a `NetworkBehaviour`.

This PR introduces a `prelude` option that - by default - points to `libp2p::swarm::derive_prelude`, a new module added to `libp2p_swarm`. With this config option, users of `libp2p_swarm` can now refer to the macro without depending on `libp2p`, breaking the circular dependency in our workspace. For consistency with the ecosystem, the macro is now also re-exported by `libp2p_swarm` instead of `libp2p` at the same position as the trait that it implements.

Lastly, we introduce an off-by-default `macros` feature flag that shrinks the dependency tree for users that don't need the derive macro.
2022-11-12 23:59:14 +00:00
Hannes
c32f03c317
*: Fix newly raised clippy warnings (#3106)
Fixed minor issues raised by clippy to improve correctness and readablitity.
2022-11-11 20:30:58 +00:00
Steve Loeppky
90df86d9e7
Update ROADMAP.md based on previous feedback. (#3091)
Co-authored-by: Prithvi Shahi <shahi.prithvi@gmail.com>
2022-11-10 11:08:00 -08:00
dependabot[bot]
e1e6413fc0
build(deps): Bump Swatinem/rust-cache from 2.1.0 to 2.2.0 (#3104) 2022-11-10 12:14:17 +00:00
dependabot[bot]
313ed588fe
build(deps): Bump Swatinem/rust-cache from 2.0.1 to 2.1.0 (#3093) 2022-11-08 08:23:07 +00:00
efarg
ba14ffdd42
protocols/identify: Change default cache_size of Config to 100 (#2995)
`Config` struct's member `cache_size` now defaults to `100`.
2022-11-04 19:40:30 +00:00
João Oliveira
280c51ef83
*: Link to libp2p/specs in doc comments (#3077) 2022-11-04 10:32:41 +00:00
Nick Loadholtes
1ba9e4579d
protocols/gossipsub: Make use of prost-codec (#3070) 2022-11-04 10:12:08 +00:00
Thomas Eizinger
b528d336cd
*: Fix clippy warnings introduced by Rust 1.65 release (#3081) 2022-11-04 09:40:09 +00:00
dependabot[bot]
f9b4af3d9d
build(deps): Update rcgen requirement from 0.9.2 to 0.10.0 (#3059) 2022-11-03 01:40:53 +00:00
Thomas Eizinger
95e27ece8e
.github: Add mergify configuration (#3026) 2022-11-03 12:25:12 +11:00
Thomas Eizinger
53d445e61c
protocols/kademlia: Refactor stream state machines (#3074)
* Refactor `InboundSubstreamState` to implement `Stream`

This allows us to use `stream::SelectAll` instead of iterating
through the states ourselves. It also allows us to fix an existing
TODO where we don't properly close a stream.

* Refactor `OutboundSubstreamState` to implement `Stream`

* Remove unnecessary keep_alive changes

The same thing is happening further down.

* Remove code duplication in answering requests

* Debug assert that we can answer every request
2022-11-02 19:20:55 +00:00
Thomas Eizinger
f4ce1fe9ae
swarm/pool: Misc refactoring (#3073)
* Remove unreachable error case

Instead of taking the connection out of the map again, construct
the event to be returned with the data we already have available.

* Remove `Pool::get` and `PoolConnection`

These are effectively not used.

* Replace `iter_pending_info` with its only usage: `is_dialing`

* Add `is_for_same_remote_as` convenience function

* Remove `PendingConnection`

* Rename `PendingConnectionInfo` to `PendingConnection`

With the latter being gone, the name is now free.

* Merge `EstablishedConnectionInfo` and `EstablishedConnection`

This is a leftover from when `Pool` was still in `libp2p-core` and
one of them was a public API and the other one wasn't.

All of this is private to `libp2p-swarm` so we no longer need to
differentiate.

* Don't `pub use` out of `pub(crate)` modules
2022-11-02 18:47:00 +00:00
João Oliveira
64e38bd6b4
swarm/: Link ThreadPool in documentation (#3067) 2022-11-02 15:09:55 +00:00
Thomas Eizinger
df659e5bcd
core/muxer: Remove deprecated functions (#3031) 2022-11-02 15:09:12 +00:00
João Oliveira
49679d31e7
swarm/CHANGELOG.md: Fix version mismatch with v0.40.1 (#3063) 2022-11-02 13:41:28 +00:00
dependabot[bot]
ee5c9b7202
build(deps): Update multiaddr requirement from 0.14.0 to 0.15.0 (#3051)
Updates the requirements on [multiaddr](https://github.com/multiformats/rust-multiaddr) to permit the latest version.
- [Release notes](https://github.com/multiformats/rust-multiaddr/releases)
- [Changelog](https://github.com/multiformats/rust-multiaddr/blob/master/CHANGELOG.md)
- [Commits](https://github.com/multiformats/rust-multiaddr/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: multiaddr
  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-11-02 12:57:21 +00:00
Thomas Eizinger
71131e0622
*: Don't leak prost dependency in error types (#3058)
With the current design, a major version bump of `prost` leaks into
all consumers of `prost-codec`.
2022-11-02 12:02:21 +00:00
Max Inden
b42f28630e
ROADMAP: Follow ups on recent review (#3062)
* ROADMAP: Remove project board for now

* ROADMAP: Encourage feedback

* ROADMAP: Remove TLS

* ROADMAP: Link to specs/ROADMAP.md

* ROADMAP: Prioritize QUIC beyond the first iteration

* ROADMAP: No longer mark QUIC as experimental
2022-10-26 10:20:34 +01:00
Andrew Mackenzie
5bce6edff9
examples/gossipsub-chat: Add mDNS peer discovery (#2996)
Co-authored-by: João Oliveira <hello@jxs.pt>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-10-26 11:43:14 +11:00
Thomas Eizinger
437b387159
CHANGELOG.md: Move libp2p-tls to correct version (#3057)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-10-25 22:09:46 +11:00
Thomas Eizinger
4d1b165982
transports/tcp: Unify symbol naming (#2961)
Co-authored-by: Elena Frank <elena.frank@protonmail.com>
2022-10-24 15:41:08 +11:00