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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
- Move helpers to the bottom
- Restructure tests to follow arrange-act-assert
- Only set necessary options on builder for each test
Pull-Request: #3836.
Instead of doing an entire connection establishment dance, we simply use a futures-aware ringbuffer to implement the test. This removes the dependency of `libp2p-plaintext` on the `libp2p_core::upgrade::apply` function.
Related #3748.
Pull-Request: #3770.
Instead of relying on the `MemoryTransport` to provide us with a duplex stream, we use the `futures_ringbuf` crate. This saves us several lines of code and removes the dependency on `libp2p_core::upgrade::apply`.
Related #3748.
Pull-Request: #3772.
Previously, we used a TCP transport to test the deflate compression. Really, all we need is an in-memory ringbuffer that we can plug in at both ends. This PR uses `futures_ringbuf` for that.
Related #3748.
Pull-Request: #3771.
`cargo-semver-checks` v0.20 uses Trustfall's newly-added optimization API to make semver-checking scale as `O(n)` instead of `O(n^2)`. On one large crate this was a 2354x speedup: 5h3min turned into 7.7s!
Pull-Request: #3822.
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.