Skip to content

Commit 964636d

Browse files
committed
http and ws: fix build errors with --no-default-features
1 parent acabf15 commit 964636d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

crates/http/src/workers/swarm/storage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl TorrentMaps {
9999
}
100100
}
101101

102+
#[cfg(feature = "metrics")]
102103
pub fn update_torrent_metrics(&self) {
103104
self.ipv4.torrent_gauge.set(self.ipv4.torrents.len() as f64);
104105
self.ipv6.torrent_gauge.set(self.ipv6.torrents.len() as f64);

crates/ws/src/workers/socket/connection.rs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::workers::socket::calculate_in_message_consumer_index;
4242
use crate::workers::socket::{ip_version_to_metrics_str, WORKER_INDEX};
4343

4444
/// Optional second tuple field is for peer id hex representation
45+
#[cfg(feature = "metrics")]
4546
type PeerClientGauge = (Gauge, Option<Gauge>);
4647

4748
pub struct ConnectionRunner {
@@ -68,6 +69,7 @@ impl ConnectionRunner {
6869
let clean_up_data = ConnectionCleanupData {
6970
announced_info_hashes: Default::default(),
7071
ip_version: self.ip_version,
72+
#[cfg(feature = "metrics")]
7173
opt_peer_client: Default::default(),
7274
#[cfg(feature = "metrics")]
7375
active_connections_gauge: ::metrics::gauge!(
@@ -597,6 +599,7 @@ impl<S: futures::AsyncRead + futures::AsyncWrite + Unpin> ConnectionWriter<S> {
597599
struct ConnectionCleanupData {
598600
announced_info_hashes: Rc<RefCell<HashMap<InfoHash, PeerId>>>,
599601
ip_version: IpVersion,
602+
#[cfg(feature = "metrics")]
600603
opt_peer_client: Rc<RefCell<Option<PeerClientGauge>>>,
601604
#[cfg(feature = "metrics")]
602605
active_connections_gauge: Gauge,

crates/ws/src/workers/socket/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ async fn clean_connections(
240240
}
241241
});
242242

243-
::log::info!(
244-
"cleaned connections in worker {}, {} references remaining",
245-
WORKER_INDEX.get(),
246-
connection_slab.borrow_mut().len()
247-
);
248-
249243
#[cfg(feature = "metrics")]
250244
{
245+
::log::info!(
246+
"cleaned connections in worker {}, {} references remaining",
247+
WORKER_INDEX.get(),
248+
connection_slab.borrow_mut().len()
249+
);
250+
251251
// Increment gauges by zero to prevent them from being removed due to
252252
// idleness
253253

crates/ws/src/workers/swarm/storage.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl TorrentMap {
176176
server_start_instant,
177177
request_sender_meta,
178178
&request,
179+
#[cfg(feature = "metrics")]
179180
&self.peer_gauge,
180181
);
181182

@@ -260,7 +261,11 @@ impl TorrentMap {
260261

261262
pub fn handle_connection_closed(&mut self, info_hash: InfoHash, peer_id: PeerId) {
262263
if let Some(torrent_data) = self.torrents.get_mut(&info_hash) {
263-
torrent_data.handle_connection_closed(peer_id, &self.peer_gauge);
264+
torrent_data.handle_connection_closed(
265+
peer_id,
266+
#[cfg(feature = "metrics")]
267+
&self.peer_gauge,
268+
);
264269
}
265270
}
266271

0 commit comments

Comments
 (0)