node: Add `--tracking-policy` flag
Sets the default tracking policy.
This commit is contained in:
parent
97a2f8c1df
commit
11da344e3a
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{env, net, process};
|
use std::{env, net, process};
|
||||||
|
|
||||||
|
use anyhow::anyhow;
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use crossbeam_channel as chan;
|
use crossbeam_channel as chan;
|
||||||
use cyphernet::addr::PeerAddr;
|
use cyphernet::addr::PeerAddr;
|
||||||
|
|
@ -8,6 +9,7 @@ use localtime::LocalDuration;
|
||||||
use radicle::profile;
|
use radicle::profile;
|
||||||
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
||||||
use radicle_node::prelude::{Address, NodeId};
|
use radicle_node::prelude::{Address, NodeId};
|
||||||
|
use radicle_node::service::tracking::Policy;
|
||||||
use radicle_node::Runtime;
|
use radicle_node::Runtime;
|
||||||
use radicle_node::{logger, service, signals};
|
use radicle_node::{logger, service, signals};
|
||||||
|
|
||||||
|
|
@ -21,6 +23,7 @@ Options
|
||||||
--connect <peer> Connect to the given peer address on start
|
--connect <peer> Connect to the given peer address on start
|
||||||
--external-address <address> Publicly accessible address (default 0.0.0.0:8776)
|
--external-address <address> Publicly accessible address (default 0.0.0.0:8776)
|
||||||
--git-daemon <address> Address to bind git-daemon to (default 0.0.0.0:9418)
|
--git-daemon <address> Address to bind git-daemon to (default 0.0.0.0:9418)
|
||||||
|
--tracking-policy (track|block) Default tracking policy
|
||||||
--help Print help
|
--help Print help
|
||||||
--listen <address> Address to listen on
|
--listen <address> Address to listen on
|
||||||
|
|
||||||
|
|
@ -33,6 +36,7 @@ struct Options {
|
||||||
daemon: Option<net::SocketAddr>,
|
daemon: Option<net::SocketAddr>,
|
||||||
limits: service::config::Limits,
|
limits: service::config::Limits,
|
||||||
listen: Vec<net::SocketAddr>,
|
listen: Vec<net::SocketAddr>,
|
||||||
|
tracking_policy: Policy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
|
|
@ -45,6 +49,7 @@ impl Options {
|
||||||
let mut limits = service::config::Limits::default();
|
let mut limits = service::config::Limits::default();
|
||||||
let mut listen = Vec::new();
|
let mut listen = Vec::new();
|
||||||
let mut daemon = None;
|
let mut daemon = None;
|
||||||
|
let mut tracking_policy = Policy::default();
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -60,6 +65,13 @@ impl Options {
|
||||||
let addr = parser.value()?.parse()?;
|
let addr = parser.value()?.parse()?;
|
||||||
daemon = Some(addr);
|
daemon = Some(addr);
|
||||||
}
|
}
|
||||||
|
Long("tracking-policy") => {
|
||||||
|
let policy = parser
|
||||||
|
.value()?
|
||||||
|
.parse()
|
||||||
|
.map_err(|s| anyhow!("unknown tracking policy {:?}", s))?;
|
||||||
|
tracking_policy = policy;
|
||||||
|
}
|
||||||
Long("limit-routing-max-age") => {
|
Long("limit-routing-max-age") => {
|
||||||
let secs: u64 = parser.value()?.parse()?;
|
let secs: u64 = parser.value()?.parse()?;
|
||||||
limits.routing_max_age = LocalDuration::from_secs(secs);
|
limits.routing_max_age = LocalDuration::from_secs(secs);
|
||||||
|
|
@ -92,6 +104,7 @@ impl Options {
|
||||||
external_addresses,
|
external_addresses,
|
||||||
limits,
|
limits,
|
||||||
listen,
|
listen,
|
||||||
|
tracking_policy,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +123,7 @@ fn execute() -> anyhow::Result<()> {
|
||||||
connect: options.connect.into_iter().collect(),
|
connect: options.connect.into_iter().collect(),
|
||||||
external_addresses: options.external_addresses,
|
external_addresses: options.external_addresses,
|
||||||
limits: options.limits,
|
limits: options.limits,
|
||||||
|
policy: options.tracking_policy,
|
||||||
..service::Config::default()
|
..service::Config::default()
|
||||||
};
|
};
|
||||||
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ impl<G: Signer + Ecdh + 'static> Runtime<G> {
|
||||||
let tracking = tracking::Store::open(tracking_db)?;
|
let tracking = tracking::Store::open(tracking_db)?;
|
||||||
let tracking = tracking::Config::new(config.policy, tracking);
|
let tracking = tracking::Config::new(config.policy, tracking);
|
||||||
|
|
||||||
|
log::info!(target: "node", "Default tracking policy set to '{}'", &config.policy);
|
||||||
log::info!(target: "node", "Initializing service ({:?})..", network);
|
log::info!(target: "node", "Initializing service ({:?})..", network);
|
||||||
let service = service::Service::new(
|
let service = service::Service::new(
|
||||||
config,
|
config,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl Default for Config {
|
||||||
network: Network::default(),
|
network: Network::default(),
|
||||||
relay: true,
|
relay: true,
|
||||||
limits: Limits::default(),
|
limits: Limits::default(),
|
||||||
policy: Policy::Block,
|
policy: Policy::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
mod store;
|
mod store;
|
||||||
|
|
||||||
use std::ops;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::{fmt, ops};
|
||||||
|
|
||||||
use crate::prelude::Id;
|
use crate::prelude::Id;
|
||||||
use crate::service::NodeId;
|
use crate::service::NodeId;
|
||||||
|
|
@ -13,14 +13,36 @@ pub use store::Error;
|
||||||
pub type Alias = String;
|
pub type Alias = String;
|
||||||
|
|
||||||
/// Tracking policy.
|
/// Tracking policy.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Policy {
|
pub enum Policy {
|
||||||
/// The resource is tracked.
|
/// The resource is tracked.
|
||||||
Track,
|
Track,
|
||||||
/// The resource is blocked.
|
/// The resource is blocked.
|
||||||
|
#[default]
|
||||||
Block,
|
Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Policy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Track => write!(f, "track"),
|
||||||
|
Self::Block => write!(f, "block"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Policy {
|
||||||
|
type Err = String;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"track" => Ok(Self::Track),
|
||||||
|
"block" => Ok(Self::Block),
|
||||||
|
_ => Err(s.to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Tracking scope of a repository tracking policy.
|
/// Tracking scope of a repository tracking policy.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Scope {
|
pub enum Scope {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue