2019-10-16 15:16:29 -07:00
|
|
|
use std::{net::SocketAddr, time::Duration};
|
|
|
|
|
|
|
|
use crate::network::Network;
|
|
|
|
|
2019-10-08 13:57:24 -07:00
|
|
|
/// Configuration for networking code.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
pub struct Config {
|
2019-10-16 18:29:45 -07:00
|
|
|
/// The address on which this node should listen for connections.
|
|
|
|
pub listen_addr: SocketAddr,
|
2019-10-16 15:16:29 -07:00
|
|
|
/// The network to connect to.
|
|
|
|
pub network: Network,
|
2019-10-08 13:57:24 -07:00
|
|
|
/// The user-agent to advertise.
|
|
|
|
pub user_agent: String,
|
2019-10-16 15:16:29 -07:00
|
|
|
/// A list of initial peers for the peerset.
|
|
|
|
///
|
|
|
|
/// XXX this should be replaced with DNS names, not SocketAddrs
|
|
|
|
pub initial_peers: Vec<SocketAddr>,
|
|
|
|
/// The default RTT estimate for peer responses, used in load-balancing.
|
|
|
|
pub ewma_default_rtt: Duration,
|
|
|
|
/// The decay time for the exponentially-weighted moving average response time.
|
|
|
|
pub ewma_decay_time: Duration,
|
2019-10-21 15:24:17 -07:00
|
|
|
/// The outgoing request buffer size for the peer set.
|
|
|
|
pub peerset_request_buffer_size: usize,
|
2019-10-08 13:57:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Config {
|
|
|
|
Config {
|
2019-10-16 18:29:45 -07:00
|
|
|
listen_addr: "127.0.0.1:28233"
|
|
|
|
.parse()
|
|
|
|
.expect("Hardcoded address should be parseable"),
|
2019-10-08 13:57:24 -07:00
|
|
|
user_agent: crate::constants::USER_AGENT.to_owned(),
|
2019-10-16 15:16:29 -07:00
|
|
|
network: Network::Mainnet,
|
|
|
|
initial_peers: Vec::new(),
|
|
|
|
ewma_default_rtt: Duration::from_secs(1),
|
|
|
|
ewma_decay_time: Duration::from_secs(60),
|
2019-10-21 15:24:17 -07:00
|
|
|
peerset_request_buffer_size: 1,
|
2019-10-08 13:57:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|