Skip to content

Commit

Permalink
feat: Add config option for retry interval
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Jul 15, 2021
1 parent 6ae26cb commit 6bba5ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub struct Config {
/// Duration of a UPnP port mapping.
#[structopt(long)]
pub upnp_lease_duration: Option<u32>,
/// Duration to wait before retrying to resend / reconnect
#[structopt(long, default_value = "500")]
pub retry_interval: u64,
}

/// To be used to read and write our certificate and private key to disk esp. as a part of our
Expand Down
7 changes: 2 additions & 5 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const STANDARD_CHANNEL_SIZE: usize = 10000;
/// Max number of attempts for connection retries
const MAX_ATTEMPTS: usize = 5;

/// How long to wait (ms) between retry attempts
const RETRY_INTERVAL: u64 = 500;

/// Channel on which incoming messages can be listened to
pub struct IncomingMessages(pub(crate) MpscReceiver<(SocketAddr, Bytes)>);

Expand Down Expand Up @@ -360,7 +357,7 @@ impl Endpoint {
let mut connecting = self.attempt_connection(node_addr).await;

while connecting.is_err() && attempts < MAX_ATTEMPTS {
sleep(Duration::from_millis(RETRY_INTERVAL)).await;
sleep(Duration::from_millis(self.qp2p_config.retry_interval)).await;
connecting = self.attempt_connection(node_addr).await;
attempts += 1;
}
Expand Down Expand Up @@ -527,7 +524,7 @@ impl Endpoint {
while attempts < MAX_ATTEMPTS && res.is_err() {
trace!("send attempt # {:?}", attempts);
attempts += 1;
sleep(Duration::from_millis(RETRY_INTERVAL)).await;
sleep(Duration::from_millis(self.qp2p_config.retry_interval)).await;
res = self.try_send_message(msg.clone(), dest).await;
}

Expand Down

0 comments on commit 6bba5ec

Please sign in to comment.