From aee9cdc16226146b06d1d9f84851becc95669325 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Tue, 13 Aug 2024 12:52:13 +0300 Subject: [PATCH] replace async_channel also in the os dependent impls of RouteMonitor --- iroh-net/src/net/netmon/android.rs | 3 ++- iroh-net/src/net/netmon/linux.rs | 4 ++-- iroh-net/src/net/netmon/windows.rs | 3 ++- iroh-net/src/util.rs | 8 +++++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/net/netmon/android.rs b/iroh-net/src/net/netmon/android.rs index f92eb721f06..ace7e8f3262 100644 --- a/iroh-net/src/net/netmon/android.rs +++ b/iroh-net/src/net/netmon/android.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use tokio::sync::mpsc; use super::actor::NetworkMessage; @@ -6,7 +7,7 @@ use super::actor::NetworkMessage; pub(super) struct RouteMonitor {} impl RouteMonitor { - pub(super) fn new(_sender: async_channel::Sender) -> Result { + pub(super) fn new(_sender: mpsc::Sender) -> Result { // Very sad monitor. Android doesn't allow us to do this Ok(RouteMonitor {}) diff --git a/iroh-net/src/net/netmon/linux.rs b/iroh-net/src/net/netmon/linux.rs index 12976b37e8f..7a422ad9c38 100644 --- a/iroh-net/src/net/netmon/linux.rs +++ b/iroh-net/src/net/netmon/linux.rs @@ -9,7 +9,7 @@ use netlink_packet_core::NetlinkPayload; use netlink_packet_route::{address, constants::*, route, RtnlMessage}; use netlink_sys::{AsyncSocket, SocketAddr}; use rtnetlink::new_connection; -use tokio::task::JoinHandle; +use tokio::{sync::mpsc, task::JoinHandle}; use tracing::{info, trace, warn}; use crate::net::ip::is_link_local; @@ -49,7 +49,7 @@ macro_rules! get_nla { } impl RouteMonitor { - pub(super) fn new(sender: async_channel::Sender) -> Result { + pub(super) fn new(sender: mpsc::Sender) -> Result { let (mut conn, mut _handle, mut messages) = new_connection()?; // Specify flags to listen on. diff --git a/iroh-net/src/net/netmon/windows.rs b/iroh-net/src/net/netmon/windows.rs index da77899d0fd..548c03e0448 100644 --- a/iroh-net/src/net/netmon/windows.rs +++ b/iroh-net/src/net/netmon/windows.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, sync::Arc}; use anyhow::Result; use libc::c_void; +use tokio::sync::mpsc; use tracing::{trace, warn}; use windows::Win32::{ Foundation::{BOOLEAN, HANDLE as Handle}, @@ -19,7 +20,7 @@ pub(super) struct RouteMonitor { } impl RouteMonitor { - pub(super) fn new(sender: async_channel::Sender) -> Result { + pub(super) fn new(sender: mpsc::Sender) -> Result { // Register two callbacks with the windows api let mut cb_handler = CallbackHandler::default(); diff --git a/iroh-net/src/util.rs b/iroh-net/src/util.rs index 1fcbb7945b6..5d62f67cd06 100644 --- a/iroh-net/src/util.rs +++ b/iroh-net/src/util.rs @@ -7,9 +7,9 @@ use std::{ task::{Context, Poll}, }; -use tokio::sync::mpsc; use futures_lite::future::Boxed as BoxFuture; use futures_util::{future::Shared, FutureExt}; +use tokio::sync::mpsc; pub mod chain; @@ -135,7 +135,10 @@ pub(crate) fn relay_only_mode() -> bool { } /// Send an element blocking, automtically handling the existence of a runtime. -pub fn send_blocking(sender: &mpsc::Sender, el: T) -> std::result::Result<(), mpsc::error::SendError> { +pub fn send_blocking( + sender: &mpsc::Sender, + el: T, +) -> std::result::Result<(), mpsc::error::SendError> { match tokio::runtime::Handle::try_current() { Ok(h) => { dbg!(&h); @@ -153,7 +156,6 @@ pub fn send_blocking(sender: &mpsc::Sender, el: T) -> std: } } - #[cfg(test)] mod tests { use super::*;