node: Rename `client` module to `runtime`
This commit is contained in:
parent
02be334144
commit
23cf44f4c7
|
|
@ -9,10 +9,10 @@ use std::{io, net};
|
||||||
|
|
||||||
use radicle::node::Handle;
|
use radicle::node::Handle;
|
||||||
|
|
||||||
use crate::client;
|
|
||||||
use crate::identity::Id;
|
use crate::identity::Id;
|
||||||
use crate::node;
|
use crate::node;
|
||||||
use crate::node::FetchLookup;
|
use crate::node::FetchLookup;
|
||||||
|
use crate::runtime;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
@ -23,7 +23,7 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen for commands on the control socket, and process them.
|
/// 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,
|
listener: UnixListener,
|
||||||
mut handle: H,
|
mut handle: H,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
@ -62,15 +62,15 @@ enum DrainError {
|
||||||
InvalidCommandArg(String, Box<dyn std::error::Error>),
|
InvalidCommandArg(String, Box<dyn std::error::Error>),
|
||||||
#[error("unknown command `{0}`")]
|
#[error("unknown command `{0}`")]
|
||||||
UnknownCommand(String),
|
UnknownCommand(String),
|
||||||
#[error("client error: {0}")]
|
#[error("runtime error: {0}")]
|
||||||
Client(#[from] client::handle::Error),
|
Runtime(#[from] runtime::HandleError),
|
||||||
#[error("i/o error: {0}")]
|
#[error("i/o error: {0}")]
|
||||||
Io(#[from] io::Error),
|
Io(#[from] io::Error),
|
||||||
#[error("shutdown requested")]
|
#[error("shutdown requested")]
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drain<H: Handle<Error = client::handle::Error>>(
|
fn drain<H: Handle<Error = runtime::HandleError>>(
|
||||||
stream: &UnixStream,
|
stream: &UnixStream,
|
||||||
handle: &mut H,
|
handle: &mut H,
|
||||||
) -> Result<(), DrainError> {
|
) -> Result<(), DrainError> {
|
||||||
|
|
@ -104,7 +104,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -121,7 +121,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -144,7 +144,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -165,7 +165,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -175,7 +175,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
Some(("announce-refs", arg)) => match arg.parse() {
|
Some(("announce-refs", arg)) => match arg.parse() {
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
if let Err(e) = handle.announce_refs(id) {
|
if let Err(e) = handle.announce_refs(id) {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
writeln!(writer, "{}", node::RESPONSE_OK)?;
|
writeln!(writer, "{}", node::RESPONSE_OK)?;
|
||||||
}
|
}
|
||||||
|
|
@ -197,7 +197,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
writeln!(writer, "{id} {seed}",)?;
|
writeln!(writer, "{id} {seed}",)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => return Err(DrainError::Client(e)),
|
Err(e) => return Err(DrainError::Runtime(e)),
|
||||||
},
|
},
|
||||||
"inventory" => match handle.inventory() {
|
"inventory" => match handle.inventory() {
|
||||||
Ok(c) => {
|
Ok(c) => {
|
||||||
|
|
@ -205,7 +205,7 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
writeln!(writer, "{id}")?;
|
writeln!(writer, "{id}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => return Err(DrainError::Client(e)),
|
Err(e) => return Err(DrainError::Runtime(e)),
|
||||||
},
|
},
|
||||||
"shutdown" => {
|
"shutdown" => {
|
||||||
return Err(DrainError::Shutdown);
|
return Err(DrainError::Shutdown);
|
||||||
|
|
@ -218,14 +218,14 @@ fn drain<H: Handle<Error = client::handle::Error>>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch<W: Write, H: Handle<Error = client::handle::Error>>(
|
fn fetch<W: Write, H: Handle<Error = runtime::HandleError>>(
|
||||||
id: Id,
|
id: Id,
|
||||||
mut writer: W,
|
mut writer: W,
|
||||||
handle: &mut H,
|
handle: &mut H,
|
||||||
) -> Result<(), DrainError> {
|
) -> Result<(), DrainError> {
|
||||||
match handle.fetch(id) {
|
match handle.fetch(id) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(DrainError::Client(e));
|
return Err(DrainError::Runtime(e));
|
||||||
}
|
}
|
||||||
Ok(FetchLookup::Found { seeds, results }) => {
|
Ok(FetchLookup::Found { seeds, results }) => {
|
||||||
let seeds = Vec::from(seeds);
|
let seeds = Vec::from(seeds);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
pub mod address;
|
pub mod address;
|
||||||
pub mod bounded;
|
pub mod bounded;
|
||||||
pub mod client;
|
|
||||||
pub mod clock;
|
pub mod clock;
|
||||||
pub mod control;
|
pub mod control;
|
||||||
pub mod deserializer;
|
pub mod deserializer;
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
|
pub mod runtime;
|
||||||
pub mod service;
|
pub mod service;
|
||||||
pub mod sql;
|
pub mod sql;
|
||||||
#[cfg(any(test, feature = "test"))]
|
#[cfg(any(test, feature = "test"))]
|
||||||
|
|
@ -17,6 +17,7 @@ pub mod worker;
|
||||||
pub use localtime::{LocalDuration, LocalTime};
|
pub use localtime::{LocalDuration, LocalTime};
|
||||||
pub use netservices::LinkDirection as Link;
|
pub use netservices::LinkDirection as Link;
|
||||||
pub use radicle::{collections, crypto, git, identity, node, profile, rad, storage};
|
pub use radicle::{collections, crypto, git, identity, node, profile, rad, storage};
|
||||||
|
pub use runtime::Runtime;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::bounded::BoundedVec;
|
pub use crate::bounded::BoundedVec;
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ use cyphernet::addr::PeerAddr;
|
||||||
use localtime::LocalDuration;
|
use localtime::LocalDuration;
|
||||||
|
|
||||||
use radicle::profile;
|
use radicle::profile;
|
||||||
use radicle_node::client::Runtime;
|
|
||||||
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::Runtime;
|
||||||
use radicle_node::{logger, service};
|
use radicle_node::{logger, service};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
mod handle;
|
||||||
|
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::os::unix::net::UnixListener;
|
use std::os::unix::net::UnixListener;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -22,8 +24,8 @@ use crate::wire::Wire;
|
||||||
use crate::worker::{WorkerPool, WorkerReq};
|
use crate::worker::{WorkerPool, WorkerReq};
|
||||||
use crate::{crypto, service, LocalTime};
|
use crate::{crypto, service, LocalTime};
|
||||||
|
|
||||||
pub mod handle;
|
pub use handle::Error as HandleError;
|
||||||
use handle::Handle;
|
pub use handle::Handle;
|
||||||
|
|
||||||
/// Directory in `$RAD_HOME` under which node-specific files are stored.
|
/// Directory in `$RAD_HOME` under which node-specific files are stored.
|
||||||
pub const NODE_DIR: &str = "node";
|
pub const NODE_DIR: &str = "node";
|
||||||
|
|
@ -3,9 +3,9 @@ use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crossbeam_channel as chan;
|
use crossbeam_channel as chan;
|
||||||
|
|
||||||
use crate::client::handle::Error;
|
|
||||||
use crate::identity::Id;
|
use crate::identity::Id;
|
||||||
use crate::node::FetchLookup;
|
use crate::node::FetchLookup;
|
||||||
|
use crate::runtime::HandleError;
|
||||||
use crate::service;
|
use crate::service;
|
||||||
use crate::service::NodeId;
|
use crate::service::NodeId;
|
||||||
|
|
||||||
|
|
@ -17,56 +17,56 @@ pub struct Handle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl radicle::node::Handle for Handle {
|
impl radicle::node::Handle for Handle {
|
||||||
type Error = Error;
|
type Error = HandleError;
|
||||||
type Sessions = service::Sessions;
|
type Sessions = service::Sessions;
|
||||||
|
|
||||||
fn is_running(&self) -> bool {
|
fn is_running(&self) -> bool {
|
||||||
true
|
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!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch(&mut self, _id: Id) -> Result<FetchLookup, Error> {
|
fn fetch(&mut self, _id: Id) -> Result<FetchLookup, Self::Error> {
|
||||||
Ok(FetchLookup::NotFound)
|
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))
|
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))
|
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))
|
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))
|
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);
|
self.updates.lock().unwrap().push(id);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn routing(&self) -> Result<chan::Receiver<(Id, service::NodeId)>, Error> {
|
fn routing(&self) -> Result<chan::Receiver<(Id, service::NodeId)>, Self::Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sessions(&self) -> Result<Self::Sessions, Error> {
|
fn sessions(&self) -> Result<Self::Sessions, Self::Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inventory(&self) -> Result<chan::Receiver<Id>, Error> {
|
fn inventory(&self) -> Result<chan::Receiver<Id>, Self::Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shutdown(self) -> Result<(), Error> {
|
fn shutdown(self) -> Result<(), Self::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ use crate::test::storage::MockStorage;
|
||||||
use crate::wire::Decode;
|
use crate::wire::Decode;
|
||||||
use crate::wire::Encode;
|
use crate::wire::Encode;
|
||||||
use crate::LocalTime;
|
use crate::LocalTime;
|
||||||
use crate::{client, git, identity, rad, service, test};
|
use crate::{git, identity, rad, runtime, service, test};
|
||||||
|
|
||||||
// NOTE
|
// NOTE
|
||||||
//
|
//
|
||||||
|
|
@ -343,19 +343,13 @@ fn test_tracking() {
|
||||||
|
|
||||||
let (sender, receiver) = chan::bounded(1);
|
let (sender, receiver) = chan::bounded(1);
|
||||||
alice.command(Command::TrackRepo(proj_id, sender));
|
alice.command(Command::TrackRepo(proj_id, sender));
|
||||||
let policy_change = receiver
|
let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap();
|
||||||
.recv()
|
|
||||||
.map_err(client::handle::Error::from)
|
|
||||||
.unwrap();
|
|
||||||
assert!(policy_change);
|
assert!(policy_change);
|
||||||
assert!(alice.tracking().is_repo_tracked(&proj_id).unwrap());
|
assert!(alice.tracking().is_repo_tracked(&proj_id).unwrap());
|
||||||
|
|
||||||
let (sender, receiver) = chan::bounded(1);
|
let (sender, receiver) = chan::bounded(1);
|
||||||
alice.command(Command::UntrackRepo(proj_id, sender));
|
alice.command(Command::UntrackRepo(proj_id, sender));
|
||||||
let policy_change = receiver
|
let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap();
|
||||||
.recv()
|
|
||||||
.map_err(client::handle::Error::from)
|
|
||||||
.unwrap();
|
|
||||||
assert!(policy_change);
|
assert!(policy_change);
|
||||||
assert!(!alice.tracking().is_repo_tracked(&proj_id).unwrap());
|
assert!(!alice.tracking().is_repo_tracked(&proj_id).unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use radicle::{assert_matches, rad};
|
||||||
use crate::node::NodeId;
|
use crate::node::NodeId;
|
||||||
use crate::storage::git::transport;
|
use crate::storage::git::transport;
|
||||||
use crate::test::logger;
|
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.
|
/// A node that can be run.
|
||||||
struct Node {
|
struct Node {
|
||||||
|
|
@ -36,7 +36,7 @@ struct NodeHandle {
|
||||||
storage: Storage,
|
storage: Storage,
|
||||||
signer: MockSigner,
|
signer: MockSigner,
|
||||||
addr: net::SocketAddr,
|
addr: net::SocketAddr,
|
||||||
thread: ManuallyDrop<thread::JoinHandle<Result<(), client::Error>>>,
|
thread: ManuallyDrop<thread::JoinHandle<Result<(), runtime::Error>>>,
|
||||||
handle: ManuallyDrop<Handle<MockSigner>>,
|
handle: ManuallyDrop<Handle<MockSigner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ use radicle::storage::{ReadRepository, RefUpdate, WriteRepository, WriteStorage}
|
||||||
use radicle::{git, Storage};
|
use radicle::{git, Storage};
|
||||||
use reactor::poller::popol;
|
use reactor::poller::popol;
|
||||||
|
|
||||||
use crate::client::handle::Handle;
|
|
||||||
use crate::node::{FetchError, FetchResult};
|
use crate::node::{FetchError, FetchResult};
|
||||||
|
use crate::runtime::Handle;
|
||||||
use crate::service::reactor::Fetch;
|
use crate::service::reactor::Fetch;
|
||||||
use crate::wire::{WireReader, WireSession, WireWriter};
|
use crate::wire::{WireReader, WireSession, WireWriter};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue