Skip to content

Commit

Permalink
Configured ack and gc_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Dec 8, 2023
1 parent 697c526 commit 409eddb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
8 changes: 8 additions & 0 deletions config/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ uri = "http://mainnet-config.helium.io:6080/"
[router]
uri = "http://mainnet-router.helium.io:8080/"
# Maximum number of packets to queue up for the packet router
# Do NOT set hiher than 25 to avoid hpr rate limiting restrictions
queue = 20
# When non 0, the numnber of seconds to expect an ack for uplink packets
#
# ack_timeout = 0

# maximum time a packet is queued for before considered to stale to uplink.
# Default is 60s
#
# gc_timeout = 60
10 changes: 5 additions & 5 deletions src/packet_router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ use helium_proto::services::router::{
};
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::time::Instant as StdInstant;
use tokio::time::Duration;
use std::time::{Duration, Instant as StdInstant};
use tracing::{debug, info, warn};

const STORE_GC_INTERVAL: Duration = Duration::from_secs(60);

#[derive(Debug)]
pub enum Message {
Uplink {
Expand Down Expand Up @@ -57,6 +54,7 @@ pub struct PacketRouter {
service: PacketRouterService,
reconnect: Reconnect,
ack_timer: AckTimer,
gc_timeout: Duration,
store: MessageCache<PacketUp>,
}

Expand All @@ -81,13 +79,15 @@ impl PacketRouter {
let store = MessageCache::new(router_settings.queue);
let reconnect = Reconnect::default();
let ack_timer = AckTimer::new(router_settings.ack_timeout(), false);
let gc_timeout = router_settings.gc_timeout();
Self {
service,
transmit,
messages,
store,
reconnect,
ack_timer,
gc_timeout,
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ impl PacketRouter {
}

async fn send_unacked_packets(&mut self) -> Result {
while let (removed, Some(packet)) = self.store.pop_front(STORE_GC_INTERVAL) {
while let (removed, Some(packet)) = self.store.pop_front(self.gc_timeout) {
if removed > 0 {
info!(removed, "discarded queued packets");
}
Expand Down
17 changes: 14 additions & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ pub struct RouterSettings {
pub queue: u16,
/// Timeout for packet acks in seconds
#[serde(default = "default_ack_timeout")]
pub ack: u64,
pub ack_timeout: u64,
#[serde(default = "default_gc_timeout")]
pub gc_timeout: u64,
}

impl RouterSettings {
pub fn ack_timeout(&self) -> Duration {
Duration::from_secs(self.ack)
Duration::from_secs(self.ack_timeout)
}

pub fn gc_timeout(&self) -> Duration {
Duration::from_secs(self.gc_timeout)
}
}

Expand Down Expand Up @@ -161,10 +167,15 @@ fn default_poc_interval() -> u64 {
}

fn default_ack_timeout() -> u64 {
// disabled = 0
// in seconds, disabled = 0
0
}

fn default_gc_timeout() -> u64 {
// 60 seconds
60
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, clap::ValueEnum)]
#[clap(rename_all = "lower")]
#[repr(u8)]
Expand Down

0 comments on commit 409eddb

Please sign in to comment.