Add fields to zebra-network Config.
This commit is contained in:
parent
0a56830eab
commit
63cf340ab4
|
|
@ -1,15 +1,33 @@
|
||||||
|
use std::{net::SocketAddr, time::Duration};
|
||||||
|
|
||||||
|
use crate::network::Network;
|
||||||
|
|
||||||
/// Configuration for networking code.
|
/// Configuration for networking code.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
/// The network to connect to.
|
||||||
|
pub network: Network,
|
||||||
/// The user-agent to advertise.
|
/// The user-agent to advertise.
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
|
/// 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config {
|
||||||
user_agent: crate::constants::USER_AGENT.to_owned(),
|
user_agent: crate::constants::USER_AGENT.to_owned(),
|
||||||
|
network: Network::Mainnet,
|
||||||
|
initial_peers: Vec::new(),
|
||||||
|
ewma_default_rtt: Duration::from_secs(1),
|
||||||
|
ewma_decay_time: Duration::from_secs(60),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{constants::magics, protocol::types::Magic};
|
use crate::{constants::magics, protocol::types::Magic};
|
||||||
|
|
||||||
/// An enum describing the possible network choices.
|
/// An enum describing the possible network choices.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
pub enum Network {
|
pub enum Network {
|
||||||
/// The production mainnet.
|
/// The production mainnet.
|
||||||
Mainnet,
|
Mainnet,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ use super::{error::ErrorSlot, server::ServerState, HandshakeError, PeerClient, P
|
||||||
/// A [`Service`] that connects to a remote peer and constructs a client/server pair.
|
/// A [`Service`] that connects to a remote peer and constructs a client/server pair.
|
||||||
pub struct PeerConnector<S> {
|
pub struct PeerConnector<S> {
|
||||||
config: Config,
|
config: Config,
|
||||||
network: Network,
|
|
||||||
internal_service: S,
|
internal_service: S,
|
||||||
sender: mpsc::Sender<PeerLastSeen>,
|
sender: mpsc::Sender<PeerLastSeen>,
|
||||||
nonces: Arc<Mutex<HashSet<Nonce>>>,
|
nonces: Arc<Mutex<HashSet<Nonce>>>,
|
||||||
|
|
@ -39,12 +38,7 @@ where
|
||||||
S::Future: Send,
|
S::Future: Send,
|
||||||
{
|
{
|
||||||
/// Construct a new `PeerConnector`.
|
/// Construct a new `PeerConnector`.
|
||||||
pub fn new(
|
pub fn new(config: Config, internal_service: S, collector: &TimestampCollector) -> Self {
|
||||||
config: Config,
|
|
||||||
network: Network,
|
|
||||||
internal_service: S,
|
|
||||||
collector: &TimestampCollector,
|
|
||||||
) -> Self {
|
|
||||||
// XXX this function has too many parameters, but it's not clear how to
|
// XXX this function has too many parameters, but it's not clear how to
|
||||||
// do a nice builder as all fields are mandatory. Could have Builder1,
|
// do a nice builder as all fields are mandatory. Could have Builder1,
|
||||||
// Builder2, ..., with Builder1::with_config() -> Builder2;
|
// Builder2, ..., with Builder1::with_config() -> Builder2;
|
||||||
|
|
@ -53,7 +47,6 @@ where
|
||||||
let sender = collector.sender_handle();
|
let sender = collector.sender_handle();
|
||||||
PeerConnector {
|
PeerConnector {
|
||||||
config,
|
config,
|
||||||
network,
|
|
||||||
internal_service,
|
internal_service,
|
||||||
sender,
|
sender,
|
||||||
nonces: Arc::new(Mutex::new(HashSet::new())),
|
nonces: Arc::new(Mutex::new(HashSet::new())),
|
||||||
|
|
@ -82,11 +75,11 @@ where
|
||||||
let connection_span = span!(Level::INFO, "peer", addr = ?addr);
|
let connection_span = span!(Level::INFO, "peer", addr = ?addr);
|
||||||
|
|
||||||
// Clone these upfront, so they can be moved into the future.
|
// Clone these upfront, so they can be moved into the future.
|
||||||
let network = self.network.clone();
|
let nonces = self.nonces.clone();
|
||||||
let internal_service = self.internal_service.clone();
|
let internal_service = self.internal_service.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let user_agent = self.config.user_agent.clone();
|
let user_agent = self.config.user_agent.clone();
|
||||||
let nonces = self.nonces.clone();
|
let network = self.config.network.clone();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
info!("connecting to remote peer");
|
info!("connecting to remote peer");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue