951 Commits

Author SHA1 Message Date
Thomas Eizinger
99ad3b6eaf
refactor(kad): don't use OutboundOpenInfo
As part of pushing #3268 forward, remove the use of `OutboundOpenInfo` from `libp2p-kad`.

Related #3268.

Pull-Request: #3760.
2023-04-28 13:37:06 +00:00
Thomas Eizinger
8445079622
refactor(perf): don't use OutboundOpenInfo
Instead of passing the command along, we store it in a buffer and retrieve it once the stream is upgraded.

Related: https://github.com/libp2p/rust-libp2p/issues/3268.

Pull-Request: #3763.
2023-04-28 11:47:10 +00:00
Thomas Eizinger
66466c43af
refactor(dcutr): don't use OutboundOpenInfo
In a previous refactoring, we actually removed the usage of this openinfo so this is just removing dead code.

Related: #3268.

Pull-Request: #3762.
2023-04-28 11:33:31 +00:00
dependabot[bot]
a836bb471f
deps: bump clap from 4.2.1 to 4.2.4
Pull-Request: #3808.
2023-04-28 11:19:43 +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 Coratger
3f6f08d8e0
feat(request-response): make handler and codec modules private
Resolves #3704.

Pull-Request: #3847.
2023-04-28 10:12:07 +00:00
Thomas Eizinger
9d1058df7b
fix(gossipsub): always honor support_floodsub setting
Previously, we only honored the `support_floodsub` setting when the user did not specify a custom protocol for gossipsub. This patch fixes this and allows users to advertise floodsub even when they use a custom protocol.

Pull-Request: #3837.
2023-04-27 05:20:19 +00:00
Thomas Eizinger
71805caaec
refactor(gossipsub): miscellaneous tidy-up of config tests
- Move helpers to the bottom
- Restructure tests to follow arrange-act-assert
- Only set necessary options on builder for each test

Pull-Request: #3836.
2023-04-26 17:05: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]
b4bfaacd05
deps: bump regex from 1.7.3 to 1.8.1
Pull-Request: #3816.
2023-04-24 17:23:39 +00:00
Nathaniel Cook
1f508095dc
fix(kad): preserve deadline in keep alive logic
Previous to this change if the ConnectionHandler::poll for kad was called more frequently than the connection idle timeout the timeout would continually be pushed further into the future. After this change kad now will preserve the existing idle deadline.

Pull-Request: #3801.
2023-04-24 08:55:46 +00:00
Thomas Coratger
270d204db2
feat(gossipsub): make gossipsub modules private
Resolves #3494.

Pull-Request: #3777.
2023-04-23 21:00:23 +00:00
Victor Ermolaev
96288b8984
fix(gossipsub): gracefully disable handler on stream errors
Previously, we closed the entire connection upon receiving too many upgrade errors. This is unnecessarily aggressive. For example, an upgrade error may be caused by the remote dropping a stream during the initial handshake which is completely isolated from other protocols running on the same connection.

Instead of closing the connection, set `KeepAlive::No`.

Related: #3591.
Resolves: #3690.

Pull-Request: #3625.
2023-04-14 15:19:47 +00:00
DrHuangMHT
058c2d85ec
refactor(identity): follow naming conventions for conversion methods
This PR renames some method names that don't follow Rust naming conventions or behave differently from what the name suggests:
- Enforce "try" prefix on all methods that return `Result`.
- Enforce "encode" method name for methods that return encoded bytes.
- Enforce "to_bytes" method name for methods that return raw bytes.
- Enforce "decode" method name for methods that convert encoded key.
- Enforce "from_bytes" method name for methods that convert raw bytes.

Pull-Request: #3775.
2023-04-14 08:55:13 +00:00
Thomas Eizinger
9eb3030b1f
fix(relay): ensure stable connect test
With the changes from #3767, we made the `connect` test flaky because the `Swarm` was fully passed to the future and thus dropped as soon as the connection was established. We pass a mutable reference instead which keeps the `Swarm` alive.

Pull-Request: #3780.
2023-04-12 12:04:01 +00:00
Max Inden
3c5940aead
chore: prepare v0.51.3
Pull-Request: #3779.
2023-04-12 10:28:30 +00:00
Thomas Eizinger
af63130a41
fix(relay): send correct PeerId to client in outbound STOP message
Previously, the relay server would erroneously send its own `PeerId` in the STOP message to the client upon an incoming relay connection. This is obviously wrong and results in failed connection upgrades in other implementations.

Pull-Request: #3767.
2023-04-11 22:11:51 +00:00
dependabot[bot]
849554abb0
deps: bump lru from 0.9.0 to 0.10.0
Pull-Request: #3558.
2023-04-11 17:54:56 +00:00
Max Inden
eeddf2791b
fix(relay): flush relayed connection once idle
As a relay, when forwarding data between relay-connection-source and -destination and vice versa, flush write side when read currently has no more data available.

Pull-Request: #3765.
2023-04-11 16:13:23 +00:00
Thomas Coratger
4cac590765
feat(kad): make implementation modules private
Similar to #3494, make implementation modules private for Kademlia (`kad`).

Resolves #3608.

Pull-Request: #3738.
2023-04-11 14:44:46 +00:00
Darius Clark
8f8c86d347
fix(autonat): prohibit potentially large memory consumption
Autonat uses `Vec` for the servers field to hold a list of `PeerId` when calling `Behaviour::add_server`, but there is no check to prevent duplicated entries of the `PeerId`, which would cause unnecessary allocation overtime with repeated calls to the function.

Resolves #3733.

Pull-Request: #3736.
2023-04-11 11:40:35 +00:00
Benno
1b2de2df3f
fix(kad): export RoutingUpdate
The `RoutingUpdate` type that `add_address` returns was not made available publicly. This type is added in this PR by `pub use`.

Resolves #3737.

Pull-Request: #3739.
2023-04-09 16:35:05 +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
Thomas Eizinger
7c85f92e31
refactor(gossipsub): use pop instead of remove
Doesn't change any functionality but `pop` returns an `Option` whereas `remove` will panic on out-of-bounds. I am more comfortable with `pop` and a pattern match. Also, usage of `continue` allows us to not use an `else`.

Pull-Request: #3734.
2023-04-04 16:04:40 +00:00
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