Skip to content

Commit

Permalink
sdk: add PING_INTERVAL const
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 6, 2023
1 parent faceb69 commit 7282f09
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/nostr-sdk/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use crate::RUNTIME;
type Message = (RelayEvent, Option<oneshot::Sender<bool>>);

const MIN_UPTIME: f64 = 0.90;
#[cfg(not(target_arch = "wasm32"))]
const PING_INTERVAL: u64 = 55;

/// [`Relay`] error
#[derive(Debug, Error)]
Expand Down Expand Up @@ -343,7 +345,9 @@ impl RelayConnectionStats {
}

pub(crate) fn add_bytes_received(&self, size: usize) {
self.bytes_received.fetch_add(size, Ordering::SeqCst);
if size > 0 {
self.bytes_received.fetch_add(size, Ordering::SeqCst);
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -812,7 +816,7 @@ impl Relay {
tracing::error!("Impossible to ping {}: {e}", relay.url);
break;
};
thread::sleep(Duration::from_secs(60)).await;
thread::sleep(Duration::from_secs(PING_INTERVAL)).await;
}

tracing::debug!("Exited from Ping Thread of {}", relay.url);
Expand Down

0 comments on commit 7282f09

Please sign in to comment.