925 Commits

Author SHA1 Message Date
Darius Clark
f2a7457fde
fix(gossipsub): prevent erroneously duplicate message IDs
Previously, we only mutably borrowed the `last_seq_no` in the current scope but did not modify the underlying number. This is because `u64` is copy and calling `wrapping_add` consumes `self` so the compiler just copied it. We introduce a new-type instead that is not `Copy`.

Additionally, `wrapping_add` and initializing with a random u64 might actually warp the number and thus not give us sequential numbers as intended in #3551. To solve this, we initialize with the current unix timestamp in nanoseconds. This allows a node to publish 1000000 messages a second and still not reuse sequence numbers even after a restart / re-initialization of the configuration. This is also what the go implementation does.

Resolves #3714.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>

Pull-Request: #3716.
2023-04-04 10:52:16 +00:00
dependabot[bot]
389e519e7f
deps: bump clap from 4.1.11 to 4.2.1
Pull-Request: #3731.
2023-04-03 19:02:18 +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
Thomas Eizinger
dfa7bd6b57
refactor: don't depend on multihash features
All we need from the multihash is for it to be a data structure that we pass around. We only ever use the identity "hasher" and the sha256 hasher. Those are easily implemented without depending the (fairly heavy) machinery in `multihash`.

Unfortunately, this patch by itself does not yet lighten our dependency tree because `multiaddr` activates those features unconditionally. I opened a companion PR for this: https://github.com/multiformats/rust-multiaddr/pull/77.

https://github.com/multiformats/rust-multiaddr/pull/77 is another breaking change and we are trying to delay those at the moment. However, it will (hopefully) land eventually which should then be much easier to implement.

Fixes #3276.

Pull-Request: #3514.
2023-03-30 17:47:35 +00:00
dependabot[bot]
be42f214bf
deps: bump regex from 1.7.1 to 1.7.3
Pull-Request: #3687.
2023-03-29 13:47:44 +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]
ea573b3b49
deps: bump bimap from 0.6.2 to 0.6.3
Pull-Request: #3641.
2023-03-29 11:28:43 +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
dependabot[bot]
7e9581c4ef
deps: bump thiserror from 1.0.39 to 1.0.40
Pull-Request: #3637.
2023-03-24 14:17:02 +00:00
Thomas Eizinger
dcbc04e89e
feat(swarm): rename NetworkBehaviourAction to ToSwarm
Resolves #3123.

Pull-Request: #3658.
2023-03-24 13:43:49 +00:00
Thomas Eizinger
fd0983567c
chore(relay): move server example to examples/
Related: #3111.

Pull-Request: #3663.
2023-03-23 21:38:56 +00:00
Thomas Eizinger
d652c014af
chore(autonat): move example to examples/
Related: #3111.

Pull-Request: #3662.
2023-03-23 21:10:52 +00:00
Max Inden
3f99c31bb3
chore(gossipsub): bump crate version
Missed in https://github.com/libp2p/rust-libp2p/pull/3551/.

Pull-Request: #3668.
2023-03-23 14:17:18 +00:00
Lin Oshitani
64cd225dca
fix(gossipsub): fix check for fanout peer inclusion in test_join
The check for fanout peer inclusion in `test_join` does not check anything since `new_peers` is always empty.

12b785e94e/protocols/gossipsub/src/behaviour/tests.rs (L611)

I assume the intention was to fill the `new_peers` with the fanout peers. In this MR I do just that.

Pull-Request: #3628.
2023-03-21 22:04:57 +00:00
Thomas Eizinger
f64187049d
feat: introduce libp2p-allow-block-list connection management module
Currently, banning peers is a first-class feature of `Swarm`. With the new connection management capabilities of `NetworkBehaviour`, we can now implement allow and block lists as a separate module.

We introduce a new crate `libp2p-allow-block-list` and deprecate `Swarm::ban_peer_id` in favor of that.

Related #2824.

Pull-Request: #3590.
2023-03-21 20:58:09 +00:00
Thomas Eizinger
3fa10be0d5
feat(swarm): introduce ConnectionId::new_unchecked constructor
In earlier iterations of the design for generic connection management, we removed the `ConnectionId::new` constructor because it would have allowed users to create `ConnectionId`s that are already taken, thus breaking invariants that `NetworkBehaviour`s rely on. Later, we incorporated the creation of `ConnectionId` in `DialOpts` which mitigates this risk altogether.

Thus, it is reasonably safe to introduce a public, non-deprecated constructor for `ConnectionId` that can be used for tests.

Related https://github.com/libp2p/rust-libp2p/pull/3327#issuecomment-1469870307.

Pull-Request: #3652.
2023-03-21 19:28:46 +00:00
Thomas Eizinger
48a70e5102
feat: introduce libp2p-connection-limits connection management module
This patch deprecates the existing connection limits within `Swarm` and uses the new `NetworkBehaviour` APIs to implement it as a plugin instead.

Related #2824.

Pull-Request: #3386.
2023-03-21 15:04:53 +00:00
Max Inden
9f63a0a69e
feat(swarm-test): allow publishing to crates.io
Allows folks like @bajtos to use the crate, see https://github.com/filecoin-station/zinnia/pull/85.

I opted for not exposing the crate through the `libp2p` meta crate as it is a testing tool only. @thomas
let me know if you prefer me to do so.

Pull-Request: #3629.
2023-03-20 17:49:35 +00:00
dependabot[bot]
15ef8c0325
deps: bump clap from 4.1.8 to 4.1.11
Pull-Request: #3638.
2023-03-20 14:06:08 +00:00
Max Inden
9d1116fd5d
feat(perf): implement libp2p perf protocol
Implementation of the libp2p perf protocol according to https://github.com/libp2p/specs/pull/478/.

//CC @MarcoPolo  as the author of the specification.

**Don't (yet) expect this to produce reliable performance metrics.**

Pull-Request: #3508.
2023-03-19 18:20:42 +00:00
Age Manning
eb5e269165
fix(gossipsub): signed messages use monotonically increasing seq numbers
This modifies the gossipsub implementation to use monotonically increasing sequence numbers for signed messages (as dictated by the specification). There is a discussion about this in #3453. This change will make rust-libp2p gossipsub align with the go-implementation when messages are signed.

Messages will however still use randomized sequence numbers when messages are unsigned for security reasons (as discussed in the issue linked).

This shouldn't change any user-level API, only the seqno behavior. It is fully backwards compatible.

Resolves #3453.

Pull-Request: #3551.
2023-03-14 00:06:01 +00:00
Victor Ermolaev
2ec5402474
feat(swarm): enforce creation of Swarm via SwarmBuilder
Mark constructors `Swarm::with_X_executor` as deprecated.
Move the deprecated functionality to `SwarmBuilder::with_X_executor`
Use `SwarmBuilder` throughout.

Resolves #3186.
Resolves #3107.

Pull-Request: #3588.
2023-03-13 19:53:14 +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
Max Inden
3959b2ccef
docs: Prepare v0.51.1 (#3594) 2023-03-12 16:42:57 +01: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
0cad636eba
fix: move changelog entries to correct version
Whilst https://github.com/libp2p/rust-libp2p/pull/3312 was in development, we pushed a new release out and forgot to move the changelog entries to the new version. Unfortunately, this is all still very manual until we have a solution for https://github.com/libp2p/rust-libp2p/issues/2902 so this stuff keeps happening.

Pull-Request: #3541.
2023-03-10 10:59:49 +00:00
dependabot[bot]
645b229d43
deps: bump thiserror from 1.0.38 to 1.0.39
Pull-Request: #3554.
2023-03-08 12:59:53 +00: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
Oleg Kubrakov
b63e05dad6
refactor: move examples to common location
Refactor examples into separate binary crates.

Fixes https://github.com/libp2p/rust-libp2p/issues/3111.

Pull-Request: #3509.
2023-03-08 08:17:33 +00:00
Max Inden
1a2608d084
fix(dcutr): don't set dial concurrency factor in example
Since https://github.com/libp2p/rust-libp2p/pull/2741 the default dial concurrency factor is > 1, more specifically 8. Thus there is no need to explicitly set it anylonger.

Pull-Request: #3550.
2023-03-06 11:48:03 +00:00
Miguel Guarniz
db82e0210e
feat: migrate to quick-protobuf
Instead of relying on `protoc` and buildscripts, we generate the bindings using `pb-rs` and version them within our codebase. This makes for a better IDE integration, a faster build and an easier use of `rust-libp2p` because we don't force the `protoc` dependency onto them.

Resolves #3024.

Pull-Request: #3312.
2023-03-02 10:45:07 +00:00
Thomas Eizinger
73013de3f1
refactor: remove unused dependencies
Pull-Request: #3530.
2023-02-28 23:39:01 +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
d80d92dc45
feat(ci): lint against usages of variables with underscore
Prefixing a variable with an underscore (`_`) in Rust indicates that it is not used. Through refactorings, it can sometimes happen that we do end up using such a variable. In this case, the underscore should be removed.

Clippy can help us with this.

Pull-Request: #3484.
2023-02-24 08:34:59 +00:00
dependabot[bot]
6383e1e8bd
deps: update base64 requirement from 0.20.0 to 0.21.0
Pull-Request: #3315.
2023-02-24 00:36:59 +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
dependabot[bot]
30ff1317d6
deps: bump clap from 4.1.4 to 4.1.6
Pull-Request: #3480.
2023-02-22 23:15:32 +00:00
StemCll
58af2e0887
refactor(gossipsub): make error module private
Resolves https://github.com/libp2p/rust-libp2p/issues/3392.

Pull-Request: #3457.
2023-02-20 19:35:21 +00:00
Elena Frank
79b7cef070
fix(identify): don't close stream in protocol::recv
Don't close the stream `protocol::recv`.

This is a short-term fix for #3298.

The issue behind this is a general one on the QUIC transport when closing streams, as described in #3343. This PR only circumvents the issue for identify. A proper solution for our QUIC transport still needs more thought.

Pull-Request: #3344.
2023-02-19 21:18:54 +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]
063aab5909
deps: bump bytes from 1.3.0 to 1.4.0 (#3422) 2023-02-01 11:34:26 +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
Thomas Eizinger
8f3b7e3876
fix: deal with new lints from beta clippy (#3389)
Most of this is trivial, apart from the rename of the `clippy::derive_hash_xor_eq` lint to `clippy::derived_hash_with_manual_eq`.

Instead of allowing that lint, we manually implement `PartialEq` and add a comment why the difference between the `PartialEq` and `Hash` implementations are okay.
2023-01-31 13:20:26 +00:00
StemCll
ab59af4d46
refactor(gossipsub): revise symbol naming to follow conventions (#3303)
Changes regarding the  #2217
2023-01-27 04:44:04 +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
e55202200c
refactor(gossipsub)!: initialize ProtocolConfig from GossipsubConfig (#3381)
This simplifies the tests as we don't have to go through the `new_handler` abstraction.
2023-01-26 14:39:48 +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
14825c7ecb
feat(swarm): remove unused DialError::ConnectionIo variant (#3374)
This variant is never constructed.
2023-01-26 08:10:08 +00:00