Skip to content

Commit

Permalink
Specify the unit of the rate limit period by adding secs as suffix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kannapoix committed Sep 28, 2024
1 parent df74d7c commit 711a7b6
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config_spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ default = "10"
doc = "The number of calls each peer is allowed to make within the rate limit period. This value determines the maximum number of requests a peer can send before being rate limited."

[[param]]
name = "rate_limit_period"
name = "rate_limit_period_secs"
type = "u64"
default = "1"
doc = "The duration of the rate limit period in seconds. This value specifies the time window over which the rate limit count is applied."
2 changes: 1 addition & 1 deletion sample-lndk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ response_invoice_timeout=15

# Rate limits for onion messaging. Followings are the default values.
# rate_limit_count=1
# rate_limit_period=10
# rate_limit_period_secs=10
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub struct Cfg {
pub signals: LifecycleSignals,
pub skip_version_check: bool,
pub rate_limit_count: u8,
pub rate_limit_period: u64,
pub rate_limit_period_secs: u64,
}

#[derive(Clone)]
Expand Down Expand Up @@ -241,7 +241,7 @@ impl LndkOnionMessenger {
args.signals,
RateLimiterCfg {
call_count: args.rate_limit_count,
call_period: Duration::from_secs(args.rate_limit_period),
call_period_secs: Duration::from_secs(args.rate_limit_period_secs),
},
)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn main() -> Result<(), ()> {
signals,
skip_version_check: config.skip_version_check,
rate_limit_count: config.rate_limit_count,
rate_limit_period: config.rate_limit_period,
rate_limit_period_secs: config.rate_limit_period_secs,

Check warning on line 58 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L57-L58

Added lines #L57 - L58 were not covered by tests
};

let response_invoice_timeout = config.response_invoice_timeout;
Expand Down
2 changes: 1 addition & 1 deletion src/onion_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl LndkOnionMessenger {
let rate_limiter = &mut TokenLimiter::new(
current_peers.keys().copied(),
rate_limiter_cfg.call_count,
rate_limiter_cfg.call_period,
rate_limiter_cfg.call_period_secs,
TokioClock::new(),
);
let mut message_sender = CustomMessenger {
Expand Down
2 changes: 1 addition & 1 deletion src/rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) struct TokenLimiter<C: Clock> {

pub(crate) struct RateLimiterCfg {
pub(crate) call_count: u8,
pub(crate) call_period: Duration,
pub(crate) call_period_secs: Duration,
}

impl<C: Clock> TokenLimiter<C> {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub async fn setup_lndk(
signals,
skip_version_check: false,
rate_limit_count: 10,
rate_limit_period: 1,
rate_limit_period_secs: 1,
};

// Make sure lndk successfully sends the invoice_request.
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async fn test_lndk_send_invoice_request() {
signals,
skip_version_check: false,
rate_limit_count: 10,
rate_limit_period: 1,
rate_limit_period_secs: 1,
};

let mut client = lnd.client.clone().unwrap();
Expand Down Expand Up @@ -263,7 +263,7 @@ async fn test_lndk_send_invoice_request() {
signals,
skip_version_check: false,
rate_limit_count: 10,
rate_limit_period: 1,
rate_limit_period_secs: 1,
};

let log_dir = Some(
Expand Down

0 comments on commit 711a7b6

Please sign in to comment.