43 Commits

Author SHA1 Message Date
Max Inden
d605255fec
feat(libp2p): add SwarmBuilder
Introduce the new `libp2p::SwarmBuilder`. Users should use the new `libp2p::SwarmBuilder` instead of the now deprecated `libp2p::swarm::SwarmBuilder`. See `libp2p::SwarmBuilder` docs on how to use the new builder.

Fixes #3657.
Fixes #3563.
Fixes #3179.

Pull-Request: #4120.
2023-10-10 06:55:14 +00:00
Binston Sukhael Cardoza
0e9d339bd2
ci: use workspace inheritance to enforce lints in all crates
Starting with nightly-2023-09-10, the `[lints]` section in `Cargo.toml` files is stable. Together with workspace inheritance, this can be used to declare all lints we want to enforce in a single place.

Resolves: #4484.

Pull-Request: #4575.
2023-10-09 02:20:46 +00:00
Max Inden
d862b40383
refactor(examples): remove #[behaviour(to_swarm = "Event")]
Removes the usage of the `to_swarm` `libp2p-swarm-derive` attribute in favor of the automatically generated event through the `NetworkBehaviour` derive macro.

Pull-Request: #4580.
2023-10-03 22:21:17 +00:00
Panagiotis Ganelis
c8b5f49ec2
refactor(kad): rename to follow naming convention across repository
Renamed the following

`kad::Kademlia` -> `kad::Behaviour`
`kad::KademliaEvent` -> `kad::Event`
`kad::KademliaBucketInserts` -> `kad::BucketInserts`
`kad::KademliaStoreInserts` -> `kad::StoreInserts`
`kad::KademliaConfig` -> `kad::Config`
`kad::KademliaCaching` -> `kad::Caching`
`kad::KademliaEvent` -> `kad::Event`
`kad::KademliaConnectionType` -> `kad::ConnectionType`
`KademliaHandler` -> `Handler`
`KademliaHandlerEvent` -> `HandlerEvent`
`KademliaProtocolConfig` -> `ProtocolConfig`
`KademliaHandlerIn` -> `HandlerIn`
`KademliaRequestId` -> `RequestId`
`KademliaHandlerQueryErr` -> `HandlerQueryErr`

Resolves: #4485

Pull-Request: #4547.
2023-09-27 20:25:22 +00:00
Thomas Eizinger
2157052794
examples: employ consistent naming
Resolves: #4459.

Pull-Request: #4533.
2023-09-21 01:10:24 +00:00
dependabot[bot]
eb83367430
deps: bump clap from 4.3.21 to 4.3.23
Pull-Request: #4359.
2023-08-21 09:37:15 +00:00
dependabot[bot]
8022769daf
deps: bump clap from 4.3.19 to 4.3.21
Pull-Request: #4319.
2023-08-14 09:20:07 +00:00
Max Inden
fbf35e14cb
fix(examples/file-sharing): set Kademlia Mode::Server
Explicitly set `libp2p-kad` `Kademlia::set_mode` to `Mode::Server` to reduce complexity of example, i.e. not having to explicitly set external addresses.

Pull-Request: #4197.
2023-08-01 13:53:38 +00:00
dependabot[bot]
12c98dca35
deps: bump either from 1.8.1 to 1.9.0
Pull-Request: #4243.
2023-07-24 16:02:14 +00:00
dependabot[bot]
132688961f
deps: bump clap from 4.3.11 to 4.3.12
Pull-Request: #4206.
2023-07-19 13:10:14 +00:00
dependabot[bot]
2f288523b0
deps: bump clap from 4.3.10 to 4.3.11
Pull-Request: #4178.
2023-07-11 11:44:04 +00:00
dependabot[bot]
62ab42aecb
deps: bump clap from 4.3.8 to 4.3.10
Pull-Request: #4144.
2023-07-03 16:46:28 +00:00
dependabot[bot]
6241b92fe4
deps: bump clap from 4.3.3 to 4.3.8
Pull-Request: #4118.
2023-06-26 10:43:20 +00:00
dependabot[bot]
e28f0326c7
deps: bump clap from 4.3.2 to 4.3.3
Pull-Request: #4061.
2023-06-20 15:23:15 +00:00
Thomas Eizinger
ed14630672
feat: leverage type-safe /p2p in multiaddr
This updates `multiaddr` to version `0.19`.

Depends-On: #3656.
Depends-On: https://github.com/multiformats/rust-multiaddr/pull/83.
Resolves: #4039.

Pull-Request: #4037.
2023-06-08 01:38:18 +00:00
Thomas Coratger
90d6a77e6a
feat(examples): use cbor codec in file-sharing example
Remove the use of the core `upgrade::transfer` module in `file-sharing` example in favor of `cbor` codec.

Related #4011.

Pull-Request: #4036.
2023-06-06 20:10:22 +00:00
dependabot[bot]
c723df461f
deps: bump clap from 4.3.0 to 4.3.1
Pull-Request: #4027.
2023-06-05 10:59:28 +00:00
Thomas Coratger
75edcfcdb0
docs(examples): add a README to each example
Resolves #3853.

Pull-Request: #3974.
2023-06-01 07:40:22 +00:00
Denis Garus
a5cd0d0e03
feat(request-response): add modules for json and cbor messages
This patch adds two modules to `libp2p::request_response`:

- `cbor`
- `json`

Both define a `Behaviour` type-alias that comes with a `Codec` implementation which uses the respective `serde` crate to serialize and deserialize the messages.

Fixes #3905.

Pull-Request: #3952.
2023-05-24 11:13:12 +00:00
dependabot[bot]
d090b58881
deps: bump clap from 4.2.7 to 4.3.0
Pull-Request: #3970.
2023-05-22 18:48:38 +00:00
Max Inden
cc5b346a7c
feat(swarm): expose ConnectionId and add conn duration metric
- Exposes the `ConnectionId` in the various `SwarmEvent` variants.
- Tracks connection duration in `libp2p-metrics::swarm`.

Pull-Request: #3927.
2023-05-17 05:19:53 +00:00
Thomas Eizinger
1742bffcea
feat(request-response): don't close connection on stream errors
Related: #3591.

Pull-Request: #3913.
2023-05-15 02:40:55 +00:00
Thomas Coratger
6e36e8aa35
feat(swarm): rename associated types for message passing
Previously, the associated types on `NetworkBehaviour` and `ConnectionHandler` carried generic names like `InEvent` and `OutEvent`. These names are _correct_ in that `OutEvent`s are passed out and `InEvent`s are passed in but they don't help users understand how these types are used.

In theory, a `ConnectionHandler` could be used separately from `NetworkBehaviour`s but that is highly unlikely. Thus, we rename these associated types to indicate, where the message is going to be sent to:

- `NetworkBehaviour::OutEvent` is renamed to `ToSwarm`: It describes the message(s) a `NetworkBehaviour` can emit to the `Swarm`. The user is going to receive those in `SwarmEvent::Behaviour`.
- `ConnectionHandler::InEvent` is renamed to `FromBehaviour`: It describes the message(s) a `ConnectionHandler` can receive from its behaviour via `ConnectionHandler::on_swarm_event`. The `NetworkBehaviour` can send it via the `ToSwarm::NotifyHandler` command.
- `ConnectionHandler::OutEvent` is renamed to `ToBehaviour`: It describes the message(s) a `ConnectionHandler` can send back to the behaviour via the now also renamed `ConnectionHandlerEvent::NotifyBehaviour` (previously `ConnectionHandlerEvent::Custom`)

Resolves: #2854.

Pull-Request: #3848.
2023-05-14 10:58:08 +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
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]
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
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
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
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
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
Thomas Eizinger
28da3d4180
fix(ci): ensure all examples compile with the specified feature-set
Due to cargo's feature unification, a full build of our workspace doesn't actually check whether the examples compile as standalone projects.

We add a new CI check that iterates through all crates in the `examples/` directory and runs a plain `cargo check` on them. Any failure is bubbled up via `set -e`, thus failing CI in case one of the `cargo check` commands fails.

To fix the current failures, we construct a simple TCP transport everywhere where we were previously using `development_transport`. That is because `development_transport` requires `mplex` which is now deprecated.

Related #3657.
Related #3809.

Pull-Request: #3811.
2023-04-21 09:58:08 +00:00
dependabot[bot]
95fa913923
deps: bump multiaddr from 0.17.0 to 0.17.1
Pull-Request: #3688.
2023-04-04 13:38:53 +00:00
Thomas Coratger
44d4b1133d
feat(libp2p): deprecate mplex
`mplex` module (no flow control and no streams limit) is deprecated to encourage `yamux` usage.

Resolves #3677.

Pull-Request: #3689.
2023-04-04 09:49:59 +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
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
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
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
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
d53cfed236
chore: move libp2p crate to a dedicated directory
Currently, our top-level `Cargo.toml` manifest represents a crate AND a workspace. This causes surprising behaviour (e.g. #2949) where we need to explicitly pass `--workpace` to every command to run it on the entire workspace and not just the meta crate.

My moving the meta crate into its own directory, the root manifest file is a virtual manifest only and thus, every `cargo` command will automatically default to running on the entire workspace.

On top of this, I personally find it easier to understand if workspace and crate manifests are not mixed.

Pull-Request: #3536.
2023-03-08 13:20:39 +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