pub struct RelayLatencies(/* private fields */);Expand description
Latencies per relay node.
-Implementations§
Source§impl RelayLatencies
impl RelayLatencies
Sourcepub fn iter(&self) -> impl Iterator<Item = (&RelayUrl, Duration)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&RelayUrl, Duration)> + '_
Returns an iterator over all the relays and their latencies.
+Implementations§
Trait Implementations§
Source§impl Clone for RelayLatencies
impl Clone for RelayLatencies
Source§fn clone(&self) -> RelayLatencies
fn clone(&self) -> RelayLatencies
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RelayLatencies
impl Debug for RelayLatencies
Source§impl Default for RelayLatencies
impl Default for RelayLatencies
Source§fn default() -> RelayLatencies
fn default() -> RelayLatencies
Source§impl PartialEq for RelayLatencies
impl PartialEq for RelayLatencies
impl Eq for RelayLatencies
impl StructuralPartialEq for RelayLatencies
Auto Trait Implementations§
impl Freeze for RelayLatencies
impl RefUnwindSafe for RelayLatencies
impl Send for RelayLatencies
impl Sync for RelayLatencies
impl Unpin for RelayLatencies
impl UnwindSafe for RelayLatencies
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_net_report/struct.Report.html b/pr/3093/docs/iroh_net_report/struct.Report.html
index dffd956afd..1a2175c6da 100644
--- a/pr/3093/docs/iroh_net_report/struct.Report.html
+++ b/pr/3093/docs/iroh_net_report/struct.Report.html
@@ -11,7 +11,7 @@
pub mapping_varies_by_dest_ipv6: Option<bool>,
pub hair_pinning: Option<bool>,
pub portmap_probe: Option<ProbeOutput>,
- pub preferred_relay: Option<RelayUrl>,
+ pub preferred_relay: Option<RelayUrl>,
pub relay_latency: RelayLatencies,
pub relay_v4_latency: RelayLatencies,
pub relay_v6_latency: RelayLatencies,
@@ -35,7 +35,7 @@ detecting rather than using it. For now.
§hair_pinning: Option<bool>Whether the router supports communicating between two local devices through the NATted
public IP address (on IPv4).
§portmap_probe: Option<ProbeOutput>Probe indicating the presence of port mapping protocols on the LAN.
-§preferred_relay: Option<RelayUrl>None for unknown
+§preferred_relay: Option<RelayUrl>None for unknown
§relay_latency: RelayLatencieskeyed by relay Url
§relay_v4_latency: RelayLatencieskeyed by relay Url
§relay_v6_latency: RelayLatencieskeyed by relay Url
diff --git a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
index 196743d3c9..e916c781a4 100644
--- a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
+++ b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
@@ -1,9 +1,9 @@
ReceivedMessage in iroh_relay::client - Rust pub enum ReceivedMessage {
ReceivedPacket {
- remote_node_id: NodeId,
+ remote_node_id: NodeId,
data: Bytes,
},
- NodeGone(NodeId),
+ NodeGone(NodeId),
Ping([u8; 8]),
Pong([u8; 8]),
KeepAlive,
@@ -17,9 +17,9 @@
}
Expand description
The messages received from a framed relay stream.
This is a type-validated version of the Frames on the RelayCodec.
Variants§
§ReceivedPacket
Represents an incoming packet.
-Fields
§NodeGone(NodeId)
Indicates that the client identified by the underlying public key had previously sent you a
packet but has now disconnected from the server.
§Ping([u8; 8])
Request from a client or server to reply to the
other side with a ReceivedMessage::Pong with the given payload.
diff --git a/pr/3093/docs/iroh_relay/client/enum.SendMessage.html b/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
index 7e43b4d825..4a227894e8 100644
--- a/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
+++ b/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
@@ -1,9 +1,9 @@
SendMessage in iroh_relay::client - Rust pub enum SendMessage {
- SendPacket(NodeId, Bytes),
+ SendPacket(NodeId, Bytes),
Ping([u8; 8]),
Pong([u8; 8]),
}
Expand description
Messages we can send to a relay server.
-Variants§
§SendPacket(NodeId, Bytes)
Send a packet of data to the [NodeId].
+Variants§
§SendPacket(NodeId, Bytes)
Send a packet of data to the NodeId.
§Ping([u8; 8])
Sends a ping message to the connected relay server.
§Pong([u8; 8])
Sends a pong message to the connected relay server.
Trait Implementations§
Source§impl Debug for SendMessage
Source§impl Sink<SendMessage> for Client
Source§type Error = ConnSendError
The type of value produced by the sink when an error occurs.Source§fn poll_ready(
diff --git a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
index 98e615a1e1..eff40160fc 100644
--- a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
+++ b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
@@ -1,7 +1,7 @@
ClientBuilder in iroh_relay::client - Rust pub struct ClientBuilder { /* private fields */ }
Expand description
Build a Client.
Implementations§
Source§impl ClientBuilder
Sourcepub fn new(
- url: impl Into<RelayUrl>,
- secret_key: SecretKey,
+ url: impl Into<RelayUrl>,
+ secret_key: SecretKey,
dns_resolver: DnsResolver,
) -> Self
Create a new ClientBuilder
Sourcepub fn protocol(self, protocol: Protocol) -> Self
Sets whether to connect to the relay via websockets or not.
diff --git a/pr/3093/docs/iroh_relay/protos/relay/index.html b/pr/3093/docs/iroh_relay/protos/relay/index.html
index 9253a719da..f5269c8ba3 100644
--- a/pr/3093/docs/iroh_relay/protos/relay/index.html
+++ b/pr/3093/docs/iroh_relay/protos/relay/index.html
@@ -1,4 +1,4 @@
-
iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
+iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
Protocol flow:
Login:
diff --git a/pr/3093/docs/iroh_relay/server/struct.Server.html b/pr/3093/docs/iroh_relay/server/struct.Server.html
index f8ea38e000..cac179ba5d 100644
--- a/pr/3093/docs/iroh_relay/server/struct.Server.html
+++ b/pr/3093/docs/iroh_relay/server/struct.Server.html
@@ -14,9 +14,9 @@ case there is an error in the server before it is shut down.
Sourcepub fn quic_addr(&self) -> Option<SocketAddr>
The socket address the QUIC server is listening on.
Sourcepub fn stun_addr(&self) -> Option<SocketAddr>
The socket address the STUN server is listening on.
Sourcepub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
The certificates chain if configured with manual TLS certificates.
-Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https [RelayUrl].
+Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https RelayUrl.
This uses Self::https_addr so it’s mostly useful for local development.
-Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Server
§impl RefUnwindSafe for Server
§impl Send for Server
§impl Sync for Server
§impl Unpin for Server
§impl UnwindSafe for Server
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_net_report/struct.Report.html b/pr/3093/docs/iroh_net_report/struct.Report.html
index dffd956afd..1a2175c6da 100644
--- a/pr/3093/docs/iroh_net_report/struct.Report.html
+++ b/pr/3093/docs/iroh_net_report/struct.Report.html
@@ -11,7 +11,7 @@
pub mapping_varies_by_dest_ipv6: Option<bool>,
pub hair_pinning: Option<bool>,
pub portmap_probe: Option<ProbeOutput>,
- pub preferred_relay: Option<RelayUrl>,
+ pub preferred_relay: Option<RelayUrl>,
pub relay_latency: RelayLatencies,
pub relay_v4_latency: RelayLatencies,
pub relay_v6_latency: RelayLatencies,
@@ -35,7 +35,7 @@ detecting rather than using it. For now.
§hair_pinning: Option<bool>Whether the router supports communicating between two local devices through the NATted
public IP address (on IPv4).
§portmap_probe: Option<ProbeOutput>Probe indicating the presence of port mapping protocols on the LAN.
-§preferred_relay: Option<RelayUrl>None for unknown
+§preferred_relay: Option<RelayUrl>None for unknown
§relay_latency: RelayLatencieskeyed by relay Url
§relay_v4_latency: RelayLatencieskeyed by relay Url
§relay_v6_latency: RelayLatencieskeyed by relay Url
diff --git a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
index 196743d3c9..e916c781a4 100644
--- a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
+++ b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html
@@ -1,9 +1,9 @@
ReceivedMessage in iroh_relay::client - Rust pub enum ReceivedMessage {
ReceivedPacket {
- remote_node_id: NodeId,
+ remote_node_id: NodeId,
data: Bytes,
},
- NodeGone(NodeId),
+ NodeGone(NodeId),
Ping([u8; 8]),
Pong([u8; 8]),
KeepAlive,
@@ -17,9 +17,9 @@
}
Expand description
The messages received from a framed relay stream.
This is a type-validated version of the Frames on the RelayCodec.
Variants§
§ReceivedPacket
Represents an incoming packet.
-Fields
§NodeGone(NodeId)
Indicates that the client identified by the underlying public key had previously sent you a
packet but has now disconnected from the server.
§Ping([u8; 8])
Request from a client or server to reply to the
other side with a ReceivedMessage::Pong with the given payload.
diff --git a/pr/3093/docs/iroh_relay/client/enum.SendMessage.html b/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
index 7e43b4d825..4a227894e8 100644
--- a/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
+++ b/pr/3093/docs/iroh_relay/client/enum.SendMessage.html
@@ -1,9 +1,9 @@
SendMessage in iroh_relay::client - Rust pub enum SendMessage {
- SendPacket(NodeId, Bytes),
+ SendPacket(NodeId, Bytes),
Ping([u8; 8]),
Pong([u8; 8]),
}
Expand description
Messages we can send to a relay server.
-Variants§
§SendPacket(NodeId, Bytes)
Send a packet of data to the [NodeId].
+Variants§
§SendPacket(NodeId, Bytes)
Send a packet of data to the NodeId.
§Ping([u8; 8])
Sends a ping message to the connected relay server.
§Pong([u8; 8])
Sends a pong message to the connected relay server.
Trait Implementations§
Source§impl Debug for SendMessage
Source§impl Sink<SendMessage> for Client
Source§type Error = ConnSendError
The type of value produced by the sink when an error occurs.Source§fn poll_ready(
diff --git a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
index 98e615a1e1..eff40160fc 100644
--- a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
+++ b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
@@ -1,7 +1,7 @@
ClientBuilder in iroh_relay::client - Rust pub struct ClientBuilder { /* private fields */ }
Expand description
Build a Client.
Implementations§
Source§impl ClientBuilder
Sourcepub fn new(
- url: impl Into<RelayUrl>,
- secret_key: SecretKey,
+ url: impl Into<RelayUrl>,
+ secret_key: SecretKey,
dns_resolver: DnsResolver,
) -> Self
Create a new ClientBuilder
Sourcepub fn protocol(self, protocol: Protocol) -> Self
Sets whether to connect to the relay via websockets or not.
diff --git a/pr/3093/docs/iroh_relay/protos/relay/index.html b/pr/3093/docs/iroh_relay/protos/relay/index.html
index 9253a719da..f5269c8ba3 100644
--- a/pr/3093/docs/iroh_relay/protos/relay/index.html
+++ b/pr/3093/docs/iroh_relay/protos/relay/index.html
@@ -1,4 +1,4 @@
-
iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
+iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
Protocol flow:
Login:
diff --git a/pr/3093/docs/iroh_relay/server/struct.Server.html b/pr/3093/docs/iroh_relay/server/struct.Server.html
index f8ea38e000..cac179ba5d 100644
--- a/pr/3093/docs/iroh_relay/server/struct.Server.html
+++ b/pr/3093/docs/iroh_relay/server/struct.Server.html
@@ -14,9 +14,9 @@ case there is an error in the server before it is shut down.
Sourcepub fn quic_addr(&self) -> Option<SocketAddr>
The socket address the QUIC server is listening on.
Sourcepub fn stun_addr(&self) -> Option<SocketAddr>
The socket address the STUN server is listening on.
Sourcepub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
The certificates chain if configured with manual TLS certificates.
-Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https [RelayUrl].
+Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https RelayUrl.
This uses Self::https_addr so it’s mostly useful for local development.
-Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Server
§impl RefUnwindSafe for Server
§impl Send for Server
§impl Sync for Server
§impl Unpin for Server
§impl UnwindSafe for Server
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
Whether the router supports communicating between two local devices through the NATted public IP address (on IPv4).
Probe indicating the presence of port mapping protocols on the LAN.
-None for unknown
None for unknown
keyed by relay Url
keyed by relay Url
keyed by relay Url
diff --git a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html index 196743d3c9..e916c781a4 100644 --- a/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html +++ b/pr/3093/docs/iroh_relay/client/enum.ReceivedMessage.html @@ -1,9 +1,9 @@pub enum ReceivedMessage {
ReceivedPacket {
- remote_node_id: NodeId,
+ remote_node_id: NodeId,
data: Bytes,
},
- NodeGone(NodeId),
+ NodeGone(NodeId),
Ping([u8; 8]),
Pong([u8; 8]),
KeepAlive,
@@ -17,9 +17,9 @@
}Expand description
The messages received from a framed relay stream.
This is a type-validated version of the Frames on the RelayCodec.
Variants§
ReceivedPacket
Represents an incoming packet.
-Fields
NodeGone(NodeId)
Indicates that the client identified by the underlying public key had previously sent you a packet but has now disconnected from the server.
Ping([u8; 8])
Request from a client or server to reply to the
other side with a ReceivedMessage::Pong with the given payload.
pub enum SendMessage {
- SendPacket(NodeId, Bytes),
+ SendPacket(NodeId, Bytes),
Ping([u8; 8]),
Pong([u8; 8]),
}Expand description
Messages we can send to a relay server.
-Variants§
SendPacket(NodeId, Bytes)
Send a packet of data to the [NodeId].
Variants§
SendPacket(NodeId, Bytes)
Send a packet of data to the NodeId.
Ping([u8; 8])
Sends a ping message to the connected relay server.
Pong([u8; 8])
Sends a pong message to the connected relay server.
Trait Implementations§
Source§impl Debug for SendMessage
impl Debug for SendMessage
Source§impl Sink<SendMessage> for Client
impl Sink<SendMessage> for Client
Source§type Error = ConnSendError
type Error = ConnSendError
Source§fn poll_ready(
diff --git a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
index 98e615a1e1..eff40160fc 100644
--- a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
+++ b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
@@ -1,7 +1,7 @@
ClientBuilder in iroh_relay::client - Rust pub struct ClientBuilder { /* private fields */ }
Expand description
Build a Client.
Implementations§
Source§impl ClientBuilder
Sourcepub fn new(
- url: impl Into<RelayUrl>,
- secret_key: SecretKey,
+ url: impl Into<RelayUrl>,
+ secret_key: SecretKey,
dns_resolver: DnsResolver,
) -> Self
Create a new ClientBuilder
Sourcepub fn protocol(self, protocol: Protocol) -> Self
Sets whether to connect to the relay via websockets or not.
diff --git a/pr/3093/docs/iroh_relay/protos/relay/index.html b/pr/3093/docs/iroh_relay/protos/relay/index.html
index 9253a719da..f5269c8ba3 100644
--- a/pr/3093/docs/iroh_relay/protos/relay/index.html
+++ b/pr/3093/docs/iroh_relay/protos/relay/index.html
@@ -1,4 +1,4 @@
-
iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
+iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
Protocol flow:
Login:
diff --git a/pr/3093/docs/iroh_relay/server/struct.Server.html b/pr/3093/docs/iroh_relay/server/struct.Server.html
index f8ea38e000..cac179ba5d 100644
--- a/pr/3093/docs/iroh_relay/server/struct.Server.html
+++ b/pr/3093/docs/iroh_relay/server/struct.Server.html
@@ -14,9 +14,9 @@ case there is an error in the server before it is shut down.
Sourcepub fn quic_addr(&self) -> Option<SocketAddr>
The socket address the QUIC server is listening on.
Sourcepub fn stun_addr(&self) -> Option<SocketAddr>
The socket address the STUN server is listening on.
Sourcepub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
The certificates chain if configured with manual TLS certificates.
-Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https [RelayUrl].
+Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https RelayUrl.
This uses Self::https_addr so it’s mostly useful for local development.
-Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Server
§impl RefUnwindSafe for Server
§impl Send for Server
§impl Sync for Server
§impl Unpin for Server
§impl UnwindSafe for Server
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
fn poll_ready(
diff --git a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
index 98e615a1e1..eff40160fc 100644
--- a/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
+++ b/pr/3093/docs/iroh_relay/client/struct.ClientBuilder.html
@@ -1,7 +1,7 @@
ClientBuilder in iroh_relay::client - Rust pub struct ClientBuilder { /* private fields */ }
Expand description
Build a Client.
Implementations§
Source§impl ClientBuilder
Sourcepub fn new(
- url: impl Into<RelayUrl>,
- secret_key: SecretKey,
+ url: impl Into<RelayUrl>,
+ secret_key: SecretKey,
dns_resolver: DnsResolver,
) -> Self
Create a new ClientBuilder
Sourcepub fn protocol(self, protocol: Protocol) -> Self
Sets whether to connect to the relay via websockets or not.
diff --git a/pr/3093/docs/iroh_relay/protos/relay/index.html b/pr/3093/docs/iroh_relay/protos/relay/index.html
index 9253a719da..f5269c8ba3 100644
--- a/pr/3093/docs/iroh_relay/protos/relay/index.html
+++ b/pr/3093/docs/iroh_relay/protos/relay/index.html
@@ -1,4 +1,4 @@
-
iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
+iroh_relay::protos::relay - Rust Expand description
This module implements the relaying protocol used by the server and client.
Protocol flow:
Login:
diff --git a/pr/3093/docs/iroh_relay/server/struct.Server.html b/pr/3093/docs/iroh_relay/server/struct.Server.html
index f8ea38e000..cac179ba5d 100644
--- a/pr/3093/docs/iroh_relay/server/struct.Server.html
+++ b/pr/3093/docs/iroh_relay/server/struct.Server.html
@@ -14,9 +14,9 @@ case there is an error in the server before it is shut down.
Sourcepub fn quic_addr(&self) -> Option<SocketAddr>
The socket address the QUIC server is listening on.
Sourcepub fn stun_addr(&self) -> Option<SocketAddr>
The socket address the STUN server is listening on.
Sourcepub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
The certificates chain if configured with manual TLS certificates.
-Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https [RelayUrl].
+Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
Get the server’s https RelayUrl.
This uses Self::https_addr so it’s mostly useful for local development.
-Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Server
§impl RefUnwindSafe for Server
§impl Send for Server
§impl Sync for Server
§impl Unpin for Server
§impl UnwindSafe for Server
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
pub struct ClientBuilder { /* private fields */ }Expand description
Build a Client.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new(
- url: impl Into<RelayUrl>,
- secret_key: SecretKey,
+ url: impl Into<RelayUrl>,
+ secret_key: SecretKey,
dns_resolver: DnsResolver,
) -> Self
pub fn new( - url: impl Into<RelayUrl>, - secret_key: SecretKey, + url: impl Into<RelayUrl>, + secret_key: SecretKey, dns_resolver: DnsResolver, ) -> Self
Create a new ClientBuilder
Sourcepub fn protocol(self, protocol: Protocol) -> Self
pub fn protocol(self, protocol: Protocol) -> Self
Sets whether to connect to the relay via websockets or not. diff --git a/pr/3093/docs/iroh_relay/protos/relay/index.html b/pr/3093/docs/iroh_relay/protos/relay/index.html index 9253a719da..f5269c8ba3 100644 --- a/pr/3093/docs/iroh_relay/protos/relay/index.html +++ b/pr/3093/docs/iroh_relay/protos/relay/index.html @@ -1,4 +1,4 @@ -
Expand description
This module implements the relaying protocol used by the server and client.
Expand description
This module implements the relaying protocol used by the server and client.
Protocol flow:
Login:
-
diff --git a/pr/3093/docs/iroh_relay/server/struct.Server.html b/pr/3093/docs/iroh_relay/server/struct.Server.html
index f8ea38e000..cac179ba5d 100644
--- a/pr/3093/docs/iroh_relay/server/struct.Server.html
+++ b/pr/3093/docs/iroh_relay/server/struct.Server.html
@@ -14,9 +14,9 @@ case there is an error in the server before it is shut down.
Sourcepub fn quic_addr(&self) -> Option<SocketAddr>
pub fn quic_addr(&self) -> Option<SocketAddr>
The socket address the QUIC server is listening on.
Sourcepub fn stun_addr(&self) -> Option<SocketAddr>
pub fn stun_addr(&self) -> Option<SocketAddr>
The socket address the STUN server is listening on.
Sourcepub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
pub fn certificates(&self) -> Option<Vec<CertificateDer<'static>>>
The certificates chain if configured with manual TLS certificates.
-Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
pub fn https_url(&self) -> Option<RelayUrl>
test-utils only.Get the server’s https [RelayUrl].
Sourcepub fn https_url(&self) -> Option<RelayUrl>
Available on crate feature test-utils only.
pub fn https_url(&self) -> Option<RelayUrl>
test-utils only.Get the server’s https RelayUrl.
This uses Self::https_addr so it’s mostly useful for local development.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnwindSafe for Server
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
diff --git a/pr/3093/docs/iroh_relay/struct.RelayMap.html b/pr/3093/docs/iroh_relay/struct.RelayMap.html
index f69c9124c5..2f8d052e51 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayMap.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayMap.html
@@ -1,16 +1,16 @@
RelayMap in iroh_relay - Rust pub struct RelayMap { /* private fields */ }
Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
Implementations§
Source§impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6.
If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
-Sourcepub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
RelayNode in iroh_relay - Rust pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}
Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
+Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
§stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay
functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html
index 040a285979..5cff68a5d8 100644
--- a/pr/3093/docs/src/iroh/magicsock.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock.rs.html
@@ -6008,7 +6008,7 @@
}
impl RelayDatagramRecvQueue {
- /// Creates a new, empty queue with a fixed size bound of 128 items.
+ /// Creates a new, empty queue with a fixed size bound of 512 items.
fn new() -> Self {
Self {
queue: ConcurrentQueue::bounded(512),
diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
index c0e17180a3..51a74fc28c 100644
--- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
+++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html
@@ -1534,10 +1534,7 @@
1533
1534
1535
-1536
-1537
-1538
-1539//! The relay actor.
+1536
//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841
//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842
//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720
//! The server-side representation of an ongoing client relaying connection.
+699
//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204
//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205
//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");
pub struct RelayMap { /* private fields */ }Expand description
Configuration of all the relay servers that can be used.
-Implementations§
Source§impl RelayMap
impl RelayMap
Implementations§
Source§impl RelayMap
impl RelayMap
Sourcepub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
pub fn nodes(&self) -> impl Iterator<Item = &Arc<RelayNode>>
Returns an Iterator over all known nodes.
Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
pub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
-Sourcepub fn contains_node(&self, url: &RelayUrl) -> bool
pub fn contains_node(&self, url: &RelayUrl) -> bool
Is this a known node?
+Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
pub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Sourcepub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
pub fn default_from_node(url: RelayUrl, stun_port: u16) -> Self
Creates a new RelayMap with a single relay server configured.
Allows to set a custom STUN port and different IP addresses for IPv4 and IPv6. If IP addresses are provided, no DNS lookup will be performed.
Sets the port to the default DEFAULT_RELAY_QUIC_PORT.
Sourcepub fn from_url(url: RelayUrl) -> Self
pub fn from_url(url: RelayUrl) -> Self
Returns a RelayMap from a RelayUrl.
This will use the default STUN port, the default QUIC port
(as defined by the iroh-relay crate) and IP addresses
resolved from the URL’s host name via DNS.
diff --git a/pr/3093/docs/iroh_relay/struct.RelayNode.html b/pr/3093/docs/iroh_relay/struct.RelayNode.html
index 5a4af90c83..ebdf471da6 100644
--- a/pr/3093/docs/iroh_relay/struct.RelayNode.html
+++ b/pr/3093/docs/iroh_relay/struct.RelayNode.html
@@ -1,11 +1,11 @@
pub struct RelayNode {
- pub url: RelayUrl,
+ pub url: RelayUrl,
pub stun_only: bool,
pub stun_port: u16,
pub quic: Option<RelayQuicConfig>,
}Expand description
Information on a specific relay server.
Includes the Url where it can be dialed.
-Fields§
§url: RelayUrlThe [RelayUrl] where this relay server can be dialed.
Fields§
§url: RelayUrlThe RelayUrl where this relay server can be dialed.
stun_only: boolWhether this relay server should only be used for STUN requests.
This essentially allows you to use a normal STUN server as a relay node, no relay functionality is used.
diff --git a/pr/3093/docs/src/iroh/magicsock.rs.html b/pr/3093/docs/src/iroh/magicsock.rs.html index 040a285979..5cff68a5d8 100644 --- a/pr/3093/docs/src/iroh/magicsock.rs.html +++ b/pr/3093/docs/src/iroh/magicsock.rs.html @@ -6008,7 +6008,7 @@ } impl RelayDatagramRecvQueue { - /// Creates a new, empty queue with a fixed size bound of 128 items. + /// Creates a new, empty queue with a fixed size bound of 512 items. fn new() -> Self { Self { queue: ConcurrentQueue::bounded(512), diff --git a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html index c0e17180a3..51a74fc28c 100644 --- a/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html +++ b/pr/3093/docs/src/iroh/magicsock/relay_actor.rs.html @@ -1534,10 +1534,7 @@ 1533 1534 1535 -1536 -1537 -1538 -1539//! The relay actor.
+1536//! The relay actor.
//!
//! The [`RelayActor`] handles all the relay connections. It is helped by the
//! [`ActiveRelayActor`] which handles a single relay connection.
@@ -1645,7 +1642,7 @@
struct ActiveRelayActor {
// The inboxes and channels this actor communicates over.
/// Inbox for messages which should be handled without any blocking.
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox: mpsc::Receiver<ActiveRelayPrioMessage>,
/// Inbox for messages which involve sending to the relay server.
inbox: mpsc::Receiver<ActiveRelayMessage>,
/// Queue to send received relay datagrams on.
@@ -1698,7 +1695,7 @@
/// which can be blocking. So the actor may not always be processing that inbox. Messages
/// here are processed immediately.
#[derive(Debug)]
-enum ActiveRelayFastMessage {
+enum ActiveRelayPrioMessage {
/// Returns whether or not this relay can reach the NodeId.
HasNodeRoute(NodeId, oneshot::Sender<bool>),
}
@@ -1707,7 +1704,7 @@
#[derive(Debug)]
struct ActiveRelayActorOptions {
url: RelayUrl,
- fast_inbox: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -1730,7 +1727,7 @@
fn new(opts: ActiveRelayActorOptions) -> Self {
let ActiveRelayActorOptions {
url,
- fast_inbox,
+ prio_inbox_: prio_inbox,
inbox,
relay_datagrams_send,
relay_datagrams_recv,
@@ -1739,7 +1736,7 @@
} = opts;
let relay_client_builder = Self::create_relay_builder(url.clone(), connection_opts);
ActiveRelayActor {
- fast_inbox,
+ prio_inbox,
inbox,
relay_datagrams_recv,
relay_datagrams_send,
@@ -1831,13 +1828,13 @@
debug!("Shutdown.");
break None;
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break None;
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(_peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(_peer, sender) => {
sender.send(false).ok();
}
}
@@ -1955,13 +1952,13 @@
debug!("Shutdown.");
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2130,13 +2127,13 @@
_ = self.stop_token.cancelled() => {
break Ok(());
}
- msg = self.fast_inbox.recv() => {
+ msg = self.prio_inbox.recv() => {
let Some(msg) = msg else {
- warn!("Fast inbox closed, shutdown.");
+ warn!("Priority inbox closed, shutdown.");
break Ok(());
};
match msg {
- ActiveRelayFastMessage::HasNodeRoute(peer, sender) => {
+ ActiveRelayPrioMessage::HasNodeRoute(peer, sender) => {
let has_peer = state.nodes_present.contains(&peer);
sender.send(has_peer).ok();
}
@@ -2377,16 +2374,13 @@
// If we don't have an open connection to the remote node's home relay, see if
// we have an open connection to a relay node where we'd heard from that peer
// already. E.g. maybe they dialed our home relay recently.
- // TODO: LRU cache the NodeId -> relay mapping so this is much faster for repeat
- // senders.
-
{
// Futures which return Some(RelayUrl) if the relay knows about the remote node.
let check_futs = self.active_relays.iter().map(|(url, handle)| async move {
let (tx, rx) = oneshot::channel();
handle
- .fast_inbox_addr
- .send(ActiveRelayFastMessage::HasNodeRoute(*remote_node, tx))
+ .prio_inbox_addr
+ .send(ActiveRelayPrioMessage::HasNodeRoute(*remote_node, tx))
.await
.ok();
match rx.await {
@@ -2440,12 +2434,12 @@
// TODO: Replace 64 with PER_CLIENT_SEND_QUEUE_DEPTH once that's unused
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(64);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(32);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(32);
let (inbox_tx, inbox_rx) = mpsc::channel(64);
let span = info_span!("active-relay", %url);
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send: send_datagram_rx,
relay_datagrams_recv: self.relay_datagram_recv_queue.clone(),
@@ -2463,7 +2457,7 @@
.instrument(span),
);
let handle = ActiveRelayHandle {
- fast_inbox_addr: fast_inbox_tx,
+ prio_inbox_addr: prio_inbox_tx,
inbox_addr: inbox_tx,
datagrams_send_queue: send_datagram_tx,
};
@@ -2533,7 +2527,7 @@
/// Handle to one [`ActiveRelayActor`].
#[derive(Debug, Clone)]
struct ActiveRelayHandle {
- fast_inbox_addr: mpsc::Sender<ActiveRelayFastMessage>,
+ prio_inbox_addr: mpsc::Sender<ActiveRelayPrioMessage>,
inbox_addr: mpsc::Sender<ActiveRelayMessage>,
datagrams_send_queue: mpsc::Sender<RelaySendItem>,
}
@@ -2773,7 +2767,7 @@
secret_key: SecretKey,
stop_token: CancellationToken,
url: RelayUrl,
- fast_inbox_rx: mpsc::Receiver<ActiveRelayFastMessage>,
+ prio_inbox_rx: mpsc::Receiver<ActiveRelayPrioMessage>,
inbox_rx: mpsc::Receiver<ActiveRelayMessage>,
relay_datagrams_send: mpsc::Receiver<RelaySendItem>,
relay_datagrams_recv: Arc<RelayDatagramRecvQueue>,
@@ -2781,7 +2775,7 @@
) -> AbortOnDropHandle<anyhow::Result<()>> {
let opts = ActiveRelayActorOptions {
url,
- fast_inbox: fast_inbox_rx,
+ prio_inbox_: prio_inbox_rx,
inbox: inbox_rx,
relay_datagrams_send,
relay_datagrams_recv,
@@ -2807,14 +2801,14 @@
let secret_key = SecretKey::from_bytes(&[8u8; 32]);
let recv_datagram_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let actor_task = start_active_relay_actor(
secret_key.clone(),
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
recv_datagram_queue.clone(),
@@ -2843,7 +2837,7 @@
let supervisor_task = tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
// move the inboxes here so it is not dropped, as this stops the actor.
- let _fast_inbox_tx = fast_inbox_tx;
+ let _prio_inbox_tx = prio_inbox_tx;
let _inbox_tx = inbox_tx;
tokio::select! {
biased;
@@ -2900,14 +2894,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url.clone(),
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
@@ -2986,14 +2980,14 @@
let secret_key = SecretKey::from_bytes(&[1u8; 32]);
let datagram_recv_queue = Arc::new(RelayDatagramRecvQueue::new());
let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16);
- let (_fast_inbox_tx, fast_inbox_rx) = mpsc::channel(8);
+ let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8);
let (inbox_tx, inbox_rx) = mpsc::channel(16);
let cancel_token = CancellationToken::new();
let mut task = start_active_relay_actor(
secret_key,
cancel_token.clone(),
relay_url,
- fast_inbox_rx,
+ prio_inbox_rx,
inbox_rx,
send_datagram_rx,
datagram_recv_queue.clone(),
diff --git a/pr/3093/docs/src/iroh_relay/client.rs.html b/pr/3093/docs/src/iroh_relay/client.rs.html
index 6b2b56cfe5..3dbab5f2ba 100644
--- a/pr/3093/docs/src/iroh_relay/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/client.rs.html
@@ -1281,7 +1281,7 @@
})
.await
.context("Timeout connecting")?
- .context("Error connecting")?;
+ .context("Connecting")?;
tcp_stream.set_nodelay(true)?;
diff --git a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
index af23188dc9..13ccdcd773 100644
--- a/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
+++ b/pr/3093/docs/src/iroh_relay/protos/relay.rs.html
@@ -839,7 +839,8 @@
838
839
840
-841//! This module implements the relaying protocol used by the `server` and `client`.
+841
+842//! This module implements the relaying protocol used by the `server` and `client`.
//!
//! Protocol flow:
//!
@@ -1019,7 +1020,7 @@
// TODO: variable recv size: 256 * 1024
let buf = tokio::time::timeout(
- Duration::from_secs(10),
+ std::time::Duration::from_secs(10),
recv_frame(FrameType::ClientInfo, stream),
)
.await
@@ -1431,6 +1432,7 @@
use super::*;
#[tokio::test]
+ #[cfg(feature = "server")]
async fn test_basic_read_write() -> anyhow::Result<()> {
let (reader, writer) = tokio::io::duplex(1024);
let mut reader = FramedRead::new(reader, RelayCodec::test());
diff --git a/pr/3093/docs/src/iroh_relay/server/client.rs.html b/pr/3093/docs/src/iroh_relay/server/client.rs.html
index 2e5774699f..43fcc69a20 100644
--- a/pr/3093/docs/src/iroh_relay/server/client.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/client.rs.html
@@ -697,28 +697,7 @@
696
697
698
-699
-700
-701
-702
-703
-704
-705
-706
-707
-708
-709
-710
-711
-712
-713
-714
-715
-716
-717
-718
-719
-720//! The server-side representation of an ongoing client relaying connection.
+699//! The server-side representation of an ongoing client relaying connection.
use std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
@@ -729,9 +708,9 @@
use futures_util::{SinkExt, Stream, StreamExt};
use iroh_base::NodeId;
use iroh_metrics::{inc, inc_by};
-use tokio::sync::mpsc;
+use tokio::sync::mpsc::{self, error::TrySendError};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
-use tracing::{error, info, instrument, trace, warn, Instrument};
+use tracing::{debug, error, instrument, trace, warn, Instrument};
use crate::{
protos::{
@@ -743,16 +722,13 @@
/// A request to write a dataframe to a Client
#[derive(Debug, Clone)]
-struct Packet {
+pub(super) struct Packet {
/// The sender of the packet
src: NodeId,
/// The data packet bytes.
data: Bytes,
}
-/// Number of times we try to send to a client connection before dropping the data;
-const RETRIES: usize = 3;
-
/// Configuration for a [`Client`].
#[derive(Debug)]
pub(super) struct Config {
@@ -826,20 +802,20 @@
// start io loop
let io_done = done.clone();
- let io_client_id = node_id;
let handle = tokio::task::spawn(
async move {
- let key = io_client_id;
match actor.run(io_done).await {
Err(e) => {
- warn!("connection manager for {key:?}: writer closed in error {e:?}");
+ warn!("writer closed in error {e:#?}");
}
Ok(()) => {
- info!("connection manager for {key:?}: writer closed");
+ debug!("writer closed");
}
}
}
- .instrument(tracing::info_span!("client_conn_actor")),
+ .instrument(
+ tracing::info_span!("client connection actor", remote_node = %node_id.fmt_short()),
+ ),
);
Client {
@@ -859,51 +835,33 @@
self.done.cancel();
if let Err(e) = self.handle.await {
warn!(
- "error closing actor loop for client connection {:?}: {e:?}",
- self.node_id,
+ remote_node = %self.node_id.fmt_short(),
+ "error closing actor loop: {e:#?}",
);
};
}
- pub(super) fn send_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.send_queue, Packet { src, data })
+ pub(super) fn try_send_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_disco_packet(&self, src: NodeId, data: Bytes) -> Result<(), SendError> {
- try_send(&self.disco_send_queue, Packet { src, data })
+ pub(super) fn try_send_disco_packet(
+ &self,
+ src: NodeId,
+ data: Bytes,
+ ) -> Result<(), TrySendError<Packet>> {
+ self.disco_send_queue.try_send(Packet { src, data })
}
- pub(super) fn send_peer_gone(&self, key: NodeId) -> Result<(), SendError> {
- try_send(&self.peer_gone, key)
+ pub(super) fn try_send_peer_gone(&self, key: NodeId) -> Result<(), TrySendError<NodeId>> {
+ self.peer_gone.try_send(key)
}
}
-#[derive(Debug, thiserror::Error)]
-pub(super) enum SendError {
- #[error("packet dropped")]
- PacketDropped,
- #[error("sender closed")]
- SenderClosed,
-}
-
-/// Tries up to `3` times to send a message into the given channel, retrying iff it is full.
-fn try_send<T>(sender: &mpsc::Sender<T>, msg: T) -> Result<(), SendError> {
- let mut msg = msg;
- for _ in 0..RETRIES {
- match sender.try_send(msg) {
- Ok(_) => {
- return Ok(());
- }
- // if the queue is full, try again (max 3 times)
- Err(mpsc::error::TrySendError::Full(m)) => msg = m,
- // only other option is `TrySendError::Closed`, report the
- // closed error
- Err(_) => return Err(SendError::SenderClosed),
- }
- }
- Err(SendError::PacketDropped)
-}
-
/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE`
/// message to the client to keep the connection alive.
///
diff --git a/pr/3093/docs/src/iroh_relay/server/clients.rs.html b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
index cca3f31971..cd2d18deca 100644
--- a/pr/3093/docs/src/iroh_relay/server/clients.rs.html
+++ b/pr/3093/docs/src/iroh_relay/server/clients.rs.html
@@ -202,7 +202,8 @@
201
202
203
-204//! The "Server" side of the client. Uses the `ClientConnManager`.
+204
+205//! The "Server" side of the client. Uses the `ClientConnManager`.
// Based on tailscale/derp/derp_server.go
use std::{collections::HashSet, sync::Arc};
@@ -212,9 +213,10 @@
use dashmap::DashMap;
use iroh_base::NodeId;
use iroh_metrics::inc;
+use tokio::sync::mpsc::error::TrySendError;
use tracing::{debug, trace, warn};
-use super::client::{Client, Config, SendError};
+use super::client::{Client, Config, Packet};
use crate::server::metrics::Metrics;
/// Manages the connections to all currently connected clients.
@@ -262,12 +264,12 @@
if let Some((_, client)) = self.0.clients.remove(&node_id) {
if let Some((_, sent_to)) = self.0.sent_to.remove(&node_id) {
for key in sent_to {
- match client.send_peer_gone(key) {
+ match client.try_send_peer_gone(key) {
Ok(_) => {}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {key:?} too busy to receive packet, dropping packet");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {key:?}, dropping packet");
}
}
@@ -280,7 +282,7 @@
/// Attempt to send a packet to client with [`NodeId`] `dst`
pub(super) async fn send_packet(&self, dst: NodeId, data: Bytes, src: NodeId) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_packet(src, data);
+ let res = client.try_send_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped packet");
@@ -295,7 +297,7 @@
src: NodeId,
) -> Result<()> {
if let Some(client) = self.0.clients.get(&dst) {
- let res = client.send_disco_packet(src, data);
+ let res = client.try_send_disco_packet(src, data);
return self.process_result(src, dst, res).await;
}
warn!("could not find client for {dst:?}, dropped disco packet");
@@ -307,7 +309,7 @@
&self,
src: NodeId,
dst: NodeId,
- res: Result<(), SendError>,
+ res: Result<(), TrySendError<Packet>>,
) -> Result<()> {
match res {
Ok(_) => {
@@ -315,11 +317,11 @@
self.0.sent_to.entry(src).or_default().insert(dst);
Ok(())
}
- Err(SendError::PacketDropped) => {
+ Err(TrySendError::Full(_)) => {
warn!("client {dst:?} too busy to receive packet, dropping packet");
bail!("failed to send message");
}
- Err(SendError::SenderClosed) => {
+ Err(TrySendError::Closed(_)) => {
debug!("can no longer write to client {dst:?}, dropping message and pruning connection");
self.unregister(dst).await;
bail!("failed to send message");