512 Commits

Author SHA1 Message Date
Max Inden
74f31f1266
{core,swarm}/: Allow configuring dial concurrency factor per dial (#2404)
Enable a `NetworkBehaviour` or a user via `Swarm::dial` to override the
dial concurrency factor per dial. This is especially relevant in the
case of libp2p-autonat where one wants to probe addresses in sequence to
reduce the amount of work a remote peer can force onto the local node.

To enable the above, this commit also:

- Introduces `libp2p_core::DialOpts` mirroring `libp2p_swarm::DialOpts`.
  Passed as an argument to `Network::dial`.
- Removes `Peer::dial` in favor of `Network::dial`.
- Simplifies `Swarm::dial_with_handler`.

The introduction of `libp2p_core::DialOpts` will be useful beyond this
feature, e.g. for https://github.com/libp2p/rust-libp2p/pull/2363.

In the long run I would like to move and merge `libp2p_core::Network`
and `libp2p_core::Pool` into `libp2p_swarm::Swarm` thus deduplicating
`libp2p_core::DialOpts` and `libp2p_swarm::DialOpts`.

Fixes #2385.
2022-01-13 18:07:07 +01:00
Ibiyemi Abiodun
5617481e56
*: Add Serialize and Deserialize to PeerId gossipsub MessageId and kad Key (#2408)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-11 21:38:51 +01:00
Max Inden
176636f706
core/src/connection: Add ConnectedPoint::is_relayed (#2392)
Add convenience function `is_relayed` to `ConnectedPoint`, determining
whether a connection is relayed based on whether it contains a
`Protocol::P2pCircuit`.
2021-12-19 14:50:55 +01:00
dependabot[bot]
b6c82a499c
build(deps): Update p256 requirement from 0.9.0 to 0.10.0 (#2384)
Updates the requirements on [p256](https://github.com/RustCrypto/elliptic-curves) to permit the latest version.
- [Release notes](https://github.com/RustCrypto/elliptic-curves/releases)
- [Commits](https://github.com/RustCrypto/elliptic-curves/commits/p256/v0.10.0)

---
updated-dependencies:
- dependency-name: p256
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-15 17:29:31 +01:00
dependabot[bot]
3d9ff58ff2
build(deps): Update sha2 requirement from 0.9.1 to 0.10.0 (#2371)
Updates the requirements on [sha2](https://github.com/RustCrypto/hashes) to permit the latest version.
- [Release notes](https://github.com/RustCrypto/hashes/releases)
- [Commits](https://github.com/RustCrypto/hashes/compare/streebog-v0.9.1...sha2-v0.10.0)

---
updated-dependencies:
- dependency-name: sha2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-08 15:07:29 +01:00
Thomas Eizinger
2d61fe296f
*: Fix clippy errors from upgrade to Rust 1.57 (#2365)
* core: Mark "unused" field with "_"

We need to keep this marker type to ensure that the type continues
to be required to be pinned.

* tranports/noise: Derive `Default` for `Config`

`false` is the default for `bool`, we can derive this.

* protocols/request-response: Remove unused fields

These are already included the `RequestResponseMessage::Request`
variant.

* *: Allow clippy's large-enum-variant lint

Tackling these suggestions would require performance measurement
which we don't want to do at this stage.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-06 16:13:42 +01:00
Davide Galassi
245b0563ab
core/: Add support for ECDSA identities (#2352)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-30 17:47:35 +01:00
Dan Shields
a7ed1d6b6e
*: Migrate to Rust 2021 edition (#2339)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-26 17:34:58 +01:00
Divma
fd417517ca
swarm/: Patch reporting on banned peer connections (#2350)
Don't report events of a connection to the `NetworkBehaviour`, if connection has
been established while the remote peer was banned. Among other guarantees this
upholds that `NetworkBehaviour::inject_event` is never called without a previous
`NetworkBehaviour::inject_connection_established` for said connection.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-11-26 16:48:12 +01:00
Max Inden
4bd44c812a
*: Prepare v0.41.0 (#2342) 2021-11-16 16:39:42 +01:00
Max Inden
012287ad1e
Merge branch 'libp2p/v0.40' into master (#2324)
* *: Prepare v0.40.0 release (#2323)

* Cargo.toml: Remove rc suffix
2021-11-02 20:40:48 +01:00
Max Inden
ff5d455ccf
*: Enable libp2p to run via wasm32-unknown-unknown in the browser (#2320)
Changes needed to get libp2p to run via `wasm32-unknown-unknown` in the browser
(both main thread and inside web workers).

Replaces wasm-timer with futures-timer and instant.

Co-authored-by: Oliver Wangler <oliver@wngr.de>
2021-10-30 12:41:30 +02:00
Max Inden
8ea60af589
*: Prepare v0.40.0-rc.3 release candidate (#2313) 2021-10-27 19:27:31 +02:00
Oliver Wangler
6e76435b80
core/: Help the compiler disambiguate usize inference (#2310)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-10-27 18:49:51 +02:00
Qinxuan Chen
97509519c5
core/: Update libsecp256k1 from 0.6 to 0.7 (#2306)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2021-10-22 12:09:02 +02:00
Max Inden
cd2588e182
core/tests/connection_limit: Fix flake in max_established_incoming (#2295)
The test `max_established_incoming` starts two networks with a
configured connection limit, spawns up to `limit + 1` connections and
expects the last connection to be closed due to being over the limit.

The previous test implementation depended on both networks to handle
each connection in sequence, which is not always the case.

E.g. while network 2 might expect the last connection to close, network
1 might finish upgrading the last connection before the second to last
  connection, thus expecting the second to last connection to close.

This commit drives network 1 and 2 in sequence and ensures both networks
are finished upgrading a connection before starting a new connection. In
addition it upgrade the test to use `quickcheck`.
2021-10-20 20:22:53 +02:00
Max Inden
a905665b8b
*: Prepare v0.40.0-rc.1 release (#2290) 2021-10-15 11:15:05 +02:00
Max Inden
40c5335e3b
core/: Concurrent dial attempts (#2248)
Concurrently dial address candidates within a single dial attempt.

Main motivation for this feature is to increase success rate on hole punching
(see https://github.com/libp2p/rust-libp2p/issues/1896#issuecomment-885894496
for details). Though, as a nice side effect, as one would expect, it does
improve connection establishment time.

Cleanups and fixes done along the way:

- Merge `pool.rs` and `manager.rs`.

- Instead of manually implementing state machines in `task.rs` use
  `async/await`.

- Fix bug where `NetworkBehaviour::inject_connection_closed` is called without a
  previous `NetworkBehaviour::inject_connection_established` (see
  https://github.com/libp2p/rust-libp2p/issues/2242).

- Return handler to behaviour on incoming connection limit error. Missed in
  https://github.com/libp2p/rust-libp2p/issues/2242.
2021-10-14 18:05:07 +02:00
dependabot[bot]
c0d7d4a9eb
build(deps): Update prost-build requirement from 0.8 to 0.9 (#2288)
Updates the requirements on [prost-build](https://github.com/tokio-rs/prost) to permit the latest version.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: prost-build
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-14 14:44:34 +02:00
dependabot[bot]
3cc102da91
build(deps): Update prost requirement from 0.8 to 0.9 (#2287)
Updates the requirements on [prost](https://github.com/tokio-rs/prost) to permit the latest version.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: prost
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-14 14:16:54 +02:00
Elena Frank
7718d1de38
core/connection/listeners: Create event on remove_listener (#2261)
Create a `ListenersEvent::Closed` when a listener is removed via
`Swarm::remove_listener`. This makes it more consistent with `Swarm::listen_on`,
and also informs the Swarm about the associated expired addresses.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-10-11 22:38:55 +02:00
r-zig
57f34f6f26
core/src/connections: Avoid call to contains twice (#2279) 2021-10-08 10:18:34 +02:00
Roman
b79fd02f0b
*: Fix clippy warnings (#2227) 2021-09-14 15:00:05 +02:00
Max Inden
733a0b6ce4
core/src/network/event.rs: Fix typo (#2218) 2021-09-07 17:08:45 +02:00
Thomas Eizinger
adcfdc0750
protocols/rendezvous: Implement protocol (#2107)
Implement the libp2p rendezvous protocol.

> A lightweight mechanism for generalized peer discovery. It can be used for
bootstrap purposes, real time peer discovery, application specific routing, and
so on.

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-09-07 16:36:52 +02:00
Thomas Eizinger
6924e5ef7a
core/: Remove deprecated read/write functions (#2213)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-09-06 08:04:30 +02:00
Max Inden
c161acfb50
*: Dial with handler and return handler on error and closed (#2191)
Require `NetworkBehaviourAction::{DialPeer,DialAddress}` to contain a
`ProtocolsHandler`. This allows a behaviour to attach custom state to its
handler. The behaviour would no longer need to track this state separately
during connection establishment, thus reducing state required in a behaviour.
E.g. in the case of `libp2p-kad` the behaviour can include a `GetRecord` request
in its handler, or e.g. in the case of `libp2p-request-response` the behaviour
can include the first request in the handler.

Return `ProtocolsHandler` on connection error and close. This allows a behaviour
to extract its custom state previously included in the handler on connection
failure and connection closing. E.g. in the case of `libp2p-kad` the behaviour
could extract the attached `GetRecord` from the handler of the failed connection
and then start another connection attempt with a new handler with the same
`GetRecord` or bubble up an error to the user.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-08-31 17:00:51 +02:00
Max Inden
1e9fcf90ea
core/: Remove DisconnectedPeer::set_connected and Pool::add (#2195)
This logic seems to be a leftover of
https://github.com/libp2p/rust-libp2p/pull/889 and unused today.
2021-08-19 20:17:18 +02:00
Max Inden
f701b24ec0
*: Format with rustfmt (#2188)
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-08-11 13:12:12 +02:00
Max Inden
008561283e
core/: Remove TInEvent and TOutEvent (#2183)
TInEvent and TOutEvent are implied through THandler and thus
superflucious. Both are removed in favor of a derivation through
THandler.
2021-08-11 12:41:28 +02:00
Age Manning
76f1fcbee3
core: Add a total established connection limit (#2137)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-30 19:22:53 +02:00
izolyomi
99c7078bcf
core/identity: Document using external fixed keys for network identity (#2165)
Co-authored-by: István Zólyomi <istvan.zolyomi@iop-ventures.com>
Co-authored-by: Ruben De Smet <ruben.de.smet@rubdos.be>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-28 21:43:51 +02:00
Ruben De Smet
50b0957dfe
core/: Add Keypair::to_protobuf_encoding (#2142)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-28 17:59:08 +02:00
dependabot[bot]
e437c009dc
build(deps): Update libsecp256k1 requirement from 0.5.0 to 0.6.0 (#2151)
Updates the requirements on [libsecp256k1](https://github.com/paritytech/libsecp256k1) to permit the latest version.
- [Release notes](https://github.com/paritytech/libsecp256k1/releases)
- [Changelog](https://github.com/paritytech/libsecp256k1/blob/master/CHANGELOG.md)
- [Commits](https://github.com/paritytech/libsecp256k1/commits)

---
updated-dependencies:
- dependency-name: libsecp256k1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-23 10:54:15 +02:00
Ruben De Smet
371a7dab2c
to/into consistency for PublicKey and PeerId (#2145)
- Change `PublicKey::into_protobuf_encoding` to
  `PublicKey::to_protobuf_encoding`.

- Change `PublicKey::into_peer_id` to `PublicKey::to_peer_id`.

- Change `PeerId::from_public_key(PublicKey)` to
  `PeerId::from_public_key(&PublicKey)`.

- Add `From<&PublicKey> for PeerId`.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-22 22:34:13 +02:00
Thomas Eizinger
20183c1ea1
*: Fix clippy warnings (#2139)
* Fix needless question mark operator

* Don't convert from u64 to u64

LocalStreamId is already a u64, no need to convert.

* Don't use `.into()` to convert to the same type

* Don't specify lifetime if it can be inferred

* Use `vec!` macro if we immediately push to it

This creates the vector with the appropriate capacity.

* Don't index array when taking a reference is enough

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-16 15:11:25 +02:00
Max Inden
b5c6fa6281
*: Prepare v0.39.0 release (#2132) 2021-07-12 21:24:58 +02:00
dependabot[bot]
ee11922d97
build(deps): Update multiaddr requirement from 0.12.0 to 0.13.0 (#2129)
* build(deps): Update multiaddr requirement from 0.12.0 to 0.13.0

Updates the requirements on [multiaddr](https://github.com/multiformats/rust-multiaddr) to permit the latest version.
- [Release notes](https://github.com/multiformats/rust-multiaddr/releases)
- [Changelog](https://github.com/multiformats/rust-multiaddr/blob/master/CHANGELOG.md)
- [Commits](https://github.com/multiformats/rust-multiaddr/compare/v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: multiaddr
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): Update multihash requirement from 0.13 to 0.14

Updates the requirements on [multihash](https://github.com/multiformats/rust-multihash) to permit the latest version.
- [Release notes](https://github.com/multiformats/rust-multihash/releases)
- [Commits](https://github.com/multiformats/rust-multihash/compare/v0.13.0...v0.14.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-09 16:21:12 +02:00
Elena Frank
99da27bd97
*: Patch prost / prost-build version to v0.8 (#2126) 2021-07-09 14:38:03 +02:00
Thomas Eizinger
c1ef4bffd2
core/: Redesign upgrade::{write_one, write_with_len_prefix, read_one} (#2111)
1. Deprecating the `write_one` function

  Semantically, this function is a composition of `write_with_len_prefix` and
  `io.close()`. This represents a footgun because the `close` functionality is
  not obvious and only mentioned in the docs. Using this function multiple times
  on a single substream will produces hard to debug behaviour.

2. Deprecating `read_one` and `write_with_len_prefix` functions

3. Introducing `write_length_prefixed` and `read_length_prefixed`

- These functions are symmetric and do exactly what you would expect, just
  writing to the socket without closing
- They also have a symmetric interface (no more custom errors, just `io::Error`)

Co-authored-by: Max Inden <mail@max-inden.de>
2021-07-03 16:23:10 +02:00
Max Inden
762f4e35e7
core/CHANGELOG: Add entry for PR 2090 (#2097)
Include changelog entry for a24e4221bdeeffc9260e6e08636bc7f8f231e168.
2021-06-08 10:14:31 +02:00
Max Inden
a24e4221bd
core/src/identity: Implement Keypair::from_protobuf_encoding for ed25519 (#2090)
Implement `Keypair` decoding from Protobuf according to [peer id
specification]. For now support ed25519 keys only. Future commits might
add RSA secp256k1 and ecdsa.

[peer id specification]: https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#keys
2021-06-07 10:17:46 +02:00
Max Inden
28fe6eda28
*: Use upstream multiaddr crate (#2075)
Use multiaddr instead of parity-multiaddr, removing the latter from the
repository.
2021-05-27 14:04:33 +02:00
dependabot[bot]
bf0cdbbff1
build(deps): Update libsecp256k1 requirement from 0.3.1 to 0.5.0 (#2074)
* build(deps): Update libsecp256k1 requirement from 0.3.1 to 0.5.0

Updates the requirements on [libsecp256k1](https://github.com/paritytech/libsecp256k1) to permit the latest version.
- [Release notes](https://github.com/paritytech/libsecp256k1/releases)
- [Changelog](https://github.com/paritytech/libsecp256k1/blob/master/CHANGELOG.md)
- [Commits](https://github.com/paritytech/libsecp256k1/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* core/identity/scp256k1: Use libsecp256k1::SecretKey::random directly

* core/: Update changelog and cargo toml

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-05-21 14:15:51 +02:00
Artem Vorotnikov
5ee003b76e
core/src/identity: Fix build with secp256k1 disabled (#2057) 2021-04-26 16:53:50 +02:00
Max Inden
42441dbd86
*: Prepare v0.37.0 release (#2049) 2021-04-13 20:15:15 +02:00
David Craven
7779b8e2c1
swarm: Extend NetworkBehaviour callbacks. (#2011)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-03-24 17:21:53 +01:00
Max Inden
ba90827e46
core: Update to asn1_der v0.7 (#2000) 2021-03-22 13:53:47 +01:00
Max Inden
16018643cf
core/: Prepare libp2p-core v0.28.1 incl multiaddr v0.11.2
libp2p-dns requires a new feature in parity-multiaddr v0.11.2 namely
Multiaddr::ends_with. libp2p-dns does not depend on parity-multiaddr
directly but through libp2p-core. Prepare a new version of libp2p-core
requiring at least parity-multiaddr v0.11.2 and update libp2p-dns to
require libp2p-core v0.28.1.
2021-03-17 16:39:18 +01:00
Max Inden
0934b0178d
*: Prepare v0.36.0 release 2021-03-17 15:28:13 +01:00