nym_bandwidth_controller/config.rs
1// Copyright 2026 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use std::time::Duration;
5
6use nym_credentials_interface::TicketType;
7
8use crate::ticketbooks::AvailableTicketbooks;
9
10#[derive(Debug, Clone)]
11pub struct BandwidthControllerConfig {
12 // How often the controller proactively checks whether any ticket type needs restocking.
13 // It is also pruning any expired tickets from storage before restocking.
14 pub topup_interval: Duration,
15 // Threshold to determine if a ticket is soon expired
16 pub soon_expiry_threshold: Duration,
17
18 // If we go below this threshold, we should request more tickets
19 pub nb_ticket_restock: u64,
20
21 // If we go below this threshold, we should request more tickets
22 pub min_nb_ticket_needed: u64,
23
24 // Ticket types the controller proactively restocks: the periodic sweep, the post-spend top-up,
25 // and the restock triggered when a credential fetcher is installed. Defaults to every
26 // non-mixnet-exit type. Set to an empty vec to disable proactive restocking entirely — a
27 // credential fetcher can still be installed to serve on-demand / explicit fetches without the
28 // controller ever depositing on its own.
29 pub managed_ticket_types: Vec<TicketType>,
30}
31
32impl Default for BandwidthControllerConfig {
33 fn default() -> Self {
34 Self {
35 topup_interval: Duration::from_secs(3 * 3600), // 3 hours,
36 soon_expiry_threshold: Duration::from_secs(12 * 3600), // 12 hours,
37 nb_ticket_restock: 20,
38 min_nb_ticket_needed: 5,
39 managed_ticket_types: AvailableTicketbooks::ticketbook_types(),
40 }
41 }
42}