node: Rename `client` module to `runtime`

This commit is contained in:
Alexis Sellier 2023-01-29 17:33:07 +01:00
parent 02be334144
commit 23cf44f4c7
No known key found for this signature in database
9 changed files with 40 additions and 43 deletions

View File

@ -9,10 +9,10 @@ use std::{io, net};
use radicle::node::Handle;
use crate::client;
use crate::identity::Id;
use crate::node;
use crate::node::FetchLookup;
use crate::runtime;
#[derive(thiserror::Error, Debug)]
pub enum Error {
@ -23,7 +23,7 @@ pub enum Error {
}
/// Listen for commands on the control socket, and process them.
pub fn listen<H: Handle<Error = client::handle::Error>>(
pub fn listen<H: Handle<Error = runtime::HandleError>>(
listener: UnixListener,
mut handle: H,
) -> Result<(), Error> {
@ -62,15 +62,15 @@ enum DrainError {
InvalidCommandArg(String, Box<dyn std::error::Error>),
#[error("unknown command `{0}`")]
UnknownCommand(String),
#[error("client error: {0}")]
Client(#[from] client::handle::Error),
#[error("runtime error: {0}")]
Runtime(#[from] runtime::HandleError),
#[error("i/o error: {0}")]
Io(#[from] io::Error),
#[error("shutdown requested")]
Shutdown,
}
fn drain<H: Handle<Error = client::handle::Error>>(
fn drain<H: Handle<Error = runtime::HandleError>>(
stream: &UnixStream,
handle: &mut H,
) -> Result<(), DrainError> {
@ -104,7 +104,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
}
}
Err(e) => {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
},
Err(err) => {
@ -121,7 +121,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
}
}
Err(e) => {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
},
Err(err) => {
@ -144,7 +144,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
}
}
Err(e) => {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
},
Err(err) => {
@ -165,7 +165,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
}
}
Err(e) => {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
},
Err(err) => {
@ -175,7 +175,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
Some(("announce-refs", arg)) => match arg.parse() {
Ok(id) => {
if let Err(e) = handle.announce_refs(id) {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
writeln!(writer, "{}", node::RESPONSE_OK)?;
}
@ -197,7 +197,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
writeln!(writer, "{id} {seed}",)?;
}
}
Err(e) => return Err(DrainError::Client(e)),
Err(e) => return Err(DrainError::Runtime(e)),
},
"inventory" => match handle.inventory() {
Ok(c) => {
@ -205,7 +205,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
writeln!(writer, "{id}")?;
}
}
Err(e) => return Err(DrainError::Client(e)),
Err(e) => return Err(DrainError::Runtime(e)),
},
"shutdown" => {
return Err(DrainError::Shutdown);
@ -218,14 +218,14 @@ fn drain<H: Handle<Error = client::handle::Error>>(
Ok(())
}
fn fetch<W: Write, H: Handle<Error = client::handle::Error>>(
fn fetch<W: Write, H: Handle<Error = runtime::HandleError>>(
id: Id,
mut writer: W,
handle: &mut H,
) -> Result<(), DrainError> {
match handle.fetch(id) {
Err(e) => {
return Err(DrainError::Client(e));
return Err(DrainError::Runtime(e));
}
Ok(FetchLookup::Found { seeds, results }) => {
let seeds = Vec::from(seeds);

View File

@ -1,10 +1,10 @@
pub mod address;
pub mod bounded;
pub mod client;
pub mod clock;
pub mod control;
pub mod deserializer;
pub mod logger;
pub mod runtime;
pub mod service;
pub mod sql;
#[cfg(any(test, feature = "test"))]
@ -17,6 +17,7 @@ pub mod worker;
pub use localtime::{LocalDuration, LocalTime};
pub use netservices::LinkDirection as Link;
pub use radicle::{collections, crypto, git, identity, node, profile, rad, storage};
pub use runtime::Runtime;
pub mod prelude {
pub use crate::bounded::BoundedVec;

View File

@ -5,9 +5,9 @@ use cyphernet::addr::PeerAddr;
use localtime::LocalDuration;
use radicle::profile;
use radicle_node::client::Runtime;
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
use radicle_node::prelude::{Address, NodeId};
use radicle_node::Runtime;
use radicle_node::{logger, service};
#[derive(Debug)]

View File

@ -1,3 +1,5 @@
mod handle;
use std::io::{BufRead, BufReader};
use std::os::unix::net::UnixListener;
use std::path::PathBuf;
@ -22,8 +24,8 @@ use crate::wire::Wire;
use crate::worker::{WorkerPool, WorkerReq};
use crate::{crypto, service, LocalTime};
pub mod handle;
use handle::Handle;
pub use handle::Error as HandleError;
pub use handle::Handle;
/// Directory in `$RAD_HOME` under which node-specific files are stored.
pub const NODE_DIR: &str = "node";

View File

@ -3,9 +3,9 @@ use std::sync::{Arc, Mutex};
use crossbeam_channel as chan;
use crate::client::handle::Error;
use crate::identity::Id;
use crate::node::FetchLookup;
use crate::runtime::HandleError;
use crate::service;
use crate::service::NodeId;
@ -17,56 +17,56 @@ pub struct Handle {
}
impl radicle::node::Handle for Handle {
type Error = Error;
type Error = HandleError;
type Sessions = service::Sessions;
fn is_running(&self) -> bool {
true
}
fn connect(&mut self, _node: NodeId, _addr: radicle::node::Address) -> Result<(), Error> {
fn connect(&mut self, _node: NodeId, _addr: radicle::node::Address) -> Result<(), Self::Error> {
unimplemented!();
}
fn fetch(&mut self, _id: Id) -> Result<FetchLookup, Error> {
fn fetch(&mut self, _id: Id) -> Result<FetchLookup, Self::Error> {
Ok(FetchLookup::NotFound)
}
fn track_repo(&mut self, id: Id) -> Result<bool, Error> {
fn track_repo(&mut self, id: Id) -> Result<bool, Self::Error> {
Ok(self.tracking_repos.insert(id))
}
fn untrack_repo(&mut self, id: Id) -> Result<bool, Error> {
fn untrack_repo(&mut self, id: Id) -> Result<bool, Self::Error> {
Ok(self.tracking_repos.remove(&id))
}
fn track_node(&mut self, id: NodeId, _alias: Option<String>) -> Result<bool, Error> {
fn track_node(&mut self, id: NodeId, _alias: Option<String>) -> Result<bool, Self::Error> {
Ok(self.tracking_nodes.insert(id))
}
fn untrack_node(&mut self, id: NodeId) -> Result<bool, Error> {
fn untrack_node(&mut self, id: NodeId) -> Result<bool, Self::Error> {
Ok(self.tracking_nodes.remove(&id))
}
fn announce_refs(&mut self, id: Id) -> Result<(), Error> {
fn announce_refs(&mut self, id: Id) -> Result<(), Self::Error> {
self.updates.lock().unwrap().push(id);
Ok(())
}
fn routing(&self) -> Result<chan::Receiver<(Id, service::NodeId)>, Error> {
fn routing(&self) -> Result<chan::Receiver<(Id, service::NodeId)>, Self::Error> {
unimplemented!();
}
fn sessions(&self) -> Result<Self::Sessions, Error> {
fn sessions(&self) -> Result<Self::Sessions, Self::Error> {
unimplemented!();
}
fn inventory(&self) -> Result<chan::Receiver<Id>, Error> {
fn inventory(&self) -> Result<chan::Receiver<Id>, Self::Error> {
unimplemented!();
}
fn shutdown(self) -> Result<(), Error> {
fn shutdown(self) -> Result<(), Self::Error> {
Ok(())
}
}

View File

@ -33,7 +33,7 @@ use crate::test::storage::MockStorage;
use crate::wire::Decode;
use crate::wire::Encode;
use crate::LocalTime;
use crate::{client, git, identity, rad, service, test};
use crate::{git, identity, rad, runtime, service, test};
// NOTE
//
@ -343,19 +343,13 @@ fn test_tracking() {
let (sender, receiver) = chan::bounded(1);
alice.command(Command::TrackRepo(proj_id, sender));
let policy_change = receiver
.recv()
.map_err(client::handle::Error::from)
.unwrap();
let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap();
assert!(policy_change);
assert!(alice.tracking().is_repo_tracked(&proj_id).unwrap());
let (sender, receiver) = chan::bounded(1);
alice.command(Command::UntrackRepo(proj_id, sender));
let policy_change = receiver
.recv()
.map_err(client::handle::Error::from)
.unwrap();
let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap();
assert!(policy_change);
assert!(!alice.tracking().is_repo_tracked(&proj_id).unwrap());
}

View File

@ -21,7 +21,7 @@ use radicle::{assert_matches, rad};
use crate::node::NodeId;
use crate::storage::git::transport;
use crate::test::logger;
use crate::{client, client::handle::Handle, client::Runtime, service};
use crate::{runtime, runtime::Handle, service, Runtime};
/// A node that can be run.
struct Node {
@ -36,7 +36,7 @@ struct NodeHandle {
storage: Storage,
signer: MockSigner,
addr: net::SocketAddr,
thread: ManuallyDrop<thread::JoinHandle<Result<(), client::Error>>>,
thread: ManuallyDrop<thread::JoinHandle<Result<(), runtime::Error>>>,
handle: ManuallyDrop<Handle<MockSigner>>,
}

View File

@ -13,8 +13,8 @@ use radicle::storage::{ReadRepository, RefUpdate, WriteRepository, WriteStorage}
use radicle::{git, Storage};
use reactor::poller::popol;
use crate::client::handle::Handle;
use crate::node::{FetchError, FetchResult};
use crate::runtime::Handle;
use crate::service::reactor::Fetch;
use crate::wire::{WireReader, WireSession, WireWriter};