928 Commits

Author SHA1 Message Date
Thomas Eizinger
b8a7684153
feat(swarm): remove deprecated connection limits
Users are encouraged to use `libp2p::connection_limit::Behaviour` which is a one-to-one replacement for this functionality but built as a `NetworkBehaviour`.

Related: #3647.

Pull-Request: #3885.
2023-05-08 10:54:53 +00:00
Thomas Eizinger
8224f1a05d
feat(identify): keep connection alive while we are using it
Currently, the `connection_keep_alive` function of identify does not compute anything but its return value is set through the handler state machine. This is hard to understand and causes surprising behaviour because at the moment, we set `KeepAlive::No` as soon as the remote has answered our identify request. Depending on what else is happening on the connection, this might close the connection before we have successfully answered the remote's identify request.

To fix this, we now compute `connection_keep_alive` based on whether we are still using the connection.

Related: #3844.

Pull-Request: #3876.
2023-05-08 09:31:25 +00:00
Thomas Eizinger
81c424ea9e
feat(swarm): make stream uprade errors more ergonomic
The currently provided `ConnectionHandlerUpgrErr` is very hard to use. Not only does it have a long name, it also features 3 levels of nesting which results in a lot of boilerplate. Last but not least, it exposes `multistream-select` as a dependency to all protocols.

We fix all of the above by renaming the type to `StreamUpgradeError` and flattening out its interface. Unrecoverable errors during protocol selection are hidden within the `Io` variant.

Related: #3759.

Pull-Request: #3882.
2023-05-08 08:55:17 +00:00
Thomas Eizinger
0e36c7c072
feat(swarm): remove deprecated IntoConnectionHandler
This removes the deprecated `IntoConnectionHandler` trait and all its implementations. Consequently, `NetworkBehaviour::new_handler` and `NetworkBehaviour::addresses_of_peer` are now gone and the two `handle_` functions are now required to implement.

Related: #3647.

Pull-Request: #3884.
2023-05-08 08:30:29 +00:00
Thomas Eizinger
b4e724dd72
feat(swarm): remove deprecated banning API
This is replaced by the `libp2p::allow_block_list` module.

Related: #3647.

Pull-Request: #3886.
2023-05-08 05:50:27 +00:00
Thomas Eizinger
b507fe298f
feat(noise): remove deprecated legacy handshakes
This patch removes all deprecated legacy code from `libp2p-noise` and attempts to collapse all the abstraction layers into something a lot simpler.

Pull-Request: #3511.
2023-05-08 05:30:15 +00:00
Thomas Eizinger
53e5370919
feat: don't report inbound stream upgrade errors to handler
When an inbound stream upgrade fails, there isn't a whole lot we can do about that in the handler. In fact, for several errors, we wouldn't even know which specific handler to target, for example, `NegotiationFailed`. Similiarly, in case of an IO error during the upgrade, we don't know which handler the stream was eventually meant to be for.

Pull-Request: #3605.
2023-05-08 04:54:50 +00:00
Thomas Eizinger
fa4adc8c9d
refactor(identify): bring tests up to workspace standard
This patch refactors the identify tests to use `libp2p-swarm-test`. This allows us to delete quite a bit of code and makes several dev-dependencies obsolete.

The `correct_transfer` test is made obsolete by more precise assertions in the `periodic_identify` test. This allows us to remove the dependency on the `upgrade::{apply_inbound,apply_outbound}` functions.

Finally, we also fix a bug where the reported listen addresses to the other node could contain duplicates.

Related: #3748.

Pull-Request: #3851.
2023-05-08 03:39:34 +00:00
Thomas Eizinger
c93f753018
feat: replace ProtocolName with AsRef<str>
Previously, a protocol could be any sequence of bytes as long as it started with `/`. Now, we directly parse a protocol as `String` which enforces it to be valid UTF8.

To notify users of this change, we delete the `ProtocolName` trait. The new requirement is that users need to provide a type that implements `AsRef<str>`.

We also add a `StreamProtocol` newtype in `libp2p-swarm` which provides an easy way for users to ensure their protocol strings are compliant. The newtype enforces that protocol strings start with `/`. `StreamProtocol` also implements `AsRef<str>`, meaning users can directly use it in their upgrades.

`multistream-select` by itself only changes marginally with this patch. The only thing we enforce in the type-system is that protocols must implement `AsRef<str>`.

Resolves: #2831.

Pull-Request: #3746.
2023-05-04 04:47:11 +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
dependabot[bot]
8acbabdaf6
deps: bump clap from 4.2.6 to 4.2.7
Pull-Request: #3870.
2023-05-02 19:57:44 +00:00
dependabot[bot]
6a22bd3df0
deps: bump clap from 4.2.5 to 4.2.6
Pull-Request: #3869.
2023-05-02 19:38:16 +00:00
dependabot[bot]
55e8aea237
deps: bump prometheus-client from 0.19.0 to 0.20.0
Pull-Request: #3754.
2023-05-02 18:49:51 +00:00
Hannes
4bd4653fa9
chore(request-response): remove deprecated items
Related: https://github.com/libp2p/rust-libp2p/issues/3647.

Pull-Request: #3703.
2023-05-02 16:17:15 +00:00
Hannes
25d14349cc
chore(gossipsub): remove deprecated items
Removes deprecated items from gossipsub and make certain modules crate-private.

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

Pull-Request: #3862.
2023-05-02 16:02:21 +00:00
Bogdan
f858ec6237
feat(identify): immediately run identify protocol on new connections
Previously, and for unknown legacy reasons, we waited for a configurable delay (default 500ms) upon new connections before we ran the identify protocol. This unnecessarily slows down applications that wait for the identify handshake to complete before performing further actions.

Resolves #3485.

Pull-Request: #3545.
2023-05-02 14:24:56 +00:00
Hannes
cacfb59781
chore(dcutr): remove deprecated items
Removes deprecated items from `libp2p-dcutr`.

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

Pull-Request: #3700.
2023-05-02 13:30:04 +00:00
Hannes
3e5f64345b
chore(identify): remove deprecated items
Related: https://github.com/libp2p/rust-libp2p/issues/3647.

Pull-Request: #3698.
2023-05-02 13:15:34 +00:00
Thomas Coratger
c728824440
feat(relay): hide internals of Connection
Relayed connections to other peers are created from streams to the relay itself. Internally, such a connection has different states. These however are not relevant to the user and should be encapsulated to allow for more backwards-compatible changes. The only interface exposed is `AsyncRead` and `AsyncWrite`.

Resolves: #3255.

Pull-Request: #3829.
2023-05-02 11:49:07 +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
Max Inden
2d9ae3800f
chore: prepare patch releases on top of v0.51.3
Note that this does not release v0.51.4, i.e. there is no patch release of the meta crate `libp2p`.

Pull-Request: #3854.
2023-05-01 02:56:32 +00:00
Thomas Eizinger
b1cdf8d4bb
feat(yamux): rename symbols to follow module-based naming convention
Implements our naming convention for the `libp2p-yamux` crate.

Related: #2217.

Pull-Request: #3852.
2023-05-01 02:25:52 +00:00
dependabot[bot]
cfdf5c3345
deps: bump clap from 4.2.4 to 4.2.5
Pull-Request: #3849.
2023-04-28 14:21:17 +00:00
Thomas Eizinger
e3a1650933
feat(identify): do not implicitly dial on push
Previously, we would implicitly establish a connection when the user wanted to push identify information to a peer. I believe that this is the wrong behaviour. Instead, I am suggesting to log a message that we are skipping the push to this peer.

Additionally, the way this is currently implemented does not make much sense. Dialing a peer takes time. In case we don't have a connection at all, it could be that we drop the push requests because there isn't an active handler and thus we would have unnecessarily established the connection.

Instead of fixing this - which would require buffering the push messages - I think we should just remove the implicit dial.

Pull-Request: #3843.
2023-04-28 14:06:33 +00:00
Thomas Eizinger
2f5270ba76
feat(noise): deprecate all handshake patterns apart from XX
In the libp2p specs, the only handshake pattern that is specified is the XX handshake. Support for other handshake patterns can be added through external modules. While we are at it, we rename the remaining types to following the laid out naming convention.

The tests for handshakes other than XX are removed. The handshakes still work as we don't touch them in this patch.

Related #2217.

Pull-Request: #3768.
2023-04-28 13:50:31 +00:00
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