2024-01-03 10:24:52 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
|
2024-08-29 01:55:24 +00:00
|
|
|
mod batcher;
|
2024-01-03 10:24:52 +00:00
|
|
|
mod libp2p_event_handler;
|
2024-08-19 01:54:52 +00:00
|
|
|
mod metrics;
|
2024-01-03 10:24:52 +00:00
|
|
|
mod peer_manager;
|
|
|
|
mod service;
|
|
|
|
|
2024-07-08 10:45:55 +00:00
|
|
|
use duration_str::deserialize_duration;
|
2024-01-03 10:24:52 +00:00
|
|
|
use network::Multiaddr;
|
2024-07-08 10:45:55 +00:00
|
|
|
use serde::Deserialize;
|
|
|
|
use std::time::Duration;
|
2024-01-03 10:24:52 +00:00
|
|
|
|
|
|
|
pub use crate::service::RouterService;
|
|
|
|
|
2024-07-08 10:45:55 +00:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
#[serde(default)]
|
2024-01-03 10:24:52 +00:00
|
|
|
pub struct Config {
|
2024-07-08 10:45:55 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
|
|
pub heartbeat_interval: Duration,
|
|
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
|
|
pub idle_time: Duration,
|
2024-01-03 10:24:52 +00:00
|
|
|
pub max_idle_incoming_peers: usize,
|
|
|
|
pub max_idle_outgoing_peers: usize,
|
|
|
|
pub libp2p_nodes: Vec<Multiaddr>,
|
2024-07-08 10:45:55 +00:00
|
|
|
pub private_ip_enabled: bool,
|
2024-08-20 06:39:58 +00:00
|
|
|
pub check_announced_ip: bool,
|
2024-08-29 01:55:24 +00:00
|
|
|
|
|
|
|
// batcher
|
|
|
|
/// Timeout to publish messages in batch
|
|
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
|
|
pub batcher_timeout: Duration,
|
|
|
|
/// Number of files in an announcement
|
|
|
|
pub batcher_file_capacity: usize,
|
|
|
|
/// Number of announcements in a pubsub message
|
|
|
|
pub batcher_announcement_capacity: usize,
|
2024-01-03 10:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2024-07-08 10:45:55 +00:00
|
|
|
heartbeat_interval: Duration::from_secs(5),
|
|
|
|
idle_time: Duration::from_secs(180),
|
2024-01-03 10:24:52 +00:00
|
|
|
max_idle_incoming_peers: 12,
|
|
|
|
max_idle_outgoing_peers: 20,
|
|
|
|
libp2p_nodes: vec![],
|
2024-07-08 10:45:55 +00:00
|
|
|
private_ip_enabled: false,
|
2024-08-20 06:39:58 +00:00
|
|
|
check_announced_ip: false,
|
2024-08-29 01:55:24 +00:00
|
|
|
|
|
|
|
batcher_timeout: Duration::from_secs(1),
|
|
|
|
batcher_file_capacity: 1,
|
|
|
|
batcher_announcement_capacity: 1,
|
2024-01-03 10:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-08 10:45:55 +00:00
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn with_private_ip_enabled(mut self, enabled: bool) -> Self {
|
|
|
|
self.private_ip_enabled = enabled;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|