From 5636c1ee9fc46409b45d409b9277dc4715397d2d Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 2 Jan 2023 12:00:37 +0100 Subject: [PATCH 1/3] fix: Await async_channel::Sender::send This makes sure to await the future from async_channel::Sender::send. When not awaiting this only makes a struct and noting is ever sent. Caught by clippy really. --- iroh-bitswap/src/client/peer_manager.rs | 11 ++++++++--- iroh-bitswap/src/network.rs | 14 +++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/iroh-bitswap/src/client/peer_manager.rs b/iroh-bitswap/src/client/peer_manager.rs index c143264adf..58d3d21a0e 100644 --- a/iroh-bitswap/src/client/peer_manager.rs +++ b/iroh-bitswap/src/client/peer_manager.rs @@ -1,7 +1,7 @@ use std::{fmt::Debug, sync::Arc}; use ahash::{AHashMap, AHashSet}; -use anyhow::Result; +use anyhow::{Context, Result}; use cid::Cid; use derivative::Derivative; use futures::{future::BoxFuture, FutureExt}; @@ -658,10 +658,15 @@ impl PeerManagerActor { ) { if let Some(session) = self.sessions.get(&session) { if session.peers.contains(&peer) { - self.network.protect_peer(peer).await; + self.network + .protect_peer(peer) + .await + .context("Failed to protect connection") + .map_err(|err| error!("{err:#}")) + .ok(); } } - let _ = response.send(()); + response.send(()).ok(); } async fn remove_peer_from_session( diff --git a/iroh-bitswap/src/network.rs b/iroh-bitswap/src/network.rs index 42d0e44bcb..651fcd9b89 100644 --- a/iroh-bitswap/src/network.rs +++ b/iroh-bitswap/src/network.rs @@ -297,18 +297,22 @@ impl Network { trace!("untag {}: {}", peer, tag); } - pub async fn protect_peer(&self, peer: PeerId) { + pub async fn protect_peer(&self, peer: PeerId) -> Result<()> { trace!("protect {}", peer); - let _ = self.network_out_sender.send(OutEvent::ProtectPeer { peer }); + self.network_out_sender + .send(OutEvent::ProtectPeer { peer }) + .await?; + Ok(()) } pub async fn unprotect_peer(&self, peer: PeerId) -> bool { trace!("unprotect {}", peer); let (s, r) = oneshot::channel(); - let _ = self - .network_out_sender - .send(OutEvent::UnprotectPeer { peer, response: s }); + self.network_out_sender + .send(OutEvent::UnprotectPeer { peer, response: s }) + .await + .ok(); r.await.unwrap_or_default() } From b1dc0b6f30be210d8d897f7f2d397894d36f69bf Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 2 Jan 2023 12:25:10 +0100 Subject: [PATCH 2/3] Need to log this path too --- iroh-bitswap/src/network.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iroh-bitswap/src/network.rs b/iroh-bitswap/src/network.rs index 651fcd9b89..1fc870b055 100644 --- a/iroh-bitswap/src/network.rs +++ b/iroh-bitswap/src/network.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Context, Result}; use cid::Cid; use futures::Stream; use iroh_metrics::{bitswap::BitswapMetrics, inc}; @@ -312,6 +312,8 @@ impl Network { self.network_out_sender .send(OutEvent::UnprotectPeer { peer, response: s }) .await + .context("Failed to unprotect peer") + .map_err(|err| error!("{err:#}")) .ok(); r.await.unwrap_or_default() From 0800b0b78da1e338bae4d40d470c2983975ed80b Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 2 Jan 2023 12:34:31 +0100 Subject: [PATCH 3/3] Lol, make things actually work --- iroh-bitswap/src/network.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iroh-bitswap/src/network.rs b/iroh-bitswap/src/network.rs index 1fc870b055..1180e9b212 100644 --- a/iroh-bitswap/src/network.rs +++ b/iroh-bitswap/src/network.rs @@ -6,14 +6,14 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{anyhow, bail, Context as _, Result}; use cid::Cid; use futures::Stream; use iroh_metrics::{bitswap::BitswapMetrics, inc}; use iroh_metrics::{core::MRecorder, record}; use libp2p::{core::connection::ConnectionId, PeerId}; use tokio::sync::{mpsc, oneshot}; -use tracing::{debug, info, trace}; +use tracing::{debug, error, info, trace}; use crate::{message::BitswapMessage, protocol::ProtocolId, BitswapEvent};