Skip to content

Commit

Permalink
replace async_channel also in the os dependent impls of RouteMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Aug 13, 2024
1 parent 8a2e2f5 commit aee9cdc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion iroh-net/src/net/netmon/android.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use anyhow::Result;
use tokio::sync::mpsc;

use super::actor::NetworkMessage;

#[derive(Debug)]
pub(super) struct RouteMonitor {}

impl RouteMonitor {
pub(super) fn new(_sender: async_channel::Sender<NetworkMessage>) -> Result<Self> {
pub(super) fn new(_sender: mpsc::Sender<NetworkMessage>) -> Result<Self> {
// Very sad monitor. Android doesn't allow us to do this

Ok(RouteMonitor {})
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/net/netmon/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +49,7 @@ macro_rules! get_nla {
}

impl RouteMonitor {
pub(super) fn new(sender: async_channel::Sender<NetworkMessage>) -> Result<Self> {
pub(super) fn new(sender: mpsc::Sender<NetworkMessage>) -> Result<Self> {
let (mut conn, mut _handle, mut messages) = new_connection()?;

// Specify flags to listen on.
Expand Down
3 changes: 2 additions & 1 deletion iroh-net/src/net/netmon/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -19,7 +20,7 @@ pub(super) struct RouteMonitor {
}

impl RouteMonitor {
pub(super) fn new(sender: async_channel::Sender<NetworkMessage>) -> Result<Self> {
pub(super) fn new(sender: mpsc::Sender<NetworkMessage>) -> Result<Self> {
// Register two callbacks with the windows api
let mut cb_handler = CallbackHandler::default();

Expand Down
8 changes: 5 additions & 3 deletions iroh-net/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<T: Send + 'static>(sender: &mpsc::Sender<T>, el: T) -> std::result::Result<(), mpsc::error::SendError<T>> {
pub fn send_blocking<T: Send + 'static>(
sender: &mpsc::Sender<T>,
el: T,
) -> std::result::Result<(), mpsc::error::SendError<T>> {
match tokio::runtime::Handle::try_current() {
Ok(h) => {
dbg!(&h);
Expand All @@ -153,7 +156,6 @@ pub fn send_blocking<T: Send + 'static>(sender: &mpsc::Sender<T>, el: T) -> std:
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit aee9cdc

Please sign in to comment.