Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iroh-relay)!: Always allow acking pings #3011

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions iroh-relay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ pub enum ClientError {
/// The ping request was aborted
#[error("ping aborted")]
PingAborted,
/// This [`Client`] cannot acknowledge pings
#[error("cannot acknowledge pings")]
CannotAckPings,
/// The given [`Url`] is invalid
#[error("invalid url: {0}")]
InvalidUrl(String),
Expand Down Expand Up @@ -169,7 +166,6 @@ pub struct ClientReceiver {
#[derive(derive_more::Debug)]
struct Actor {
secret_key: SecretKey,
can_ack_pings: bool,
is_preferred: bool,
relay_conn: Option<(Conn, ConnReceiver)>,
is_closed: bool,
Expand Down Expand Up @@ -210,8 +206,6 @@ impl PingTracker {
/// Build a Client.
#[derive(derive_more::Debug)]
pub struct ClientBuilder {
/// Default is false
can_ack_pings: bool,
/// Default is false
is_preferred: bool,
/// Default is None
Expand All @@ -237,7 +231,6 @@ impl ClientBuilder {
/// Create a new [`ClientBuilder`]
pub fn new(url: impl Into<RelayUrl>) -> Self {
ClientBuilder {
can_ack_pings: false,
is_preferred: false,
address_family_selector: None,
is_prober: false,
Expand Down Expand Up @@ -277,12 +270,6 @@ impl ClientBuilder {
self
}

/// Enable this [`Client`] to acknowledge pings.
pub fn can_ack_pings(mut self, can: bool) -> Self {
self.can_ack_pings = can;
self
}

/// Indicate this client is the preferred way to communicate
/// to the peer with this client's [`PublicKey`]
pub fn is_preferred(mut self, is: bool) -> Self {
Expand Down Expand Up @@ -340,7 +327,6 @@ impl ClientBuilder {

let inner = Actor {
secret_key: key,
can_ack_pings: self.can_ack_pings,
is_preferred: self.is_preferred,
relay_conn: None,
is_closed: false,
Expand Down Expand Up @@ -829,16 +815,12 @@ impl Actor {

async fn send_pong(&mut self, data: [u8; 8]) -> Result<(), ClientError> {
debug!("send_pong");
if self.can_ack_pings {
let (conn, _) = self.connect("send_pong").await?;
if conn.send_pong(data).await.is_err() {
self.close_for_reconnect().await;
return Err(ClientError::Send);
}
Ok(())
} else {
Err(ClientError::CannotAckPings)
let (conn, _) = self.connect("send_pong").await?;
if conn.send_pong(data).await.is_err() {
self.close_for_reconnect().await;
return Err(ClientError::Send);
}
Ok(())
}

async fn close(mut self) {
Expand Down
1 change: 0 additions & 1 deletion iroh/src/magicsock/relay_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ impl RelayActor {
let ipv6_reported = ipv6_reported.clone();
Box::pin(async move { ipv6_reported.load(Ordering::Relaxed) })
})
.can_ack_pings(true)
.is_preferred(my_relay.as_ref() == Some(url));

#[cfg(any(test, feature = "test-utils"))]
Expand Down
Loading