2062 Commits

Author SHA1 Message Date
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
Thomas Eizinger
2b79f113bb
core/muxing: Remove the StreamMuxer::flush_all function (#2669)
`libp2p-core` provides the `StreamMuxer` abstraction so it can provide
functionality that abstracts over this trait.

We never use the `flush_all` function as part of our abstractions.
No one else is going to use it so we can remove it from the abstraction.
2022-05-29 17:23:13 +02:00
Thomas Eizinger
25c8bc24de
core/muxing: Rename close to poll_close (#2666)
It is common practise to prefix functions that return a `Poll` with
`poll_`.
2022-05-29 16:27:40 +02:00
Thomas Eizinger
8361fabb47
core/src/muxing: Remove deprecated function (#2665) 2022-05-23 16:56:59 +02:00
Elena Frank
ef2afcd41e
protocols/autonat: optionally use only global IPs (#2618)
Optionally only perform dial-backs on peers that are observed at a global ip-address.
This is relevant when multiple peers are in the same local network, in which case a peer could incorrectly assume themself to be public because a peer in the same local network was able to dial them. Thus servers should reject dial-back requests from clients with a non-global IP address, and at the same time clients should only pick connected peers as servers if they are global.
Behind a config flag (enabled by default) to also allow use-cases where AutoNAT is needed within a private network.
2022-05-22 22:04:05 +02:00
Elena Frank
48598fc1da
protocols/autonat: Fix flaky test (#2660)
Handle in test that a `OutboundProbeEvent::Response` can be reported
before the associated inbound connection event.
In rare cases (that only really happen in a test setup where both peers
run on the same device) the server may observe a connection and report
the response back to the client, before the connection event was
reported at the client.
2022-05-22 21:07:55 +02:00
Max Inden
1d6b08b0b6
protocols/dcutr/examples: Wait to tell relay its public addr (#2659)
As a listening client, when requesting a reservation with a relay, the relay
responds with its public addresses. The listening client can then use the public
addresses of the relay to advertise itself as reachable under a relayed
address (`/<public-relay-addr>/p2p-circuit/p2p/<listening-client-peer-id>`).

The above operates under the assumption that the relay knows its public address.
A relay learns its public address from remote peers, via the identify protocol.
In the case where the relay just started up, the listening client might be the
very first node to connect to it.

Such scenario allows for a race condition. The listening client requests a
reservation from the relay, while the relay requests its public address from the
listening client. The former needs to contain the response from the latter.

This commit serializes the two requests, making sure, in the case of a freshly
started relay, that the listening client tells the relay its public address
before requesting a reservation from the relay.

Co-authored-by: Elena Frank <elena.frank@protonmail.com>
2022-05-20 21:59:32 +02:00
Max Inden
686d6ff363
misc/metrics/README: Reference sample Grafana dashboard (#2655) 2022-05-20 09:27:03 +02:00
dependabot[bot]
8c343a911f
build(deps): Update pin-project requirement from 0.4.6 to 1.0.10 (#2654)
Updates the requirements on [pin-project](https://github.com/taiki-e/pin-project) to permit the latest version.
- [Release notes](https://github.com/taiki-e/pin-project/releases)
- [Changelog](https://github.com/taiki-e/pin-project/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/pin-project/commits/v1.0.10)

---
updated-dependencies:
- dependency-name: pin-project
  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-05-20 09:09:02 +02:00
Max Inden
0e9ab1c960
protocols/dcutr/example: Wait for relay to accept reservation request (#2642)
When in listening mode, wait for the relay to accept our reservation
request. Only then can a client in dialing mode establish a relayed
connection to us via the relay.

See also
https://github.com/libp2p/rust-libp2p/issues/2621#issuecomment-1123549348
2022-05-19 20:08:32 +02:00
Friedel Ziegelmayer
d4c1292d42
transports/dns: Remove Clone trait bound (#2658) 2022-05-19 21:00:46 +10:00
Max Inden
999a212664
README.md: Add elenaf9 to Maintainers (#2656) 2022-05-18 12:13:22 +02:00
Max Inden
9a5fec874d
swarm/src/connection: Prioritize handler over negotiating streams (#2638)
The `HandlerWrapper` polls three components:

1. `ConnectionHandler`
2. Outbound negotiating streams
3. Inbound negotiating streams

The `ConnectionHandler` itself might itself poll already negotiated streams.

By polling the three components above in the listed order one:

- Prioritizes local work and work coming from negotiated streams over
  negotiating streams.
- Prioritizes outbound negotiating streams over inbound negotiating
  streams, i.e. outbound requests over inbound requests.
2022-05-18 11:05:08 +02:00
Chad Nehemiah
d97893d293
swarm(-derive)/: Rename references of protocol handler to connection handler (#2640) 2022-05-18 09:52:50 +02:00
Max Inden
d21cd5fed7
misc/: Move rw-stream-sink into rust-libp2p monorepo (#2641)
* misc/rw-stream-sink: Initial commit

See
62a923cc27

* misc/rw-stream-sink: Update to Rust edition 2021

* misc/rw-stream-sink: Add changelog
2022-05-16 19:17:49 +02:00
hrxi
efe9c07b34
protocols/kad: Update arrayvec dependency to latest version 0.7.2 (#2644) 2022-05-16 18:52:19 +02:00
hrxi
d69681b27c
Drop atomic dependency (#2643)
Replace `atomic::Atomic<u64>` by `std::sync::atomic:AtomicU64`.

The original motivation of using `atomic::Atomic<u64>` instead of
`std`'s version in #1670 was the following:

> I used the atomic crate and an Atomic<u64> because the AtomicU64 type
> isn't available on all architectures. The atomic crate automatically
> falls back to using a Mutex on platforms that don't support AtomicU64.

This argumentation is moot because the crate directly depends on
`libp2p-core` which also uses `AtomicU64`.
2022-05-12 14:05:33 +10:00
Elena Frank
f04f6bb4fc
identify/handler: Improve property name (#2639) 2022-05-11 11:18:20 +10:00
Carson Farmer
5cf68902ce
swarm/: Remove redundant doc strings on behaviour trait (#2634)
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
2022-05-09 17:53:01 +02:00
dependabot[bot]
93fa86c263
build(deps): Update prometheus-client requirement from 0.15.0 to 0.16.0 (#2631)
* build(deps): Update prometheus-client requirement from 0.15.0 to 0.16.0

Updates the requirements on [prometheus-client](https://github.com/prometheus/client_rust) to permit the latest version.
- [Release notes](https://github.com/prometheus/client_rust/releases)
- [Changelog](https://github.com/prometheus/client_rust/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_rust/compare/v0.15.0...v0.16.0)

---
updated-dependencies:
- dependency-name: prometheus-client
  dependency-type: direct:production
...

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

* *: Update changelogs

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-05-06 14:57:40 +02:00
Elena Frank
9c7861f8ed
.github/: Fix config.yml file name & add note for logger (#2633) 2022-05-06 10:36:34 +02:00
Max Inden
afc5b8d8cd
swarm/src/lib: Prioritize Behaviour over Pool and Pool over Listeners (#2627)
Have the main event loop (`Swarm::poll_next_event`) prioritize:

1. Work on `NetworkBehaviour` over work on `Pool`, thus prioritizing
   local work over work coming from a remote.

2. Work on `Pool` over work on `ListenersStream`, thus prioritizing work
   on existing connections over upgrading new incoming connections.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2022-05-05 20:15:24 +02:00
Max Inden
bbd2f8f009
misc/prost-codec: Introduce codec for varint prefixed Protobuf messages (#2630)
Extracts the Protobuf en-/decoding pattern into its separate crate
and applies it to `libp2p-identify`.
2022-05-05 18:28:47 +02:00
Max Inden
3cfbf89a3a
swarm/src/connection/pool: Remove 'a lifetime in PoolEvent (#2625)
Simplifies `PoolEvent`, no longer carrying a reference to an
`EstablishedConnection` or the `Pool`, but instead the `PeerId`,
`ConnectionId` and `ConnectedPoint` directly.

Co-authored-by: Elena Frank <elena.frank@protonmail.com>
2022-05-04 10:33:40 +02:00
Max Inden
3e1ed95cf6
swarm/src/connection: Prioritize handler over connection (#2626)
Prioritize work in handler over work on connection, thus prioritizing local work
over work coming from a remote.
2022-05-03 22:26:28 +02:00
Hubert
70d38520fd
*: Activate clippy::style lint group (#2620) 2022-05-03 13:11:48 +02:00
Chiu-Hsiang Hsu
f46fecd4d7
src/tutorials/ping: Fix typo in multiaddress (#2623) 2022-04-27 08:48:22 +02:00
Hubert
22fbce34d5
*: Fix clippy warnings (#2615) 2022-04-19 12:13:45 +02:00
Wink Saville
0c1ac781a2
src/tutorials/hole-punching: Clarify use of libp2p-lookup & server IP (#2616) 2022-04-18 14:41:25 +02:00
Janmajayamall
c427bb3958
protocols/kad: Implement Error for GetRecordError (#2614) 2022-04-17 10:16:32 +02:00
dependabot[bot]
7ce9fb4fb1
build(deps): Bump Swatinem/rust-cache from 1.3.0 to 1.4.0 (#2613)
* build(deps): Bump Swatinem/rust-cache from 1.3.0 to 1.4.0

Bumps [Swatinem/rust-cache](https://github.com/Swatinem/rust-cache) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/Swatinem/rust-cache/releases)
- [Changelog](https://github.com/Swatinem/rust-cache/blob/v1/CHANGELOG.md)
- [Commits](842ef286ff...cb2cf0cc7c)

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

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

* Apply suggestions from code review

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-04-17 09:58:51 +02:00
Elena Frank
093863870b
.github/: Add templates for Issues and PRs (#2611) 2022-04-16 16:50:27 +02:00
Divma
a1f3547b43
protocols/gossipsub: Allow score buckets to be set (#2595)
Moves the score buckets to the metrics configuration, setting the same defaults
as what we had but also allowing the user to pass a reference to the score
thresholds to create them from that. Having them in the config also allows users
to set them directly.
2022-04-08 21:32:27 +02:00
Elena Frank
102509afe3
swarm/behaviour: make either mod private (#2610)
With no public items, having this module public serves no purpose.
2022-04-08 09:06:06 +10:00
Elvis
f5b982a13b
protocols/ping: Log remote PeerId instead of payload (#2608) 2022-04-07 21:37:02 +02:00
Max Inden
2ad905f35a
{core,swarm}/: Don't require Transport: Clone and take &mut (#2529)
Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods
on `Transport`, e.g. `Transport::dial` would take ownership, requiring
e.g. a `Clone::clone` before calling `Transport::dial`.

The requirement of `Transport` to be `Clone` is no longer needed in
`libp2p-swarm`. E.g.  concurrent dialing can be done without a clone per
dial.

This commit removes the requirement of `Clone` for `Transport` in
`libp2p-swarm`. As a follow-up methods on `Transport` no longer take
ownership, but instead a mutable reference (`&mut self`).

On the one hand this simplifies `libp2p-swarm`, on the other it
simplifies implementations of `Transport`.
2022-04-06 20:23:16 +02:00
dependabot[bot]
7a1147877a
build(deps): Update prost-build requirement from 0.9 to 0.10 (#2596)
* build(deps): Update prost-build requirement from 0.9 to 0.10

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/commits)

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

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

* .github/workflow: Don't run integration test in container

* .github/workflow: Don't run doc step in container

* .github/workflows: Remove component docs

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-04-06 15:54:42 +02:00
TotalKrill
90140a6eaf
*: Change structopt to native clap derive implementations (#2600)
Co-authored-by: Max Inden <mail@max-inden.de>
2022-04-05 21:56:44 +02:00
dependabot[bot]
680604f3d3
build(deps): Update prost requirement from 0.9 to 0.10 (#2597)
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/commits)

---
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>
Co-authored-by: Max Inden <mail@max-inden.de>
2022-04-05 21:35:54 +02:00
Max Inden
f26adbcd84
*: Prepare libp2p v0.44.0 (#2604) 2022-04-04 18:27:41 +02:00
Max Inden
4d796fdca1
protocols/{dcutr,relay}: Expose error types (#2605)
Co-authored-by: canewsin <canews.in@gmail.com>
2022-04-04 11:32:54 +02:00
Max Inden
6cc3b4ec52
*: Import libp2p with default-features = false (#2574)
* *: Import `libp2p` with `default-features = false`

While not a win in most cases, it reduces compile time for tests of
individual crates.

* Cargo.toml: Set features for examples
2022-03-22 11:22:17 +01:00
Yoshiera
3abef2e70c
examples/file-sharing: Exclude two swarm events from panic (#2580) 2022-03-22 10:59:05 +01:00