Skip to content

Commit 9135be2

Browse files
authored
Merge branch 'master' into chore-fix-libp2p-tutorial-ping-timeout
2 parents 1653e65 + 8c8b3c3 commit 9135be2

15 files changed

+55
-21
lines changed

Cargo.lock

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

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ libp2p-identity = { version = "0.2.10" }
8686
libp2p-kad = { version = "0.47.0", path = "protocols/kad" }
8787
libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" }
8888
libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" }
89-
libp2p-metrics = { version = "0.16.0", path = "misc/metrics" }
89+
libp2p-metrics = { version = "0.16.1", path = "misc/metrics" }
9090
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }
9191
libp2p-noise = { version = "0.46.0", path = "transports/noise" }
9292
libp2p-perf = { version = "0.4.0", path = "protocols/perf" }
9393
libp2p-ping = { version = "0.46.0", path = "protocols/ping" }
9494
libp2p-plaintext = { version = "0.43.0", path = "transports/plaintext" }
9595
libp2p-pnet = { version = "0.26.0", path = "transports/pnet" }
9696
libp2p-quic = { version = "0.12.0", path = "transports/quic" }
97-
libp2p-relay = { version = "0.19.1", path = "protocols/relay" }
97+
libp2p-relay = { version = "0.20.0", path = "protocols/relay" }
9898
libp2p-rendezvous = { version = "0.16.0", path = "protocols/rendezvous" }
9999
libp2p-request-response = { version = "0.28.1", path = "protocols/request-response" }
100100
libp2p-server = { version = "0.12.6", path = "misc/server" }

libp2p/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
- Introduce `libp2p-webrtc-websys` behind `webrtc-websys` feature flag.
33
See [PR 5819](https://github.com/libp2p/rust-libp2p/pull/5819).
44

5+
- Make the `*-websys` variants (`libp2p-webrtc-websys`, `libp2p-websocket-websys`, `libp2p-webtransport-websys`) only available on wasm32 target architecture.
6+
See [PR 5891](https://github.com/libp2p/rust-libp2p/pull/5891).
7+
58
## 0.55.0
69

710
- Raise MSRV to 1.83.0.

libp2p/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` featu
9999
getrandom = { workspace = true } # Explicit dependency to be used in `wasm-bindgen` feature
100100
# TODO feature flag?
101101
rw-stream-sink = { workspace = true }
102-
103102
libp2p-allow-block-list = { workspace = true }
104103
libp2p-autonat = { workspace = true, optional = true }
105104
libp2p-connection-limits = { workspace = true }
@@ -119,14 +118,16 @@ libp2p-relay = { workspace = true, optional = true }
119118
libp2p-rendezvous = { workspace = true, optional = true }
120119
libp2p-request-response = { workspace = true, optional = true }
121120
libp2p-swarm = { workspace = true }
122-
libp2p-webrtc-websys = { workspace = true, optional = true }
123-
libp2p-websocket-websys = { workspace = true, optional = true }
124-
libp2p-webtransport-websys = { workspace = true, optional = true }
125121
libp2p-yamux = { workspace = true, optional = true }
126122
multiaddr = { workspace = true }
127123
pin-project = "1.0.0"
128124
thiserror = { workspace = true }
129125

126+
[target.'cfg(target_arch = "wasm32")'.dependencies]
127+
libp2p-webrtc-websys = { workspace = true, optional = true }
128+
libp2p-websocket-websys = { workspace = true, optional = true }
129+
libp2p-webtransport-websys = { workspace = true, optional = true }
130+
130131
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
131132
libp2p-dns = { workspace = true, optional = true }
132133
libp2p-mdns = { workspace = true, optional = true }

libp2p/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ pub use libp2p_uds as uds;
123123
#[cfg(not(target_arch = "wasm32"))]
124124
#[doc(inline)]
125125
pub use libp2p_upnp as upnp;
126-
#[cfg(feature = "webrtc-websys")]
126+
#[cfg(all(feature = "webrtc-websys", target_arch = "wasm32"))]
127127
#[doc(inline)]
128128
pub use libp2p_webrtc_websys as webrtc_websys;
129129
#[cfg(feature = "websocket")]
130130
#[cfg(not(target_arch = "wasm32"))]
131131
#[doc(inline)]
132132
pub use libp2p_websocket as websocket;
133-
#[cfg(feature = "websocket-websys")]
133+
#[cfg(all(feature = "websocket-websys", target_arch = "wasm32"))]
134134
#[doc(inline)]
135135
pub use libp2p_websocket_websys as websocket_websys;
136-
#[cfg(feature = "webtransport-websys")]
136+
#[cfg(all(feature = "webtransport-websys", target_arch = "wasm32"))]
137137
#[cfg_attr(docsrs, doc(cfg(feature = "webtransport-websys")))]
138138
#[doc(inline)]
139139
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

0 commit comments

Comments
 (0)