Skip to content

Commit

Permalink
Use a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
flub committed May 7, 2024
1 parent e55e290 commit 4b80cb0
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions iroh-net/src/magic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,23 +717,7 @@ impl Connecting {
pub fn into_0rtt(self) -> Result<(quinn::Connection, quinn::ZeroRttAccepted), Self> {
match self.inner.into_0rtt() {
Ok((conn, zrtt_accepted)) => {
// If we can't notify the rtt-actor that's not great but not critical.
let Ok(peer_id) = get_remote_node_id(&conn) else {
warn!(?conn, "failed to get remote node id");
return Ok((conn, zrtt_accepted));
};
let Ok(conn_type_changes) = self.magic_ep.conn_type_stream(&peer_id) else {
warn!(?conn, "failed to create conn_type_stream");
return Ok((conn, zrtt_accepted));
};
let rtt_msg = RttMessage::NewConnection {
connection: conn.weak_handle(),
conn_type_changes,
node_id: peer_id,
};
if let Err(err) = self.magic_ep.rtt_actor.msg_tx.try_send(rtt_msg) {
warn!(?conn, "rtt-actor not reachable: {err:#}");
}
try_send_rtt_msg(&conn, &self.magic_ep);
Ok((conn, zrtt_accepted))
}
Err(inner) => Err(Self {
Expand Down Expand Up @@ -782,23 +766,7 @@ impl Future for Connecting {
Poll::Pending => Poll::Pending,
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
Poll::Ready(Ok(conn)) => {
// If we can't notify the rtt-actor that's not great but not critical.
let Ok(peer_id) = get_remote_node_id(&conn) else {
warn!(?conn, "failed to get remote node id");
return Poll::Ready(Ok(conn));
};
let Ok(conn_type_changes) = this.magic_ep.conn_type_stream(&peer_id) else {
warn!(?conn, "failed to create conn_type_stream");
return Poll::Ready(Ok(conn));
};
let rtt_msg = RttMessage::NewConnection {
connection: conn.weak_handle(),
conn_type_changes,
node_id: peer_id,
};
if let Err(err) = this.magic_ep.rtt_actor.msg_tx.try_send(rtt_msg) {
warn!(?conn, "rtt-actor not reachable: {err:#}");
}
try_send_rtt_msg(&conn, &this.magic_ep);
Poll::Ready(Ok(conn))
}
}
Expand Down Expand Up @@ -826,6 +794,30 @@ pub fn get_remote_node_id(connection: &quinn::Connection) -> Result<PublicKey> {
}
}

/// Try send a message to the rtt-actor.
///
/// If we can't notify the actor that will impact performance a little, but we can still
/// function.
fn try_send_rtt_msg(conn: &quinn::Connection, magic_ep: &MagicEndpoint) {
// If we can't notify the rtt-actor that's not great but not critical.
let Ok(peer_id) = get_remote_node_id(conn) else {
warn!(?conn, "failed to get remote node id");
return;
};
let Ok(conn_type_changes) = magic_ep.conn_type_stream(&peer_id) else {
warn!(?conn, "failed to create conn_type_stream");
return;
};
let rtt_msg = RttMessage::NewConnection {
connection: conn.weak_handle(),
conn_type_changes,
node_id: peer_id,
};
if let Err(err) = magic_ep.rtt_actor.msg_tx.try_send(rtt_msg) {
warn!(?conn, "rtt-actor not reachable: {err:#}");
}
}

// TODO: These tests could still be flaky, lets fix that:
// https://github.com/n0-computer/iroh/issues/1183
#[cfg(test)]
Expand Down

0 comments on commit 4b80cb0

Please sign in to comment.