use std::str::FromStr;
use casper_types::TimeDiff;
use datasize::DataSize;
use serde::{Deserialize, Serialize};
const DEFAULT_ADDRESS: &str = "0.0.0.0:0";
const DEFAULT_MAX_MESSAGE_SIZE: u32 = 4 * 1024 * 1024;
const DEFAULT_MAX_CONNECTIONS: usize = 5;
const DEFAULT_QPS_LIMIT: usize = 110;
const DEFAULT_INITIAL_CONNECTION_LIFETIME: &str = "10 seconds";
const DEFAULT_GET_RECORD_REQUEST_TERMINATION_DELAY: &str = "0 seconds";
const DEFAULT_GET_INFORMATION_REQUEST_TERMINATION_DELAY: &str = "5 seconds";
const DEFAULT_GET_STATE_REQUEST_TERMINATION_DELAY: &str = "0 seconds";
const DEFAULT_GET_TRIE_REQUEST_TERMINATION_DELAY: &str = "0 seconds";
const DEFAULT_ACCEPT_TRANSACTION_REQUEST_TERMINATION_DELAY: &str = "24 seconds";
const DEFAULT_SPECULATIVE_EXEC_REQUEST_TERMINATION_DELAY: &str = "0 seconds";
#[derive(Clone, DataSize, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub enable_server: bool,
pub address: String,
pub allow_request_get_all_values: bool,
pub allow_request_get_trie: bool,
pub allow_request_speculative_exec: bool,
pub max_message_size_bytes: u32,
pub max_connections: usize,
pub qps_limit: usize,
pub initial_connection_lifetime: TimeDiff,
pub get_record_request_termination_delay: TimeDiff,
pub get_information_request_termination_delay: TimeDiff,
pub get_state_request_termination_delay: TimeDiff,
pub get_trie_request_termination_delay: TimeDiff,
pub accept_transaction_request_termination_delay: TimeDiff,
pub speculative_exec_request_termination_delay: TimeDiff,
}
impl Config {
pub fn new() -> Self {
Config {
enable_server: true,
address: DEFAULT_ADDRESS.to_string(),
allow_request_get_all_values: false,
allow_request_get_trie: false,
allow_request_speculative_exec: false,
max_message_size_bytes: DEFAULT_MAX_MESSAGE_SIZE,
max_connections: DEFAULT_MAX_CONNECTIONS,
qps_limit: DEFAULT_QPS_LIMIT,
initial_connection_lifetime: TimeDiff::from_str(DEFAULT_INITIAL_CONNECTION_LIFETIME)
.unwrap(),
get_record_request_termination_delay: TimeDiff::from_str(
DEFAULT_GET_RECORD_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
get_information_request_termination_delay: TimeDiff::from_str(
DEFAULT_GET_INFORMATION_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
get_state_request_termination_delay: TimeDiff::from_str(
DEFAULT_GET_STATE_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
get_trie_request_termination_delay: TimeDiff::from_str(
DEFAULT_GET_TRIE_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
accept_transaction_request_termination_delay: TimeDiff::from_str(
DEFAULT_ACCEPT_TRANSACTION_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
speculative_exec_request_termination_delay: TimeDiff::from_str(
DEFAULT_SPECULATIVE_EXEC_REQUEST_TERMINATION_DELAY,
)
.unwrap(),
}
}
}
impl Default for Config {
fn default() -> Self {
Config::new()
}
}