Skip to content

Commit

Permalink
Add events for being connected to relays, and home relays.
Browse files Browse the repository at this point in the history
  • Loading branch information
flub committed Jan 8, 2025
1 parent 39027c4 commit ad6f463
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions iroh/src/magicsock/relay_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use tokio::{
time::{Duration, Instant, MissedTickBehavior},
};
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, info, info_span, instrument, trace, warn, Instrument};
use tracing::{debug, error, event, info_span, instrument, trace, warn, Instrument, Level};
use url::Url;

use super::RelayDatagramSendChannelReceiver;
Expand Down Expand Up @@ -288,6 +288,18 @@ impl ActiveRelayActor {
.reset(Instant::now() + RELAY_INACTIVE_CLEANUP_TIME);
}

fn set_home_relay(&mut self, is_home: bool) {
let prev = std::mem::replace(&mut self.is_home_relay, is_home);
if self.is_home_relay != prev {
event!(
target: "iroh::_events::relay::home_changed",
Level::DEBUG,
url = %self.url,
home_relay = self.is_home_relay,
);
}
}

/// Actor loop when connecting to the relay server.
///
/// Returns `None` if the actor needs to shut down. Returns `Some(client)` when the
Expand Down Expand Up @@ -341,8 +353,8 @@ impl ActiveRelayActor {
break None;
};
match msg {
ActiveRelayMessage::SetHomeRelay(is_preferred) => {
self.is_home_relay = is_preferred;
ActiveRelayMessage::SetHomeRelay(is_home) => {
self.set_home_relay(is_home);
}
ActiveRelayMessage::CheckConnection(_local_ips) => {}
#[cfg(test)]
Expand Down Expand Up @@ -412,6 +424,12 @@ impl ActiveRelayActor {
/// to the relay server is lost.
async fn run_connected(&mut self, client: iroh_relay::client::Client) -> Result<()> {
debug!("Actor loop: connected to relay");
event!(
target: "iroh::_events::relay::connected",
Level::DEBUG,
url = %self.url,
home_relay = self.is_home_relay,
);

let (mut client_stream, mut client_sink) = client.split();

Expand Down Expand Up @@ -458,8 +476,8 @@ impl ActiveRelayActor {
break Ok(());
};
match msg {
ActiveRelayMessage::SetHomeRelay(is_preferred) => {
self.is_home_relay = is_preferred;
ActiveRelayMessage::SetHomeRelay(is_home) => {
self.set_home_relay(is_home);
}
ActiveRelayMessage::CheckConnection(local_ips) => {
match client_stream.local_addr() {
Expand Down

0 comments on commit ad6f463

Please sign in to comment.