2425 Commits

Author SHA1 Message Date
Thomas Eizinger
b035fc80a0
feat: report changes in supported protocols to ConnectionHandler
With this patch, implementations of `ConnectionHandler` (which are typically composed in a tree) can exchange information about the supported protocols of a remote with each other via `ConnectionHandlerEvent::ReportRemoteProtocols`. The provided `ProtocolSupport` enum can describe either additions or removals of the remote peer's protocols.

This information is aggregated in the connection and passed down to the `ConnectionHandler` via `ConnectionEvent::RemoteProtocolsChange`.

Similarly, if the listen protocols of a connection change, all `ConnectionHandler`s on the connection will be notified via `ConnectionEvent::LocalProtocolsChange`. This will allow us to eventually remove `PollParameters` from `NetworkBehaviour`.

This pattern allows protocols on a connection to communicate with each other. For example, protocols like identify can share the list of (supposedly) supported protocols by the remote with all other handlers. A protocol like kademlia can accurately add and remove a remote from its routing table as a result.

Resolves: #2680.
Related: #3124.

Pull-Request: #3651.
2023-05-08 14:36:30 +00:00
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
dependabot[bot]
f08055e59b
deps: bump sha3 from 0.10.7 to 0.10.8
Pull-Request: #3893.
2023-05-08 10:38:49 +00:00
dependabot[bot]
b3caae5a88
deps: bump libc from 0.2.142 to 0.2.143
Pull-Request: #3892.
2023-05-08 10:22:04 +00:00
dependabot[bot]
96e7b93ff5
deps: bump serde from 1.0.160 to 1.0.162
Pull-Request: #3891.
2023-05-08 10:04:23 +00:00
dependabot[bot]
869721c459
deps: bump taiki-e/cache-cargo-install-action from 1.1.1 to 1.2.0
Pull-Request: #3890.
2023-05-08 09:47:39 +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
15c623c29a
feat(core): remove SingletonMuxer
This is effectively dead code as nothing within `rust-libp2p` uses it. Users should provide it themselves if they need it.

Pull-Request: #3883.
2023-05-08 05:10:37 +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
2130923aa5
ci: remove protoc installation
With all crates have received a release since https://github.com/libp2p/rust-libp2p/issues/3024, building the baseline rustdoc no longer required `protoc` and we can thus remove it from our CI entirely.

Resolves #3539.

Pull-Request: #3858.
2023-05-08 04:08:44 +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 Coratger
14938043cf
feat(identity): make Keypair and Publickey opaque
`Keypair` and `Publickey` are rendered opaque:
- `Keypair` is replaced by a private `KeyPairInner` enum that is encapsulated inside the `Keypair` `pub struct`
- `Publickey` is replaced by a private `PublickeyInner` enum that is encapsulated inside the `Publickey` `pub struct`

Resolves #3860.

Pull-Request: #3866.
2023-05-05 20:17:47 +00:00
DrHuangMHT
b8411d173f
feat(identity): allow importing and exporting secp256k1 keys
Related: #3681

Pull-Request: #3887.
2023-05-05 13:17:46 +00:00
Thomas Eizinger
eecfe2f094
feat(swarm): report outcome of handling SwarmEvent
Previously, a user wouldn't know whether passing a `SwarmEvent` to `ListenAddresses` or `ExternalAddresses` changed the state. We now return a boolean where `true` indicates that we handled the event **and** changed state as a result.

The API is inspired by `HashSet::insert` and the like.

Pull-Request: #3865.
2023-05-05 07:46:31 +00:00
DrHuangMHT
1eb929b38a
feat(identity): allow importing and exporting ECDSA keys
Implement encoding to/decoding from DER-encoded secret key document for `ecdsa::SecretKey`.
Implement encoding to/decoding from protobuf format for ECDSA keys.
Bump dependency `p256` from 0.12 to 0.13.
Bump dependency `sec1` from 0.3.0 to 0.7

Related: #3681.

Pull-Request: #3863.
2023-05-04 18:36:05 +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
Thomas Eizinger
2d81b99c90
chore(core): remove deprecated upgrades
Related https://github.com/libp2p/rust-libp2p/issues/3647.

Pull-Request: #3867.
2023-05-02 18:11:28 +00:00
Thomas Eizinger
62a06f9ac0
fix(ci): use env variables to ensure escaping
Environment variables are properly escaped in GitHub, thus reducing the risk of code injection.

Pull-Request: #3790.
2023-05-02 17:36:35 +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
dependabot[bot]
9fc2da0180
deps: bump anyhow from 1.0.70 to 1.0.71
Pull-Request: #3856.
2023-05-02 14:11:57 +00:00
dependabot[bot]
e135e55065
deps: bump flate2 from 1.0.25 to 1.0.26
Pull-Request: #3857.
2023-05-02 13:58:44 +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 Eizinger
4ca888580c
refactor(noise): implement tests using futures_ringbuf
Instead of creating a connection via a TCP transport, we can use the `futures_ringbuf` crate and run the noise encryption on an in-memory transport. This removes the dependency on the `libp2p_core::upgrade::apply` function and takes less code to implement.

Related #3748.

Pull-Request: #3773.
2023-05-02 12:15:22 +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
Thomas Eizinger
d1fadc592d
fix(identity): handle warnings related to feature flags
Some of the feature-flags weren't set correctly and thus produced warnings for unused code. We can fix this by using absolute paths instead of imports and allow `dead_code` for the error constructor. It might be possible to write a correct `cfg` for this as well but I think it will be very verbose, hence I didn't bother.

Pull-Request: #3859.
2023-05-01 14:10:37 +00:00
Darius Clark
c8a064b74c
chore(doc): Add missing PR to yamux CHANGELOG.md
Add missing PR to yamux CHANGELOG.md

Pull-Request: #3855.
2023-05-01 08:22:39 +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]
193d2a1a6c
deps: bump sha3 from 0.10.6 to 0.10.7
Pull-Request: #3799.
2023-04-28 14:36:12 +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
dependabot[bot]
4ebb4d0a30
deps: bump serde_json from 1.0.95 to 1.0.96
Pull-Request: #3798.
2023-04-28 12:00:43 +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