1954 Commits

Author SHA1 Message Date
Hubert
163c5c1752
README.md: Add crates.io and docs.rs badges (#2766) 2022-07-22 06:58:41 +10:00
tgmichel
c8066df232
*: Update to if-watch 1.1.1 (#2754) 2022-07-19 09:14:00 +02:00
Max Inden
66c2319230
transports/tcp: Bump to v0.35.0 (#2760)
Follow up on https://github.com/libp2p/rust-libp2p/pull/2724/. Given that
libp2p-core is bumped to v0.35.0, libp2p-tcp needs to be bumped as well.
2022-07-19 08:57:50 +02:00
dependabot[bot]
e95232cfaa
build(deps): Bump Swatinem/rust-cache from 1.4.0 to 2.0.0 (#2759)
* build(deps): Bump Swatinem/rust-cache from 1.4.0 to 2.0.0

Bumps [Swatinem/rust-cache](https://github.com/Swatinem/rust-cache) from 1.4.0 to 2.0.0.
- [Release notes](https://github.com/Swatinem/rust-cache/releases)
- [Changelog](https://github.com/Swatinem/rust-cache/blob/master/CHANGELOG.md)
- [Commits](cb2cf0cc7c...6720f05bc4)

---
updated-dependencies:
- dependency-name: Swatinem/rust-cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-19 04:04:26 +02:00
Thomas Eizinger
1a553db596
core/muxing: Flatten StreamMuxer interface to poll_{inbound,outbound,address_change,close} (#2724)
Instead of having a mix of `poll_event`, `poll_outbound` and `poll_close`, we
flatten the entire interface of `StreamMuxer` into 4 individual functions:

- `poll_inbound`
- `poll_outbound`
- `poll_address_change`
- `poll_close`

This design is closer to the design of other async traits like `AsyncRead` and
`AsyncWrite`. It also allows us to delete the `StreamMuxerEvent`.
2022-07-18 05:20:11 +02:00
Max Inden
d4f8ec2d48
misc/metrics: Track # connected nodes supporting specific protocol (#2734)
* misc/metrics: Explicitly delegate event recording to each recorder

This allows delegating a single event to multiple `Recorder`s. That enables e.g. the
`identify::Metrics` `Recorder` to act both on `IdentifyEvent` and `SwarmEvent`. The latter enables
it to garbage collect per peer data on disconnects.

* protocols/dcutr: Expose PROTOCOL_NAME

* protocols/identify: Expose PROTOCOL_NAME and PUSH_PROTOCOL_NAME

* protocols/ping: Expose PROTOCOL_NAME

* protocols/relay: Expose HOP_PROTOCOL_NAME and STOP_PROTOCOL_NAME

* misc/metrics: Track # connected nodes supporting specific protocol

An example metric exposed with this patch:

```
libp2p_identify_protocols{protocol="/ipfs/ping/1.0.0"} 10
```

This implies that 10 of the currently connected nodes support the ping protocol.
2022-07-15 09:16:03 +02:00
Max Inden
7c8a97739f
swarm/src/handler: Document responsibility limiting inbound streams (#2752)
Document that the `ConnectionHandler` implementation has to enforce a limit on
the number of inbound substreams.
2022-07-14 06:15:19 +02:00
Chad Nehemiah
d0da3a0973
swarm/: Set default dial concurrency factor to 8 (#2741) 2022-07-07 11:20:03 +02:00
Roman
2f2b7cbec1
*: Bump swarm-derive version and prepare v0.46.1 (#2747) 2022-07-06 01:48:30 +02:00
Max Inden
7df6bae520
*: Prepare v0.46.0 (#2730) 2022-07-05 13:09:58 +02:00
Elena Frank
62622a1bad
core/src/transport: Poll Transport directly, remove Transport::Listener (#2652)
Remove the concept of individual `Transport::Listener` streams from `Transport`.
Instead the `Transport` is polled directly via `Transport::poll`. The
`Transport` is now responsible for driving its listeners.
2022-07-04 04:16:57 +02:00
Max Inden
b28cdb31f9
protocols/identify: Fix race condition in discover_peer_after_disconnect (#2744)
**Summary** of the plot of the `discover_peer_after_disconnect` test:

1. `swarm2` connects to `swarm1`.
2. `swarm2` requests an identify response from `swarm1`.
3. `swarm1` sends the response to `swarm2`.
4. `swarm2` disconnects from `swarm1`.
5. `swarm2` tries to disconnect.

**Problem**

`libp2p-identify` sets `KeepAlive::No` when it identified the remote. Thus `swarm1` might
identify` `swarm2` before `swarm2` identified `swarm1`. `swarm1` then sets `KeepAlive::No` and thus closes the
connection to `swarm2` before `swarm2` identified `swarm1`. In such case the unit test
`discover_peer_after_disconnect hangs indefinitely.

**Solution**

Add an initial delay to `swarm1` requesting an identification from `swarm2`, thus ensuring `swarm2`
is always able to identify `swarm1`.
2022-07-04 03:58:16 +02:00
bernardo
6db57121e9
protocols/gossipsub/: Allow custom protocol id (#2718)
Allow for custom protocol ID via `GossipsubConfigBuilder::protocol_id()`.
2022-07-02 10:30:02 +02:00
Max Inden
31f1d66138
Cargo.toml: Undo version bump to v0.47.0 as v0.46.0 is unreleased (#2733) 2022-07-01 16:33:27 +02:00
Max Inden
862ae14ae2
protocols/rendezvous/src/client: Fix clippy warning let-unit-value (#2742) 2022-07-01 16:13:21 +02:00
Akihito Nakano
748588e3f0
protocols/gossipsub: Fix a typo in error message (#2739)
* protocols/gossipsub: Fix a typo in error message

* protocols/gossipsub: Make the error message accurately
2022-06-30 10:20:26 +02:00
Elena Frank
423adca0bf
protocols/identify: Fix dev deps for example (#2737) 2022-06-29 06:37:57 +02:00
dependabot[bot]
9f7d0fe0ac
build(deps): Bump styfle/cancel-workflow-action from 0.9.1 to 0.10.0 (#2731)
Bumps [styfle/cancel-workflow-action](https://github.com/styfle/cancel-workflow-action) from 0.9.1 to 0.10.0.
- [Release notes](https://github.com/styfle/cancel-workflow-action/releases)
- [Commits](a40b8845c0...bb6001c4ea)

---
updated-dependencies:
- dependency-name: styfle/cancel-workflow-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-28 05:23:35 +02:00
Max Inden
71909522cf
transports/tcp/: Call take_error on tokio TcpStream (#2725)
See e04e95a for the rational.

With tokio `v1.19.0` released, `TcStream` exposes `take_error`.

This commit applies the same fix from e04e95a to the tokio TCP provider.
2022-06-27 09:36:33 +02:00
pj50
f814b21f5a
protocols/relay: Don't duplicate p2p protocol in relay reservation (#2696) (#2701) 2022-06-27 06:54:40 +02:00
dadepo
40744beec1
protocols/identify/: Add example (#2689) 2022-06-27 04:17:59 +02:00
Max Inden
072d7364a1
swarm/CHANGELOG: Merge unreleased section v0.36.2 with v0.37.0 (#2727) 2022-06-26 14:24:50 +02:00
Max Inden
2c70c59618
protocols/identify: Extend log message on second identify push (#2726)
Print remote peer ID when seeing a second identify push stream coming in.
2022-06-26 10:37:29 +02:00
Thomas Eizinger
0f40e513cc
core/muxing: Replace Into<io::Error> bound on StreamMuxer with std::error::Error (#2710)
* core/muxing: Remove `Into<io::Error>` bound from `StreamMuxer::Error`

This allows us to preserve the type information of a muxer's concrete
error as long as possible. For `StreamMuxerBox`, we leverage `io::Error`'s
capability of wrapping any error that implements `Into<Box<dyn Error>>`.

* Use `?` in `Connection::poll`

* Use `?` in `muxing::boxed::Wrap`

* Use `futures::ready!` in `muxing::boxed::Wrap`

* Fill PR number into changelog

* Put `Error + Send + Sync` bounds directly on `StreamMuxer::Error`

* Move `Send + Sync` bounds to higher layers

* Use `map_inbound_stream` helper

* Update changelog to match new implementation
2022-06-24 08:26:49 +02:00
Thomas Eizinger
eb490c08e9
core/muxing: Force StreamMuxer::Substream to implement Async{Read,Write} (#2707)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-06-23 21:52:11 +10:00
Max Inden
118046c9e0
transports/uds: Bump version due to libp2p-core upgrade (#2720)
`libp2p` 0.45.1 depends (amongst others) on `libp2p-uds` v0.32.0 and on
`libp2p-core` v0.33.0 `libp2p-uds` v0.32.0, however, depends on `libp2p-core`
v0.32.0.

This commit changes the version mismatch for the upcoming `libp2p release.
2022-06-23 08:48:05 +02:00
Max Inden
7eaa9c7bb7
swarm/src/connection: Extend log when exceeding streams limit (#2716)
Log peer ID and stream limit as well as reference config option when limit is
exceeded. This should help folks running into this limit debug what is going on.
2022-06-22 06:02:55 +02:00
Friedel Ziegelmayer
e2bef93bd7
protocols/autonat: Export DEFAULT_PROTOCOL_NAME (#2717) 2022-06-22 05:36:20 +02:00
Friedel Ziegelmayer
cb3784a8b3
misc/metrics: Use correct event name for dcutr metrics (#2714) 2022-06-21 07:04:18 +02:00
Thomas Eizinger
ea487aebfe
muxers/mplex: Implement AsyncRead and AsyncWrite for Substream (#2706)
This aligns the public API of the `libp2p-mplex` module with the one
from `libp2p-yamux`. This change has two benefits:

1. For standalone users of `libp2p-mplex`, the substreams itself are
now useful, similar to `libp2p-yamux` and don't necessarily need to
be polled via the `StreamMuxer`. The `StreamMuxer` only forwards to
the `Async{Read,Write}` implementations.

2. This will reduce the diff of #2648 because we can chunk the one
giant commit into smaller atomic ones.
2022-06-20 05:33:59 +02:00
Thomas Eizinger
3c120ef971
core/muxing: Introduce StreamMuxerEvent::map_inbound_stream (#2691)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-06-16 05:33:32 +10:00
Thomas Eizinger
04f31cd501
core/muxing: Introduce boxed module (#2703)
This is analogous to other sub-modules like `transport` within
`libp2p-core` and thus contributes to consistency within the code
base.
2022-06-15 17:25:31 +02:00
Akihito Nakano
c7c21b1023
protocols/gossipsub: Fix duplicate connection id (#2702) 2022-06-14 16:31:27 +02:00
Chad Nehemiah
2fd4998928
Cargo.toml: Use Rust 1.60.0 and weak dependency for feats (#2646) 2022-06-10 18:36:29 +02:00
Max Inden
802d00e645
*: Prepare v0.45.1 (#2700) 2022-06-09 15:26:56 +02:00
Max Inden
5cb4886ab2
protocols/kad: Limit # of inbound substreams to 32 (#2699)
* protocols/kad/: Split into outbound and inbound substreams

* protocols/kad: Limit # of inbound substreams to 32

A remote node may still send more than 32 requests in parallel by using more
than one connection or by sending more than one request per stream.

* protocols/kad: Favor new substreams over old ones waiting for reuse

When a new inbound substream comes in and the limit of total inbound substreams
is hit, try to find an old inbound substream waiting to be reused. In such case,
replace the old with the new. In case no such old substream exists, drop the new
one.
2022-06-09 15:12:03 +02:00
Max Inden
0d3787ed04
protocols/relay: Limit inbound streams (#2698)
* protocols/relay: Use prost-codec

* protocols/relay: Respond to at most one incoming reservation request

Also changes poll order prioritizing

- Error handling over everything.
- Queued events over existing circuits.
- Existing circuits over accepting new circuits.
- Reservation management of existing reservation over new reservation
  requests.

* protocols/relay: Deny <= 8 incoming circuit requests with one per peer

* protocols/relay: Deny new circuits before accepting new circuits
2022-06-08 17:33:24 +02:00
Thomas Eizinger
0bce7f7fff
*: Remove warnings when compiling without default features (#2692)
* Remove unused import in rendezvous tests

* Expand uds-transport conditionals to include features

In case neither the tokio nor the async-std feature is defined,
this file needs to be empty to avoid unused code warnings.

Co-authored-by: Max Inden <mail@max-inden.de>
2022-06-08 13:05:11 +02:00
Max Inden
2acbb457cd
swarm/: Limit negotiating inbound substreams per connection (#2697)
This limit is shared across all `ConnectionHandler`s on a single connection. It
only enforces a limit on the number of negotiating substreams. Once negotiated a
`ConnectionHandler` manages the lifecycle of the substream and has to enforce
limits themselves.
2022-06-08 11:48:46 +02:00
Max Inden
59a74b4083
protocols/dcutr: Upgrade at most one inbound connect request (#2695)
Sending two concurrent connect requests is nonsensical. In the case where a
remote sends two, the earlier is dropped in favor of the latter.
2022-06-07 14:52:35 +02:00
Max Inden
676a630875
protocols/identify: Allow at most one inbound identify push stream (#2694)
An identify push contains the whole identify information of a remote
peer. Upgrading multiple inbound identify push streams is useless.
Instead older streams are dropped in favor of newer streams.
2022-06-07 13:42:34 +02:00
Thomas Eizinger
fcc987e0f6
muxers/mplex/benches: Use combinators to reduce nesting (#2688) 2022-06-03 17:38:02 +02:00
Thomas Eizinger
bd9834aab4
core/either: Use io::Result type alias instead of renaming io::Error (#2687) 2022-06-03 17:22:01 +02:00
Thomas Eizinger
c36a749478
muxers/yamux: Use existing Poll import (#2685) 2022-06-03 16:27:13 +02:00
Thomas Eizinger
3611d69e09
muxers/yamux: Refactor Yamux::close to use ? (#2677) 2022-05-31 15:24:03 +02:00
Max Inden
6e1e314872
*: Prepare v0.45.0 (#2662) 2022-05-31 13:12:53 +02:00
Max Inden
6078fc619f
transports/{tcp,dns,websocket}: Remove Clone imp for *Config (#2682)
This commit removes the `Clone` implementation on `GenTcpConfig` and consequently the `Clone`
implementations on `GenDnsConfig` and `WsConfig`.

When port-reuse is enabled, `GenTcpConfig` tracks the addresses it is listening in a `HashSet`. This
`HashSet` is shared with the `TcpListenStream`s via an `Arc<Mutex<_>>`. Given that `Clone` is
`derive`d on `GenTcpConfig`, cloning a `GenTcpConfig`, results in both instances sharing the same
set of listen addresses. This is not intuitive.

This behavior is for example error prone in the scenario where one wants to speak both plain DNS/TCP and
Websockets. Say a user creates the transport in the following way:

``` Rust
let transport = {
    let tcp = tcp::TcpConfig::new().nodelay(true).port_reuse(true);
    let dns_tcp = dns::DnsConfig::system(tcp).await?;
    let ws_dns_tcp = websocket::WsConfig::new(dns_tcp.clone());
    dns_tcp.or_transport(ws_dns_tcp)
};
```

Both `dns_tcp` and `ws_dns_tcp` share the set of listen addresses, given the `dns_tcp.clone()` to
create the `ws_dns_tcp`. Thus, with port-reuse, a Websocket dial might reuse a DNS/TCP listening
port instead of a Websocket listening port.

With this commit a user is forced to do the below, preventing the above error:

``` Rust
let transport = {
    let dns_tcp = dns::DnsConfig::system(tcp::TcpConfig::new().nodelay(true).port_reuse(true)).await?;
    let ws_dns_tcp = websocket::WsConfig::new(
        dns::DnsConfig::system(tcp::TcpConfig::new().nodelay(true).port_reuse(true)).await?,
    );
    dns_tcp.or_transport(ws_dns_tcp)
};
```

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2022-05-31 12:29:43 +02:00
pj50
280475645c
transports/tcp: Fix port reuse using Arc<RwLock> for listen_addrs (#2670)
Fix bug introduced in 2ad905f35a.

Make sure set of listen addresses is shared between GenTcpConfig and TcpListenStream.
2022-05-30 16:53:52 +02:00
Thomas Eizinger
4aa84bf7cd
core/transport: Remove Sync bounds (#2667)
With `Transport` becoming non-Clone and having `&mut` self receivers,
the `Sync` requirement no longer makes any sense and we can thus
remove it.
2022-05-29 20:42:48 +02:00
Thomas Eizinger
eba763443a
protocols/rendezvous: Remove unnecessary mapping to StreamMuxerBox (#2668)
Calling `.boxed()` will already map the muxer in a `StreamMuxer` box.
This mapping is therefore unnecessary.
2022-05-29 17:34:26 +02:00