use std::path::PathBuf;
use std::time::Duration;
use malachite_types::{ThresholdParams, TimeoutKind};
#[derive(Clone, Debug, Default)]
pub struct Config<A> {
pub address: A,
pub initial_height: u64,
pub timeout_values: TimeoutValues,
pub history_depth: u64,
pub wal_dir: PathBuf,
pub(crate) threshold_params: ThresholdParams,
}
impl<A: Default> Config<A> {
pub fn new(address: A) -> Self {
Self {
address,
history_depth: 10,
wal_dir: PathBuf::from("wal"),
..Default::default()
}
}
pub fn with_initial_height(mut self, height: u64) -> Self {
self.initial_height = height;
self
}
pub fn with_timeout_values(mut self, timeout_values: TimeoutValues) -> Self {
self.timeout_values = timeout_values;
self
}
pub fn with_history_depth(mut self, history_depth: u64) -> Self {
self.history_depth = history_depth;
self
}
pub fn with_wal_dir(mut self, wal_dir: PathBuf) -> Self {
self.wal_dir = wal_dir;
self
}
}
#[derive(Debug, Clone)]
pub struct TimeoutValues {
pub propose: Duration,
pub prevote: Duration,
pub precommit: Duration,
pub rebroadcast: Duration,
}
impl Default for TimeoutValues {
fn default() -> Self {
Self {
propose: Duration::from_secs(10),
prevote: Duration::from_secs(10),
precommit: Duration::from_secs(10),
rebroadcast: Duration::from_secs(10),
}
}
}
impl TimeoutValues {
pub fn get(&self, kind: TimeoutKind) -> Duration {
match kind {
TimeoutKind::Propose => self.propose,
TimeoutKind::Prevote => self.prevote,
TimeoutKind::Precommit => self.precommit,
TimeoutKind::Rebroadcast => self.rebroadcast,
}
}
}