1954 Commits

Author SHA1 Message Date
Max Inden
ea180aa3a8
*: Prepare v0.42.1 (#2467) 2022-02-02 15:59:32 +01:00
Max Inden
e04e95adcd
transports/tcp/: Call take_error on TCP socket (#2458)
Within `Provider::new_stream` we wait for the socket to become writable
(`stream.writable`), before returning it as a stream. In other words, we
are waiting for the socket to connect before returning it as a new TCP
connection.  Waiting to connect before returning it as a new TCP
connection allows us to catch TCP connection establishment errors early.

While `stream.writable` drives the process of connecting, it does not
surface potential connection errors themselves. These need to be
explicitly collected via `TcpSocket::take_error`. If not explicitly
collected, they will surface on future operations on the socket.

For now this commit explicitly calls `TcpSocket::take_error` when using
`async-io` only. `tokio` introduced the method (`take_error`) in
https://github.com/tokio-rs/tokio/pull/4364 though later reverted it in
https://github.com/tokio-rs/tokio/pull/4392. Once re-reverted, the same
patch can be applied when using `libp2p-tcp` with tokio.

---

One example on how this bug surfaces today:

A `/dnsaddr/xxx` `Multiaddr` can potentially resolve to multiple IP
addresses, e.g. to the IPv4 and the IPv6 addresses of a node.
`libp2p-dns` tries dialing each of them in sequence using `libp2p-tcp`,
returning the first that `libp2p-tcp` reports as successful.

Say that the local node tries the IPv6 address first. In the scenario
where the local node's networking stack does not support IPv6, e.g. has
no IPv6 route, the connection attempt to the resolved IPv6 address of
the remote node fails. Given that `libp2p-tcp` does not call
`TcpSocket::take_error`, it would falsly report the TCP connection
attempt as successful. `libp2p-dns` would receive the "successful" TCP
connection for the IPv6 address from `libp2p-tcp` and would not attempt
to dial the IPv4 address, even though it supports IPv4, and instead
bubble up the "successful" IPv6 TCP connection. Only later, when writing
or reading from the "successful" IPv6 TCP connection, would the IPv6
error surface.

Co-authored-by: Oliver Wangler <oliver@wngr.de>
2022-02-01 19:59:34 +01:00
Max Inden
6338b25e4b
protocols/relay/src/v2: Remove empty peer entries in self.reservations (#2464)
When a peer disconnects, reservations associated with that peer are removed from
the set of reservations of the peer. In case the set of reservations for the
peer is now empty, remove the entire peer.

Same when a reservation times out.
2022-02-01 19:32:58 +01:00
Elena Frank
13ded7f6a8
protocols/autonat/tests: Ignore irrelevant events (#2450)
Ignore `SwarmEvent::ExpiredListenAddr` in tests.
Print swarm event on panic.

Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-29 12:33:15 +01:00
Roland Kuhn
45bb66f862
CHANGELOG.md: Fix link to yamux changelog (#2455) 2022-01-29 12:14:26 +01:00
Max Inden
1201af6904
README: Advertise biweekly community calls (#2454) 2022-01-28 18:46:59 +01:00
Max Inden
73c103e694
protocols/autonat/Cargo.toml: Add description field (#2452)
Without one can not publish the crate to crates.io.
2022-01-27 12:17:02 +01:00
Max Inden
e6ccfbc4e7
*: Prepare v0.42.0 (#2440) 2022-01-27 11:29:09 +01:00
folex
320a1cde00
protocols/kad: Add Kademlia::get_closest_local_peers (#2436)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-22 11:43:07 +01:00
Max Inden
a26b6ab7f0
protocols/autonat: Add changelog and start version at v0.1.0 (#2444)
The `libp2p-autonat` crate has never been released, thus it should start at
`v0.1.0`.
2022-01-20 13:18:05 +01:00
hanabi1224
fad99808ac
*: Update tokio, lru and prost (#2443) 2022-01-20 09:43:32 +01:00
dependabot[bot]
d52ab1baac
build(deps): Update rmp-serde requirement from 0.15 to 1.0 (#2439)
Updates the requirements on [rmp-serde](https://github.com/3Hren/msgpack-rust) to permit the latest version.
- [Release notes](https://github.com/3Hren/msgpack-rust/releases)
- [Commits](https://github.com/3Hren/msgpack-rust/compare/rmp-serde/v0.15.0...rmp-serde/v1.0.0)

---
updated-dependencies:
- dependency-name: rmp-serde
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-19 21:06:02 +01:00
Max Inden
4001b565b6
*: Rework reporting of invalid and wrong PeerIds (#2441)
Previously, the negotiated PeerId was included in the swarm event and
inject_dial_failure’s arguments while the expected one was absent. This
patch adds the negotiated PeerId to the DialError and includes the expected
one in the notifications.

Co-authored-by: Roland Kuhn <rk@rkuhn.info>
2022-01-18 21:21:11 +01:00
Divma
30fc882037
protocols/gossipsub: Implement unsub backoff spec changes (#2403)
Implements the changes specified by
https://github.com/libp2p/specs/pull/383.

Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-17 18:08:34 +01:00
Max Inden
96dbfcd1ad
core/src/transport: Add Transport::dial_as_listener (#2363)
Allows `NetworkBehaviour` implementations to dial a peer, but instruct
the dialed connection to be upgraded as if it were the listening
endpoint.

This is needed when establishing direct connections through NATs and/or
Firewalls (hole punching). When hole punching via TCP (QUIC is different
but similar) both ends dial the other at the same time resulting in a
simultaneously opened TCP connection. To disambiguate who is the dialer
and who the listener there are two options:

1. Use the Simultaneous Open Extension of Multistream Select. See
   [sim-open] specification and [sim-open-rust] Rust implementation.

2. Disambiguate the role (dialer or listener) based on the role within
   the DCUtR [dcutr] protocol. More specifically the node initiating the
   DCUtR process will act as a listener and the other as a dialer.

This commit enables (2), i.e. enables the DCUtR protocol to specify the
role used once the connection is established.

While on the positive side (2) requires one round trip less than (1), on
the negative side (2) only works for coordinated simultaneous dials.
I.e. when a simultaneous dial happens by chance, and not coordinated via
DCUtR, the connection attempt fails when only (2) is in place.

[sim-open]: https://github.com/libp2p/specs/blob/master/connections/simopen.md
[sim-open-rust]: https://github.com/libp2p/rust-libp2p/pull/2066
[dcutr]: https://github.com/libp2p/specs/blob/master/relay/DCUtR.md
2022-01-17 16:35:14 +01:00
dependabot[bot]
bdfbceb6ee
build(deps): Update yamux requirement from 0.9.0 to 0.10.0 (#2435)
* build(deps): Update yamux requirement from 0.9.0 to 0.10.0

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

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

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

* muxers/yamux/CHANGELOG: Add entry

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-17 16:14:31 +01:00
Max Inden
17ee5047e3
protocols/relay: Implement circuit relay v2 protocol (#2059)
This commit adds an implementation for the circuit relay v2 protocol to be used
as a relay server, i.e. it supports incoming HOP requests and outgoing STOP
requests and used as a relay clients, i.e. outgoing HOP requests and incoming
STOP requests.

The existing circuit relay v1 protocol implementation is moved to
protocols/relay/src/v1.

Co-authored-by: ronzigelman <ronzigelman@gmail.com>
Co-authored-by: Marco Munizaga <git@marcopolo.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Elena Frank <57632201+elenaf9@users.noreply.github.com>
2022-01-14 19:58:28 +01:00
folex
3e39cd74a9
misc/metrics: Set libp2p-core default-features = false (#2437) 2022-01-14 17:15:12 +01:00
Max Inden
a2621ad498
swarm/src/lib: Update outdated SwarmEvent::Dialing comment (#2429)
Since https://github.com/libp2p/rust-libp2p/pull/2248 dial attempts are
no longer reported per address, but instead reported for all addresses
of a single dial at once.

This commit updates the comment accordingly.
2022-01-14 13:17:45 +01:00
Elena Frank
c61ea6ad29
protocols/: Add basic AutoNAT implementation (#2262)
This commit adds a behaviour protocol that implements the AutoNAT specification.
It enables users to detect whether they are behind a NAT. The Autonat Protocol
implements a Codec for the Request-Response protocol, and wraps it in a new
Network Behaviour with some additional functionality.

Co-authored-by: David Craven <david@craven.ch>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-14 10:27:28 +01:00
Elena Frank
ddc035170d
protocols/: Fix clippy and fmt warnings (#2433)
* protocols/mdns: fix clippy::to-string-in-format-args

* protocols/gossipsub: fix rustfmt error
2022-01-13 19:35:20 +01:00
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
dependabot[bot]
446fcaad3d
build(deps): Update if-watch requirement from 0.3.0 to 1.0.0 (#2431)
Updates the requirements on [if-watch](https://github.com/dvc94ch/if-watch) to permit the latest version.
- [Release notes](https://github.com/dvc94ch/if-watch/releases)
- [Commits](https://github.com/dvc94ch/if-watch/commits)

---
updated-dependencies:
- dependency-name: if-watch
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-13 17:30:31 +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
Piotr Galar
e19391e966
.github/workflows/: Fix test-wasm and pin third-party action versions (#2424)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-10 16:00:00 +01:00
Ibiyemi Abiodun
71a54d8227
protocols/kad: Implement Error and Clone for error types (#2414) 2022-01-07 12:54:01 +11:00
Roland Kuhn
a29c35f8e7
transports/tcp: Bind to port, not local IP, when dialing (#2382)
When using PortReuse::Enabled, bind to INADDR_ANY to avoid picking the wrong IP.

Co-authored-by: Max Inden <mail@max-inden.de>
2022-01-01 18:45:46 +01:00
Ibiyemi Abiodun
3749dd56f1
protocols/gossipsub: Fix elided lifetime on gossipsub config builder (#2409)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-30 20:23:41 +01:00
Ibiyemi Abiodun
b4468d7500
protocols/kad: Derive Clone for KademliaEvent (#2411) 2021-12-30 19:54:12 +01:00
dependabot[bot]
41826adb48
build(deps): Update open-metrics-client requirement (#2412)
Updates the requirements on [open-metrics-client](https://github.com/mxinden/rust-open-metrics-client) to permit the latest version.
- [Release notes](https://github.com/mxinden/rust-open-metrics-client/releases)
- [Changelog](https://github.com/mxinden/rust-open-metrics-client/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mxinden/rust-open-metrics-client/compare/v0.13.0...v0.14.0)

---
updated-dependencies:
- dependency-name: open-metrics-client
  dependency-type: direct:production
...

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-12-30 15:50:00 +01:00
Max Inden
4b5283643d
swarm/src/protocols_handler/dummy: Make use of void::Void (#2407)
Use `void::unreachable!` to verify `DummyProtocolsHandler` behavior at compile time.
2021-12-30 11:10:13 +01:00
David Craven
df2e5a591e
protocols/mdns: Support multiple network interfaces (#2383)
Handling multiple interfaces in mdns. The socket logic was moved into an
instance while the mdns behaviour watches for interface changes and creates new
instances with a dedicated send/recv socket.

Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-29 19:02:20 +01:00
Piotr Gołąb
23f6b00b66
protocols/rendezvous: Fix wasm32 compatibility (#2401)
Fixes #2399.
2021-12-24 09:13:36 +11:00
Max Inden
5435539d05
protocols/gossipsub/src/config: Document peer exchange not supported (#2397) 2021-12-22 11:55:23 +01:00
Divma
17861d9cac
add performance metrics to gossipsub (#2346)
* add performance metrics to gossipsub

* add changelog entry

* Re-export open-client-metrics crate

* Added some extra metrics

* More metrics

* Additional metrics

* Correct topic encoding

* More manual encoding of metric labels

* Clean up metric labelling

* Improve heartbeat duration buckets

* Remove re-export

Co-authored-by: Age Manning <Age@AgeManning.com>
2021-12-22 09:31:19 +11:00
Age Manning
379001a1d0
protocols/gossipsub: Improve bandwidth (#2327)
This PR adds some bandwidth improvements to gossipsub.

After a bit of inspection on live networks a number of improvements have been
made that can help reduce unnecessary bandwidth on gossipsub networks. This PR
introduces the following:

- A 1:1 tracking of all in-flight IWANT requests. This not only ensures that all
  IWANT requests are answered and peers penalized accordingly, but gossipsub
  will no no longer create multiple IWANT requests for multiple peers.
  Previously, gossipsub sampled the in-flight IWANT requests in order to
  penalize peers for not responding with a high probability that we would detect
  non-responsive nodes. Futher, it was possible to re-request IWANT messages
  that are already being requested causing added duplication in messages and
  wasted unnecessary IWANT control messages. This PR shifts this logic to only
  request message ids that we are not currently requesting from peers.

- Triangle routing naturally gives rise to unnecessary duplicates. Consider a
  mesh of 4 peers that are interconnected. Peer 1 sends a new message to 2,3,4.
  2 propagates to 3,4 and 3 propagates to 2,4 and 4 propagates to 2,3. In this
  case 3 has received the message 3 times. If we keep track of peers that send
  us messages, when publishing or forwarding we no longer send to peers that
  have sent us a duplicate, we can eliminate one of the sends in the scenario
  above. This only occurs when message validation is async however. This PR adds
  this logic to remove some elements of triangle-routing duplicates.

Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Diva M <divma@protonmail.com>
2021-12-21 12:09:15 +01:00
dependabot[bot]
e15dad5f45
build(deps): Update if-watch requirement from 0.2.0 to 0.3.0 (#2387)
Updates the requirements on [if-watch](https://github.com/dvc94ch/if-watch) to permit the latest version.
- [Release notes](https://github.com/dvc94ch/if-watch/releases)
- [Commits](https://github.com/dvc94ch/if-watch/commits)

---
updated-dependencies:
- dependency-name: if-watch
  dependency-type: direct:production
...

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-12-19 15:48:19 +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]
7f258698c8
build(deps): Update if-addrs requirement from 0.6.4 to 0.7.0 (#2381)
Updates the requirements on [if-addrs](https://github.com/messense/if-addrs) to permit the latest version.
- [Release notes](https://github.com/messense/if-addrs/releases)
- [Changelog](https://github.com/messense/if-addrs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/messense/if-addrs/compare/v0.6.4...v0.7.0)

---
updated-dependencies:
- dependency-name: if-addrs
  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 16:45:17 +01:00
David Craven
939e296266
swarm: Expose currently connected peers (#2378)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-13 17:17:12 +01:00
Benoit Verkindt
ab7b5a4574
swarm/src/either: Implement NetworkBehaviour on Either (#2370)
Implement `NetworkBehaviour` on `either::Either<L, R>` where both L
and R both implement `NetworkBehaviour`.

Add NetworkBehaviour derive tests for Either and Toggle

Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-12 12:51:02 +01:00
Benoit Verkindt
dd9e0a14de
swarm/src/behaviour: Move Toggle into swarm::behaviour (#2375)
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-09 12:00:47 +01:00
dependabot[bot]
cf271bcf5a
build(deps): Update sha3 requirement from 0.9 to 0.10 (#2372)
Updates the requirements on [sha3](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/groestl-v0.9.0...sha3-v0.10.0)

---
updated-dependencies:
- dependency-name: sha3
  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:35:49 +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
Max Inden
b316c6deae
swarm/: Improve NetworkBehaviour documentation (#2361)
- Contrast `NetworkBehaviour` and `Transport`.
- Describe hierarchy of `NetworkBehaviour` implementations.
- Describe `NetworkBehaviour` combinators.
- Describe `NetworkBehaviour` derive macro.
  - Document `out_event` mechanism`.
  - Document `ignore` mechanism.
2021-12-08 13:44:37 +01:00
Gerardo Enrique Arriaga Rendon
2c75fbe812
examples/*: Migrate to async await (#2356)
* Adapt examples to async style loop
* Adapt async style loop for chat.rs
* Adapt async style loop for distributed-key-value-store.rs
* Adapt async style loop for gossibsub-chat.rs
* Adapt async style loop for ipfs-private.rs
* Adapt ping to use async
* Update tutorial crate to reflect new changes

Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-06 17:32:58 +01:00
Victor Ermolaev
75ae7b0461
protocols/floodsub: Propagate messages only to target peers (#2360)
Propagate messages only to the target peers and not all connected peers.

Co-authored-by: Victor Ermolaev <victorermolaev@gmail.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-06 17:08:29 +01:00
Victor Ermolaev
4401ffa8b3
protocols/mdns/: Generate peer expiry and fix IPv6 support (#2359)
Co-authored-by: Victor Ermolaev <victorermolaev@gmail.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2021-12-06 16:52:31 +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