mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
84 lines
3.3 KiB
Rust
84 lines
3.3 KiB
Rust
use std::{collections::HashSet, fmt, sync::Arc, time};
|
|
|
|
use crossbeam_channel as chan;
|
|
use radicle::crypto::PublicKey;
|
|
use radicle::node::policy::config as policy;
|
|
use radicle::node::policy::Scope;
|
|
use radicle::node::routing;
|
|
use radicle::node::FetchResult;
|
|
use radicle::node::Seeds;
|
|
use radicle::node::{Address, Alias, Config, ConnectOptions};
|
|
use radicle::storage;
|
|
use radicle::storage::refs::RefsAt;
|
|
use radicle_core::{NodeId, RepoId};
|
|
|
|
use super::ServiceState;
|
|
|
|
/// Function used to query internal service state.
|
|
pub type QueryState = dyn Fn(&dyn ServiceState) -> Result<(), CommandError> + Send + Sync;
|
|
|
|
/// Commands sent to the service by the operator.
|
|
pub enum Command {
|
|
/// Announce repository references for given repository and namespaces to peers.
|
|
AnnounceRefs(RepoId, HashSet<PublicKey>, chan::Sender<RefsAt>),
|
|
/// Announce local repositories to peers.
|
|
AnnounceInventory,
|
|
/// Add repository to local inventory.
|
|
AddInventory(RepoId, chan::Sender<bool>),
|
|
/// Connect to node with the given address.
|
|
Connect(NodeId, Address, ConnectOptions),
|
|
/// Disconnect from node.
|
|
Disconnect(NodeId),
|
|
/// Get the node configuration.
|
|
Config(chan::Sender<Config>),
|
|
/// Get the node's listen addresses.
|
|
ListenAddrs(chan::Sender<Vec<std::net::SocketAddr>>),
|
|
/// Lookup seeds for the given repository in the routing table, and report
|
|
/// sync status for given namespaces.
|
|
Seeds(RepoId, HashSet<PublicKey>, chan::Sender<Seeds>),
|
|
/// Fetch the given repository from the network.
|
|
Fetch(RepoId, NodeId, time::Duration, chan::Sender<FetchResult>),
|
|
/// Seed the given repository.
|
|
Seed(RepoId, Scope, chan::Sender<bool>),
|
|
/// Unseed the given repository.
|
|
Unseed(RepoId, chan::Sender<bool>),
|
|
/// Follow the given node.
|
|
Follow(NodeId, Option<Alias>, chan::Sender<bool>),
|
|
/// Unfollow the given node.
|
|
Unfollow(NodeId, chan::Sender<bool>),
|
|
/// Query the internal service state.
|
|
QueryState(Arc<QueryState>, chan::Sender<Result<(), CommandError>>),
|
|
}
|
|
|
|
impl fmt::Debug for Command {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::AnnounceRefs(id, _, _) => write!(f, "AnnounceRefs({id})"),
|
|
Self::AnnounceInventory => write!(f, "AnnounceInventory"),
|
|
Self::AddInventory(rid, _) => write!(f, "AddInventory({rid})"),
|
|
Self::Connect(id, addr, opts) => write!(f, "Connect({id}, {addr}, {opts:?})"),
|
|
Self::Disconnect(id) => write!(f, "Disconnect({id})"),
|
|
Self::Config(_) => write!(f, "Config"),
|
|
Self::ListenAddrs(_) => write!(f, "ListenAddrs"),
|
|
Self::Seeds(id, _, _) => write!(f, "Seeds({id})"),
|
|
Self::Fetch(id, node, _, _) => write!(f, "Fetch({id}, {node})"),
|
|
Self::Seed(id, scope, _) => write!(f, "Seed({id}, {scope})"),
|
|
Self::Unseed(id, _) => write!(f, "Unseed({id})"),
|
|
Self::Follow(id, _, _) => write!(f, "Follow({id})"),
|
|
Self::Unfollow(id, _) => write!(f, "Unfollow({id})"),
|
|
Self::QueryState { .. } => write!(f, "QueryState(..)"),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Command-related errors.
|
|
#[derive(thiserror::Error, Debug)]
|
|
pub enum CommandError {
|
|
#[error(transparent)]
|
|
Storage(#[from] storage::Error),
|
|
#[error(transparent)]
|
|
Routing(#[from] routing::Error),
|
|
#[error(transparent)]
|
|
Policy(#[from] policy::Error),
|
|
}
|