Skip to content

Commit 04014ec

Browse files
authored
Merge branch 'master' into peer-store
2 parents e6f3d46 + 8c8b3c3 commit 04014ec

23 files changed

+138
-154
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ libp2p-identity = { version = "0.2.10" }
8787
libp2p-kad = { version = "0.47.0", path = "protocols/kad" }
8888
libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" }
8989
libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" }
90-
libp2p-metrics = { version = "0.16.0", path = "misc/metrics" }
90+
libp2p-metrics = { version = "0.16.1", path = "misc/metrics" }
9191
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }
9292
libp2p-noise = { version = "0.46.0", path = "transports/noise" }
9393
libp2p-peer-store = { version = "0.1.0", path = "misc/peer-store" }
@@ -96,12 +96,12 @@ libp2p-ping = { version = "0.46.0", path = "protocols/ping" }
9696
libp2p-plaintext = { version = "0.43.0", path = "transports/plaintext" }
9797
libp2p-pnet = { version = "0.26.0", path = "transports/pnet" }
9898
libp2p-quic = { version = "0.12.0", path = "transports/quic" }
99-
libp2p-relay = { version = "0.19.1", path = "protocols/relay" }
99+
libp2p-relay = { version = "0.20.0", path = "protocols/relay" }
100100
libp2p-rendezvous = { version = "0.16.0", path = "protocols/rendezvous" }
101101
libp2p-request-response = { version = "0.28.1", path = "protocols/request-response" }
102102
libp2p-server = { version = "0.12.6", path = "misc/server" }
103103
libp2p-stream = { version = "0.3.0-alpha", path = "protocols/stream" }
104-
libp2p-swarm = { version = "0.46.1", path = "swarm" }
104+
libp2p-swarm = { version = "0.47.0", path = "swarm" }
105105
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
106106
libp2p-swarm-test = { version = "0.5.0", path = "swarm-test" }
107107
libp2p-tcp = { version = "0.43.0", path = "transports/tcp" }

ROADMAP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Below is a high level roadmap for the rust-libp2p project.
44
Items are ordered by priority (high to low).
55

6-
This is a living document.
6+
This is a living document. We believe the roadmap should be shaped by the needs of our user community. Many of the items below are contributions made by downstream users.
77
Input is always welcome e.g. via GitHub issues or pull requests.
88

99
This is the roadmap of the Rust implementation of libp2p.

libp2p/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- Introduce `libp2p-peer-store`.
66
See [PR 5724](https://github.com/libp2p/rust-libp2p/pull/5724).
77

8+
- Make the `*-websys` variants (`libp2p-webrtc-websys`, `libp2p-websocket-websys`, `libp2p-webtransport-websys`) only available on wasm32 target architecture.
9+
See [PR 5891](https://github.com/libp2p/rust-libp2p/pull/5891).
10+
811
## 0.55.0
912

1013
- Raise MSRV to 1.83.0.

libp2p/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` featu
101101
getrandom = { workspace = true } # Explicit dependency to be used in `wasm-bindgen` feature
102102
# TODO feature flag?
103103
rw-stream-sink = { workspace = true }
104-
105104
libp2p-allow-block-list = { workspace = true }
106105
libp2p-autonat = { workspace = true, optional = true }
107106
libp2p-connection-limits = { workspace = true }
@@ -122,14 +121,16 @@ libp2p-relay = { workspace = true, optional = true }
122121
libp2p-rendezvous = { workspace = true, optional = true }
123122
libp2p-request-response = { workspace = true, optional = true }
124123
libp2p-swarm = { workspace = true }
125-
libp2p-webrtc-websys = { workspace = true, optional = true }
126-
libp2p-websocket-websys = { workspace = true, optional = true }
127-
libp2p-webtransport-websys = { workspace = true, optional = true }
128124
libp2p-yamux = { workspace = true, optional = true }
129125
multiaddr = { workspace = true }
130126
pin-project = "1.0.0"
131127
thiserror = { workspace = true }
132128

129+
[target.'cfg(target_arch = "wasm32")'.dependencies]
130+
libp2p-webrtc-websys = { workspace = true, optional = true }
131+
libp2p-websocket-websys = { workspace = true, optional = true }
132+
libp2p-webtransport-websys = { workspace = true, optional = true }
133+
133134
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
134135
libp2p-dns = { workspace = true, optional = true }
135136
libp2p-mdns = { workspace = true, optional = true }

libp2p/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ pub use libp2p_uds as uds;
126126
#[cfg(not(target_arch = "wasm32"))]
127127
#[doc(inline)]
128128
pub use libp2p_upnp as upnp;
129-
#[cfg(feature = "webrtc-websys")]
129+
#[cfg(all(feature = "webrtc-websys", target_arch = "wasm32"))]
130130
#[doc(inline)]
131131
pub use libp2p_webrtc_websys as webrtc_websys;
132132
#[cfg(feature = "websocket")]
133133
#[cfg(not(target_arch = "wasm32"))]
134134
#[doc(inline)]
135135
pub use libp2p_websocket as websocket;
136-
#[cfg(feature = "websocket-websys")]
136+
#[cfg(all(feature = "websocket-websys", target_arch = "wasm32"))]
137137
#[doc(inline)]
138138
pub use libp2p_websocket_websys as websocket_websys;
139-
#[cfg(feature = "webtransport-websys")]
139+
#[cfg(all(feature = "webtransport-websys", target_arch = "wasm32"))]
140140
#[cfg_attr(docsrs, doc(cfg(feature = "webtransport-websys")))]
141141
#[doc(inline)]
142142
pub use libp2p_webtransport_websys as webtransport_websys;

misc/metrics/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.16.1
2+
- Add `ReservationClosed` as a relay metric.
3+
See [PR 5869](https://github.com/libp2p/rust-libp2p/pull/5869).
4+
15
## 0.16.0
26

37
<!-- Update to libp2p-core v0.43.0 -->

misc/metrics/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-metrics"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "Metrics for libp2p"
6-
version = "0.16.0"
6+
version = "0.16.1"
77
authors = ["Max Inden <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

misc/metrics/src/relay.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum EventType {
5454
ReservationReqAcceptFailed,
5555
ReservationReqDenied,
5656
ReservationReqDenyFailed,
57+
ReservationClosed,
5758
ReservationTimedOut,
5859
CircuitReqDenied,
5960
CircuitReqDenyFailed,
@@ -76,6 +77,7 @@ impl From<&libp2p_relay::Event> for EventType {
7677
libp2p_relay::Event::ReservationReqDenyFailed { .. } => {
7778
EventType::ReservationReqDenyFailed
7879
}
80+
libp2p_relay::Event::ReservationClosed { .. } => EventType::ReservationClosed,
7981
libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut,
8082
libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
8183
#[allow(deprecated)]

protocols/gossipsub/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## 0.48.1
2+
- Allow whitelisting topics for metrics to ensure metrics are recorded correctly for these topics.
3+
See [PR 5895](https://github.com/libp2p/rust-libp2p/pull/5895)
4+
25
- Improve `max_messages_per_rpc` consistency by ensuring RPC control messages also adhere to the existing limits.
36
See [PR 5826](https://github.com/libp2p/rust-libp2p/pull/5826)
47

protocols/gossipsub/src/behaviour.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,13 @@ where
30533053
}
30543054
}
30553055
}
3056+
3057+
/// Register topics to ensure metrics are recorded correctly for these topics.
3058+
pub fn register_topics_for_metrics(&mut self, topics: Vec<TopicHash>) {
3059+
if let Some(metrics) = &mut self.metrics {
3060+
metrics.register_allowed_topics(topics);
3061+
}
3062+
}
30563063
}
30573064

30583065
fn get_ip_addr(addr: &Multiaddr) -> Option<IpAddr> {

protocols/gossipsub/src/metrics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,13 @@ impl Metrics {
648648
metric.set(metric.get() - 1);
649649
}
650650
}
651+
652+
/// Registers a set of topics that we want to store calculate metrics for.
653+
pub(crate) fn register_allowed_topics(&mut self, topics: Vec<TopicHash>) {
654+
for topic_hash in topics {
655+
self.topic_info.insert(topic_hash, true);
656+
}
657+
}
651658
}
652659

653660
/// Reasons why a peer was included in the mesh.

protocols/relay/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
## 0.19.1
1+
## 0.20.0
22

33
- Remove duplicated forwarding of pending events to connection handler.
4+
- Emit `relay::Event::ReservationClosed` when an active reservation is dropped due to the connection closing.
5+
See [PR 5869](https://github.com/libp2p/rust-libp2p/pull/5869).
46

57
## 0.19.0
68

protocols/relay/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-relay"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "Communications relaying for libp2p"
6-
version = "0.19.1"
6+
version = "0.20.0"
77
authors = ["Parity Technologies <[email protected]>", "Max Inden <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

protocols/relay/src/behaviour.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ pub enum Event {
193193
src_peer_id: PeerId,
194194
error: inbound_hop::Error,
195195
},
196+
/// A reservation has been closed.
197+
ReservationClosed { src_peer_id: PeerId },
196198
/// An inbound reservation has timed out.
197199
ReservationTimedOut { src_peer_id: PeerId },
198200
/// An inbound circuit request has been denied.
@@ -277,7 +279,12 @@ impl Behaviour {
277279
}: ConnectionClosed,
278280
) {
279281
if let hash_map::Entry::Occupied(mut peer) = self.reservations.entry(peer_id) {
280-
peer.get_mut().remove(&connection_id);
282+
if peer.get_mut().remove(&connection_id) {
283+
self.queued_actions
284+
.push_back(ToSwarm::GenerateEvent(Event::ReservationClosed {
285+
src_peer_id: peer_id,
286+
}));
287+
}
281288
if peer.get().is_empty() {
282289
peer.remove();
283290
}

protocols/upnp/src/behaviour.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,10 @@ impl NetworkBehaviour for Behaviour {
264264
listener_id,
265265
addr: multiaddr,
266266
}) => {
267-
let (addr, protocol) = match multiaddr_to_socketaddr_protocol(multiaddr.clone()) {
268-
Ok(addr_port) => addr_port,
269-
Err(()) => {
270-
tracing::debug!("multiaddress not supported for UPnP {multiaddr}");
271-
return;
272-
}
267+
let Ok((addr, protocol)) = multiaddr_to_socketaddr_protocol(multiaddr.clone())
268+
else {
269+
tracing::debug!("multiaddress not supported for UPnP {multiaddr}");
270+
return;
273271
};
274272

275273
if let Some((mapping, _state)) = self

scripts/ensure-version-bump-and-changelog.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MERGE_BASE=$(git merge-base "$HEAD_SHA" "$PR_BASE") # Find the merge base. This
1010
SRC_DIFF_TO_BASE=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE/src" "$DIR_TO_CRATE/Cargo.toml")
1111
CHANGELOG_DIFF=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-only -- "$DIR_TO_CRATE/CHANGELOG.md")
1212

13-
RELEASED_VERSION=$(git tag --sort=version:refname | grep "^$CRATE-v" | tail -n1 | grep -Po "\d+\.\d+\.\d+")
13+
RELEASED_VERSION=$(git tag --sort=version:refname | grep "^$CRATE-v" | tail -n1 | grep -Po "\d+\.\d+\.\d+(-.+)?")
1414

1515

1616
# If the source files of this crate weren't touched in this PR, exit early.

swarm/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## 0.46.1
1+
## 0.47.0
2+
- Separate the `PendingConnectionError` into two parts `PendingOutboundConnectionError` and `PendingInboundConnectionError` to have better control over error handling. See [PR](https://github.com/libp2p/rust-libp2p/pull/5861)
3+
24
- Undo `ConnectionHandler::{InboundOpenInfo, OutboundOpenInfo}` deprecation.
35
Substreams are not completely interchangeable and a certain Substream may be associated with a
46
certain upgrade.

swarm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-swarm"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "The libp2p swarm"
6-
version = "0.46.1"
6+
version = "0.47.0"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

swarm/src/connection.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ use std::{
3636
};
3737

3838
pub use error::ConnectionError;
39-
pub(crate) use error::{
40-
PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError,
41-
};
39+
pub(crate) use error::{PendingInboundConnectionError, PendingOutboundConnectionError};
4240
use futures::{future::BoxFuture, stream, stream::FuturesUnordered, FutureExt, StreamExt};
4341
use futures_timer::Delay;
4442
use libp2p_core::{

swarm/src/connection/error.rs

+14-63
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use std::{fmt, io};
2222

23-
use crate::{transport::TransportError, ConnectedPoint, Multiaddr, PeerId};
23+
use crate::{transport::TransportError, Multiaddr, PeerId};
2424

2525
/// Errors that can occur in the context of an established `Connection`.
2626
#[derive(Debug)]
@@ -64,17 +64,10 @@ impl From<io::Error> for ConnectionError {
6464
/// Note: Addresses for an outbound connection are dialed in parallel. Thus, compared to
6565
/// [`PendingInboundConnectionError`], one or more [`TransportError`]s can occur for a single
6666
/// connection.
67-
pub(crate) type PendingOutboundConnectionError =
68-
PendingConnectionError<Vec<(Multiaddr, TransportError<io::Error>)>>;
69-
70-
/// Errors that can occur in the context of a pending incoming `Connection`.
71-
pub(crate) type PendingInboundConnectionError = PendingConnectionError<TransportError<io::Error>>;
72-
73-
/// Errors that can occur in the context of a pending `Connection`.
7467
#[derive(Debug)]
75-
pub enum PendingConnectionError<TTransErr> {
68+
pub(crate) enum PendingOutboundConnectionError {
7669
/// An error occurred while negotiating the transport protocol(s) on a connection.
77-
Transport(TTransErr),
70+
Transport(Vec<(Multiaddr, TransportError<io::Error>)>),
7871

7972
/// Pending connection attempt has been aborted.
8073
Aborted,
@@ -83,64 +76,22 @@ pub enum PendingConnectionError<TTransErr> {
8376
/// match the one that was expected.
8477
WrongPeerId {
8578
obtained: PeerId,
86-
endpoint: ConnectedPoint,
79+
address: Multiaddr,
8780
},
8881

8982
/// The connection was dropped because it resolved to our own [`PeerId`].
90-
LocalPeerId { endpoint: ConnectedPoint },
83+
LocalPeerId { address: Multiaddr },
9184
}
9285

93-
impl<T> PendingConnectionError<T> {
94-
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> PendingConnectionError<U> {
95-
match self {
96-
PendingConnectionError::Transport(t) => PendingConnectionError::Transport(f(t)),
97-
PendingConnectionError::Aborted => PendingConnectionError::Aborted,
98-
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
99-
PendingConnectionError::WrongPeerId { obtained, endpoint }
100-
}
101-
PendingConnectionError::LocalPeerId { endpoint } => {
102-
PendingConnectionError::LocalPeerId { endpoint }
103-
}
104-
}
105-
}
106-
}
86+
/// Errors that can occur in the context of a pending incoming `Connection`.
87+
#[derive(Debug)]
88+
pub(crate) enum PendingInboundConnectionError {
89+
/// An error occurred while negotiating the transport protocol(s) on a connection.
90+
Transport(TransportError<io::Error>),
10791

108-
impl<TTransErr> fmt::Display for PendingConnectionError<TTransErr>
109-
where
110-
TTransErr: fmt::Display + fmt::Debug,
111-
{
112-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113-
match self {
114-
PendingConnectionError::Aborted => write!(f, "Pending connection: Aborted."),
115-
PendingConnectionError::Transport(err) => {
116-
write!(
117-
f,
118-
"Pending connection: Transport error on connection: {err}"
119-
)
120-
}
121-
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
122-
write!(
123-
f,
124-
"Pending connection: Unexpected peer ID {obtained} at {endpoint:?}."
125-
)
126-
}
127-
PendingConnectionError::LocalPeerId { endpoint } => {
128-
write!(f, "Pending connection: Local peer ID at {endpoint:?}.")
129-
}
130-
}
131-
}
132-
}
92+
/// Pending connection attempt has been aborted.
93+
Aborted,
13394

134-
impl<TTransErr> std::error::Error for PendingConnectionError<TTransErr>
135-
where
136-
TTransErr: std::error::Error + 'static,
137-
{
138-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
139-
match self {
140-
PendingConnectionError::Transport(_) => None,
141-
PendingConnectionError::WrongPeerId { .. } => None,
142-
PendingConnectionError::LocalPeerId { .. } => None,
143-
PendingConnectionError::Aborted => None,
144-
}
145-
}
95+
/// The connection was dropped because it resolved to our own [`PeerId`].
96+
LocalPeerId { address: Multiaddr },
14697
}

0 commit comments

Comments
 (0)