Files
heartwood/radicle-node/src/service/config.rs
T
Dr Maxim Orlovsky aa02c52a2f node: Integrate new Noise_XK transport
This is a large change that introduces transport encryption via
a Noise_XK handshake. The inner `Service` now works directly
with `NodeId` and doesn't need to interact with socket addresses.

The transport logic takes place in `wire::transport`, and the
established sessions are passed down to `Service`.

Note that the i/o implementation in the `poll-reactor` crate still
needs testing, and there is still work to be done to integrate the
Git transport as part of this architecture.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-13 14:59:06 +01:00

86 lines
2.1 KiB
Rust

use super::nakamoto::LocalDuration;
use crate::service::message::Address;
use crate::service::NodeId;
/// Peer-to-peer network.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub enum Network {
#[default]
Main,
Test,
}
/// Configuration parameters defining attributes of minima and maxima.
#[derive(Debug, Clone)]
pub struct Limits {
/// Number of routing table entries before we start pruning.
pub routing_max_size: usize,
/// How long to keep a routing table entry before being pruned.
pub routing_max_age: LocalDuration,
}
impl Default for Limits {
fn default() -> Self {
Self {
routing_max_size: 1000,
routing_max_age: LocalDuration::from_mins(7 * 24 * 60),
}
}
}
/// Service configuration.
#[derive(Debug, Clone)]
pub struct Config {
/// Peers to connect to on startup.
/// Connections to these peers will be maintained.
pub connect: Vec<(NodeId, Address)>,
/// Specify the node's public addresses
pub external_addresses: Vec<Address>,
/// Peer-to-peer network.
pub network: Network,
/// Whether or not our node should relay inventories.
pub relay: bool,
/// List of addresses to listen on for protocol connections.
pub listen: Vec<Address>,
/// Configured service limits.
pub limits: Limits,
}
impl Default for Config {
fn default() -> Self {
Self {
connect: Vec::default(),
external_addresses: vec![],
network: Network::default(),
relay: true,
listen: vec![],
limits: Limits::default(),
}
}
}
impl Config {
pub fn new(network: Network) -> Self {
Self {
network,
..Self::default()
}
}
pub fn peer(&self, id: &NodeId) -> Option<&Address> {
self.connect.iter().find(|(i, _)| i == id).map(|(_, a)| a)
}
pub fn is_persistent(&self, id: &NodeId) -> bool {
self.connect.iter().any(|(i, _)| i == id)
}
pub fn alias(&self) -> [u8; 32] {
let mut alias = [0u8; 32];
alias[..9].copy_from_slice("anonymous".as_bytes());
alias
}
}