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`.
* 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.
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.
**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`.
* 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.
* 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
* 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>
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.
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.
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.
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>
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.
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`.
* 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>