From 15e8a96948aca10c5a03e9f1acdb24f908cc730f Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Fri, 16 Sep 2022 20:25:51 +0200 Subject: [PATCH] node: Service -> Protocol Signed-off-by: Alexis Sellier --- node/src/client.rs | 34 +++++++++--------- node/src/client/handle.rs | 18 +++++----- node/src/control.rs | 4 +-- node/src/decoder.rs | 4 +-- node/src/lib.rs | 2 +- node/src/{protocol.rs => service.rs} | 44 +++++++++++------------ node/src/{protocol => service}/config.rs | 4 +-- node/src/{protocol => service}/filter.rs | 2 +- node/src/{protocol => service}/message.rs | 8 ++--- node/src/{protocol => service}/peer.rs | 4 +-- node/src/{protocol => service}/wire.rs | 24 ++++++------- node/src/storage/refs.rs | 2 +- node/src/test/arbitrary.rs | 6 ++-- node/src/test/handle.rs | 6 ++-- node/src/test/peer.rs | 44 +++++++++++------------ node/src/test/simulator.rs | 22 ++++++------ node/src/test/tests.rs | 26 +++++++------- node/src/transport.rs | 6 ++-- 18 files changed, 130 insertions(+), 130 deletions(-) rename node/src/{protocol.rs => service.rs} (96%) rename node/src/{protocol => service}/config.rs (97%) rename node/src/{protocol => service}/filter.rs (98%) rename node/src/{protocol => service}/message.rs (99%) rename node/src/{protocol => service}/peer.rs (99%) rename node/src/{protocol => service}/wire.rs (95%) diff --git a/node/src/client.rs b/node/src/client.rs index 007b8953..62289b3e 100644 --- a/node/src/client.rs +++ b/node/src/client.rs @@ -7,8 +7,8 @@ use nakamoto_net::{LocalTime, Reactor}; use crate::clock::RefClock; use crate::collections::HashMap; use crate::crypto::Signer; -use crate::protocol; -use crate::protocol::wire::Wire; +use crate::service; +use crate::service::wire::Wire; use crate::storage::git::Storage; use crate::transport::Transport; @@ -17,19 +17,19 @@ pub mod handle; /// Client configuration. #[derive(Debug, Clone)] pub struct Config { - /// Client protocol configuration. - pub protocol: protocol::Config, + /// Client service configuration. + pub service: service::Config, /// Client listen addresses. pub listen: Vec, } impl Config { /// Create a new configuration for the given network. - pub fn new(network: protocol::Network) -> Self { + pub fn new(network: service::Network) -> Self { Self { - protocol: protocol::Config { + service: service::Config { network, - ..protocol::Config::default() + ..service::Config::default() }, ..Self::default() } @@ -39,7 +39,7 @@ impl Config { impl Default for Config { fn default() -> Self { Self { - protocol: protocol::Config::default(), + service: service::Config::default(), listen: vec![([0, 0, 0, 0], 0).into()], } } @@ -50,8 +50,8 @@ pub struct Client { storage: Storage, signer: G, - handle: chan::Sender, - commands: chan::Receiver, + handle: chan::Sender, + commands: chan::Receiver, shutdown: chan::Sender<()>, listening: chan::Receiver, events: Events, @@ -59,7 +59,7 @@ pub struct Client { impl Client { pub fn new>(path: P, signer: G) -> Result { - let (handle, commands) = chan::unbounded::(); + let (handle, commands) = chan::unbounded::(); let (shutdown, shutdown_recv) = chan::bounded(1); let (listening_send, listening) = chan::bounded(1); let reactor = R::new(shutdown_recv, listening_send)?; @@ -79,7 +79,7 @@ impl Client { } pub fn run(mut self, config: Config) -> Result<(), nakamoto_net::error::Error> { - let network = config.protocol.network; + let network = config.service.network; let rng = fastrand::Rng::new(); let time = LocalTime::now(); let storage = self.storage; @@ -88,8 +88,8 @@ impl Client { log::info!("Initializing client ({:?})..", network); - let protocol = protocol::Protocol::new( - config.protocol, + let service = service::Service::new( + config.service, RefClock::from(time), storage, addresses, @@ -98,7 +98,7 @@ impl Client { ); self.reactor.run( &config.listen, - Transport::new(Wire::new(protocol)), + Transport::new(Wire::new(service)), self.events, self.commands, )?; @@ -119,8 +119,8 @@ impl Client { pub struct Events {} -impl nakamoto_net::Publisher for Events { - fn publish(&mut self, e: protocol::Event) { +impl nakamoto_net::Publisher for Events { + fn publish(&mut self, e: service::Event) { log::info!("Received event {:?}", e); } } diff --git a/node/src/client/handle.rs b/node/src/client/handle.rs index 4def78bf..9fc2ebbf 100644 --- a/node/src/client/handle.rs +++ b/node/src/client/handle.rs @@ -5,8 +5,8 @@ use nakamoto_net::Waker; use thiserror::Error; use crate::identity::Id; -use crate::protocol; -use crate::protocol::{CommandError, FetchLookup}; +use crate::service; +use crate::service::{CommandError, FetchLookup}; /// An error resulting from a handle method. #[derive(Error, Debug)] @@ -47,7 +47,7 @@ impl From> for Error { } pub struct Handle { - pub(crate) commands: chan::Sender, + pub(crate) commands: chan::Sender, pub(crate) shutdown: chan::Sender<()>, pub(crate) listening: chan::Receiver, pub(crate) waker: W, @@ -57,31 +57,31 @@ impl traits::Handle for Handle { /// Retrieve or update the given project from the network. fn fetch(&self, id: Id) -> Result { let (sender, receiver) = chan::bounded(1); - self.commands.send(protocol::Command::Fetch(id, sender))?; + self.commands.send(service::Command::Fetch(id, sender))?; receiver.recv().map_err(Error::from) } /// Start tracking the given project. Doesn't do anything if the project is already tracked. fn track(&self, id: Id) -> Result { let (sender, receiver) = chan::bounded(1); - self.commands.send(protocol::Command::Track(id, sender))?; + self.commands.send(service::Command::Track(id, sender))?; receiver.recv().map_err(Error::from) } /// Untrack the given project and delete it from storage. fn untrack(&self, id: Id) -> Result { let (sender, receiver) = chan::bounded(1); - self.commands.send(protocol::Command::Untrack(id, sender))?; + self.commands.send(service::Command::Untrack(id, sender))?; receiver.recv().map_err(Error::from) } /// Notify the client that a project has been updated. fn updated(&self, id: Id) -> Result<(), Error> { - self.command(protocol::Command::AnnounceRefs(id)) + self.command(service::Command::AnnounceRefs(id)) } /// Send a command to the command channel, and wake up the event loop. - fn command(&self, cmd: protocol::Command) -> Result<(), Error> { + fn command(&self, cmd: service::Command) -> Result<(), Error> { self.commands.send(cmd)?; self.waker.wake()?; @@ -111,7 +111,7 @@ pub mod traits { /// Notify the client that a project has been updated. fn updated(&self, id: Id) -> Result<(), Error>; /// Send a command to the command channel, and wake up the event loop. - fn command(&self, cmd: protocol::Command) -> Result<(), Error>; + fn command(&self, cmd: service::Command) -> Result<(), Error>; /// Ask the client to shutdown. fn shutdown(self) -> Result<(), Error>; } diff --git a/node/src/control.rs b/node/src/control.rs index abc020fc..fde9232e 100644 --- a/node/src/control.rs +++ b/node/src/control.rs @@ -10,8 +10,8 @@ use std::{fs, io, net}; use crate::client; use crate::client::handle::traits::Handle; use crate::identity::Id; -use crate::protocol::FetchLookup; -use crate::protocol::FetchResult; +use crate::service::FetchLookup; +use crate::service::FetchResult; /// Default name for control socket file. pub const DEFAULT_SOCKET_NAME: &str = "radicle.sock"; diff --git a/node/src/decoder.rs b/node/src/decoder.rs index 3b786093..7c49c558 100644 --- a/node/src/decoder.rs +++ b/node/src/decoder.rs @@ -1,8 +1,8 @@ use std::io; use std::marker::PhantomData; -use crate::protocol::message::Envelope; -use crate::protocol::wire; +use crate::service::message::Envelope; +use crate::service::wire; /// Message stream decoder. /// diff --git a/node/src/lib.rs b/node/src/lib.rs index 42241065..df76098e 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -14,9 +14,9 @@ mod git; mod hash; mod identity; mod logger; -mod protocol; mod rad; mod serde_ext; +mod service; mod storage; #[cfg(test)] mod test; diff --git a/node/src/protocol.rs b/node/src/service.rs similarity index 96% rename from node/src/protocol.rs rename to node/src/service.rs index 4c18b318..bbaee2d5 100644 --- a/node/src/protocol.rs +++ b/node/src/service.rs @@ -24,14 +24,14 @@ use crate::clock::RefClock; use crate::collections::{HashMap, HashSet}; use crate::crypto; use crate::identity::{Id, Project}; -use crate::protocol::config::ProjectTracking; -use crate::protocol::message::{NodeAnnouncement, RefsAnnouncement}; -use crate::protocol::peer::{Peer, PeerError, PeerState}; +use crate::service::config::ProjectTracking; +use crate::service::message::{NodeAnnouncement, RefsAnnouncement}; +use crate::service::peer::{Peer, PeerError, PeerState}; use crate::storage; use crate::storage::{Inventory, ReadRepository, RefUpdate, WriteRepository, WriteStorage}; -pub use crate::protocol::config::{Config, Network}; -pub use crate::protocol::message::{Envelope, Message}; +pub use crate::service::config::{Config, Network}; +pub use crate::service::message::{Envelope, Message}; use self::filter::Filter; use self::message::{InventoryAnnouncement, NodeFeatures}; @@ -68,7 +68,7 @@ pub enum Io { Event(Event), } -/// A protocol event. +/// A service event. #[derive(Debug, Clone)] pub enum Event { RefsFetched { @@ -121,7 +121,7 @@ pub enum FetchResult { }, } -/// Commands sent to the protocol by the operator. +/// Commands sent to the service by the operator. #[derive(Debug)] pub enum Command { AnnounceRefs(Id), @@ -136,26 +136,26 @@ pub enum Command { pub enum CommandError {} #[derive(Debug)] -pub struct Protocol { +pub struct Service { /// Peers currently or recently connected. peers: Peers, - /// Protocol state that isn't peer-specific. + /// Service state that isn't peer-specific. context: Context, /// Whether our local inventory no long represents what we have announced to the network. out_of_sync: bool, - /// Last time the protocol was idle. + /// Last time the service was idle. last_idle: LocalTime, - /// Last time the protocol synced. + /// Last time the service synced. last_sync: LocalTime, - /// Last time the protocol routing table was pruned. + /// Last time the service routing table was pruned. last_prune: LocalTime, - /// Last time the protocol announced its inventory. + /// Last time the service announced its inventory. last_announce: LocalTime, - /// Time when the protocol was initialized. + /// Time when the service was initialized. start_time: LocalTime, } -impl<'r, T: WriteStorage<'r>, S: address_book::Store, G: crypto::Signer> Protocol { +impl<'r, T: WriteStorage<'r>, S: address_book::Store, G: crypto::Signer> Service { pub fn new( config: Config, clock: RefClock, @@ -264,12 +264,12 @@ impl<'r, T: WriteStorage<'r>, S: address_book::Store, G: crypto::Signer> Protoco &self.context.signer } - /// Get the local protocol time. + /// Get the local service time. pub fn local_time(&self) -> LocalTime { self.context.clock.local_time() } - /// Get protocol configuration. + /// Get service configuration. pub fn config(&self) -> &Config { &self.context.config } @@ -589,7 +589,7 @@ impl<'r, T: WriteStorage<'r>, S: address_book::Store, G: crypto::Signer> Protoco } } -impl Deref for Protocol { +impl Deref for Service { type Target = Context; fn deref(&self) -> &Self::Target { @@ -597,7 +597,7 @@ impl Deref for Protocol { } } -impl DerefMut for Protocol { +impl DerefMut for Service { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.context } @@ -633,7 +633,7 @@ impl fmt::Display for DisconnectReason { } } -impl Iterator for Protocol { +impl Iterator for Service { type Item = Io; fn next(&mut self) -> Option { @@ -650,10 +650,10 @@ pub struct Lookup { pub remote: Vec, } -/// Global protocol state used across peers. +/// Global service state used across peers. #[derive(Debug)] pub struct Context { - /// Protocol configuration. + /// Service configuration. config: Config, /// Our cryptographic signer and key. signer: G, diff --git a/node/src/protocol/config.rs b/node/src/service/config.rs similarity index 97% rename from node/src/protocol/config.rs rename to node/src/service/config.rs index d2bfc62c..49ecaeff 100644 --- a/node/src/protocol/config.rs +++ b/node/src/service/config.rs @@ -5,7 +5,7 @@ use git_url::Url; use crate::collections::HashSet; use crate::git; use crate::identity::{Id, PublicKey}; -use crate::protocol::message::{Address, Envelope, Message}; +use crate::service::message::{Address, Envelope, Message}; /// Peer-to-peer network. #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] @@ -60,7 +60,7 @@ pub enum RemoteTracking { Allowed(HashSet), } -/// Protocol configuration. +/// Service configuration. #[derive(Debug, Clone)] pub struct Config { /// Peers to connect to on startup. diff --git a/node/src/protocol/filter.rs b/node/src/service/filter.rs similarity index 98% rename from node/src/protocol/filter.rs rename to node/src/service/filter.rs index 4ba44a9a..9dbca632 100644 --- a/node/src/protocol/filter.rs +++ b/node/src/service/filter.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut}; use bloomy::BloomFilter; use crate::identity::Id; -use crate::protocol::wire; +use crate::service::wire; /// Size in bytes of subscription bloom filter. pub const FILTER_SIZE: usize = 1024 * 16; diff --git a/node/src/protocol/message.rs b/node/src/service/message.rs similarity index 99% rename from node/src/protocol/message.rs rename to node/src/service/message.rs index cc1db72c..cc7543fe 100644 --- a/node/src/protocol/message.rs +++ b/node/src/service/message.rs @@ -5,9 +5,9 @@ use byteorder::{NetworkEndian, ReadBytesExt}; use crate::crypto; use crate::git; use crate::identity::Id; -use crate::protocol::filter::Filter; -use crate::protocol::wire; -use crate::protocol::{NodeId, Timestamp, PROTOCOL_VERSION}; +use crate::service::filter::Filter; +use crate::service::wire; +use crate::service::{NodeId, Timestamp, PROTOCOL_VERSION}; use crate::storage::refs::Refs; /// Message envelope. All messages sent over the network are wrapped in this type. @@ -607,7 +607,7 @@ mod tests { use crate::crypto::Signer; use crate::decoder::Decoder; - use crate::protocol::wire::{self, Encode}; + use crate::service::wire::{self, Encode}; use crate::test::crypto::MockSigner; #[quickcheck] diff --git a/node/src/protocol/peer.rs b/node/src/service/peer.rs similarity index 99% rename from node/src/protocol/peer.rs rename to node/src/service/peer.rs index e2109c1e..a86a5a9c 100644 --- a/node/src/protocol/peer.rs +++ b/node/src/service/peer.rs @@ -1,5 +1,5 @@ -use crate::protocol::message::*; -use crate::protocol::*; +use crate::service::message::*; +use crate::service::*; #[derive(Debug, Default)] #[allow(clippy::large_enum_variant)] diff --git a/node/src/protocol/wire.rs b/node/src/service/wire.rs similarity index 95% rename from node/src/protocol/wire.rs rename to node/src/service/wire.rs index d7c1c662..6c4fe026 100644 --- a/node/src/protocol/wire.rs +++ b/node/src/service/wire.rs @@ -16,7 +16,7 @@ use crate::git; use crate::git::fmt; use crate::hash::Digest; use crate::identity::Id; -use crate::protocol; +use crate::service; use crate::storage::refs::Refs; use crate::storage::WriteStorage; @@ -389,11 +389,11 @@ impl Decode for Digest { #[derive(Debug)] pub struct Wire { inboxes: HashMap, - inner: protocol::Protocol, + inner: service::Service, } impl Wire { - pub fn new(inner: protocol::Protocol) -> Self { + pub fn new(inner: service::Service) -> Self { Self { inboxes: HashMap::new(), inner, @@ -419,7 +419,7 @@ where self.inner.wake() } - pub fn command(&mut self, cmd: protocol::Command) { + pub fn command(&mut self, cmd: service::Command) { self.inner.command(cmd) } @@ -440,7 +440,7 @@ where pub fn disconnected( &mut self, addr: &std::net::SocketAddr, - reason: nakamoto::DisconnectReason, + reason: nakamoto::DisconnectReason, ) { self.inboxes.remove(&addr.ip()); self.inner.disconnected(addr, reason) @@ -472,11 +472,11 @@ where } impl Iterator for Wire { - type Item = nakamoto::Io; + type Item = nakamoto::Io; fn next(&mut self) -> Option { match self.inner.next() { - Some(protocol::Io::Write(addr, msgs)) => { + Some(service::Io::Write(addr, msgs)) => { let mut buf = Vec::new(); for msg in msgs { log::debug!("Write {:?} to {}", &msg, addr.ip()); @@ -486,10 +486,10 @@ impl Iterator for Wire { } Some(nakamoto::Io::Write(addr, buf)) } - Some(protocol::Io::Event(e)) => Some(nakamoto::Io::Event(e)), - Some(protocol::Io::Connect(a)) => Some(nakamoto::Io::Connect(a)), - Some(protocol::Io::Disconnect(a, r)) => Some(nakamoto::Io::Disconnect(a, r)), - Some(protocol::Io::Wakeup(d)) => Some(nakamoto::Io::Wakeup(d)), + Some(service::Io::Event(e)) => Some(nakamoto::Io::Event(e)), + Some(service::Io::Connect(a)) => Some(nakamoto::Io::Connect(a)), + Some(service::Io::Disconnect(a, r)) => Some(nakamoto::Io::Disconnect(a, r)), + Some(service::Io::Wakeup(d)) => Some(nakamoto::Io::Wakeup(d)), None => None, } @@ -497,7 +497,7 @@ impl Iterator for Wire { } impl Deref for Wire { - type Target = protocol::Protocol; + type Target = service::Service; fn deref(&self) -> &Self::Target { &self.inner diff --git a/node/src/storage/refs.rs b/node/src/storage/refs.rs index 62ed3c25..84193444 100644 --- a/node/src/storage/refs.rs +++ b/node/src/storage/refs.rs @@ -15,7 +15,7 @@ use crate::crypto; use crate::crypto::{PublicKey, Signature, Signer, Unverified, Verified}; use crate::git; use crate::git::Oid; -use crate::protocol::wire; +use crate::service::wire; use crate::storage; use crate::storage::{ReadRepository, RemoteId, WriteRepository}; diff --git a/node/src/test/arbitrary.rs b/node/src/test/arbitrary.rs index fd558e17..de453593 100644 --- a/node/src/test/arbitrary.rs +++ b/node/src/test/arbitrary.rs @@ -14,12 +14,12 @@ use crate::crypto::{PublicKey, SecretKey}; use crate::git; use crate::hash; use crate::identity::{Delegate, Did, Doc, Id, Project}; -use crate::protocol::filter::{Filter, FILTER_SIZE}; -use crate::protocol::message::{ +use crate::service::filter::{Filter, FILTER_SIZE}; +use crate::service::message::{ Address, Envelope, InventoryAnnouncement, Message, MessageType, NodeAnnouncement, RefsAnnouncement, Subscribe, }; -use crate::protocol::{NodeId, Timestamp}; +use crate::service::{NodeId, Timestamp}; use crate::storage; use crate::storage::refs::{Refs, SignedRefs}; use crate::test::storage::MockStorage; diff --git a/node/src/test/handle.rs b/node/src/test/handle.rs index 5e4c7072..502c607f 100644 --- a/node/src/test/handle.rs +++ b/node/src/test/handle.rs @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex}; use crate::client::handle::traits; use crate::client::handle::Error; use crate::identity::Id; -use crate::protocol; -use crate::protocol::FetchLookup; +use crate::service; +use crate::service::FetchLookup; #[derive(Default, Clone)] pub struct Handle { @@ -30,7 +30,7 @@ impl traits::Handle for Handle { Ok(()) } - fn command(&self, _cmd: protocol::Command) -> Result<(), Error> { + fn command(&self, _cmd: service::Command) -> Result<(), Error> { Ok(()) } diff --git a/node/src/test/peer.rs b/node/src/test/peer.rs index bee4c3ac..e6dd36c9 100644 --- a/node/src/test/peer.rs +++ b/node/src/test/peer.rs @@ -7,22 +7,22 @@ use log::*; use crate::address_book::{KnownAddress, Source}; use crate::clock::RefClock; use crate::collections::HashMap; -use crate::protocol; -use crate::protocol::config::*; -use crate::protocol::message::*; -use crate::protocol::*; +use crate::service; +use crate::service::config::*; +use crate::service::message::*; +use crate::service::*; use crate::storage::WriteStorage; use crate::test::crypto::MockSigner; use crate::test::simulator; use crate::{Link, LocalTime}; -/// Protocol instantiation used for testing. -pub type Protocol = protocol::Protocol, S, MockSigner>; +/// Service instantiation used for testing. +pub type Service = service::Service, S, MockSigner>; #[derive(Debug)] pub struct Peer { pub name: &'static str, - pub protocol: Protocol, + pub service: Service, pub ip: net::IpAddr, pub rng: fastrand::Rng, pub local_time: LocalTime, @@ -45,16 +45,16 @@ where } impl Deref for Peer { - type Target = Protocol; + type Target = Service; fn deref(&self) -> &Self::Target { - &self.protocol + &self.service } } impl DerefMut for Peer { fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.protocol + &mut self.service } } @@ -91,13 +91,13 @@ where let local_time = LocalTime::now(); let clock = RefClock::from(local_time); let signer = MockSigner::new(&mut rng); - let protocol = Protocol::new(config, clock, storage, addrs, signer, rng.clone()); + let service = Service::new(config, clock, storage, addrs, signer, rng.clone()); let ip = ip.into(); let local_addr = net::SocketAddr::new(ip, rng.u16(..)); Self { name, - protocol, + service, ip, local_addr, rng, @@ -111,12 +111,12 @@ where info!("{}: Initializing: address = {}", self.name, self.ip); self.initialized = true; - self.protocol.initialize(LocalTime::now()); + self.service.initialize(LocalTime::now()); } } pub fn timestamp(&self) -> Timestamp { - self.protocol.timestamp() + self.service.timestamp() } pub fn git_url(&self) -> Url { @@ -124,11 +124,11 @@ where } pub fn node_id(&self) -> NodeId { - self.protocol.node_id() + self.service.node_id() } pub fn receive(&mut self, peer: &net::SocketAddr, msg: Message) { - self.protocol + self.service .received_message(peer, self.config().network.envelope(msg)); } @@ -139,7 +139,7 @@ where let git = Url::from_bytes(git.as_bytes()).unwrap(); self.initialize(); - self.protocol.connected(remote, &local, Link::Inbound); + self.service.connected(remote, &local, Link::Inbound); self.receive( &remote, Message::init( @@ -161,8 +161,8 @@ where let remote = simulator::Peer::::addr(peer); self.initialize(); - self.protocol.attempted(&remote); - self.protocol + self.service.attempted(&remote); + self.service .connected(remote, &self.local_addr, Link::Outbound); let mut msgs = self.messages(&remote); @@ -187,8 +187,8 @@ where pub fn messages(&mut self, remote: &net::SocketAddr) -> impl Iterator { let mut msgs = Vec::new(); - self.protocol.outbox().retain(|o| match o { - protocol::Io::Write(a, envelopes) if a == remote => { + self.service.outbox().retain(|o| match o { + service::Io::Write(a, envelopes) if a == remote => { msgs.extend(envelopes.iter().map(|e| e.msg.clone())); false } @@ -206,6 +206,6 @@ where /// Get a draining iterator over the peer's I/O outbox. pub fn outbox(&mut self) -> impl Iterator + '_ { - self.protocol.outbox().drain(..) + self.service.outbox().drain(..) } } diff --git a/node/src/test/simulator.rs b/node/src/test/simulator.rs index e62e1ccf..da559925 100644 --- a/node/src/test/simulator.rs +++ b/node/src/test/simulator.rs @@ -13,9 +13,9 @@ use log::*; use nakamoto_net as nakamoto; use nakamoto_net::{Link, LocalDuration, LocalTime}; -use crate::protocol::{DisconnectReason, Envelope, Event, Io}; +use crate::service::{DisconnectReason, Envelope, Event, Io}; use crate::storage::WriteStorage; -use crate::test::peer::Protocol; +use crate::test::peer::Service; /// Minimum latency between peers. pub const MIN_LATENCY: LocalDuration = LocalDuration::from_millis(1); @@ -26,16 +26,16 @@ pub const MAX_EVENTS: usize = 2048; /// The simulator requires each peer to have a distinct IP address. type NodeId = std::net::IpAddr; -/// A simulated peer. Protocol instances have to be wrapped in this type to be simulated. -pub trait Peer: Deref> + DerefMut> + 'static { - /// Initialize the peer. This should at minimum initialize the protocol with the +/// A simulated peer. Service instances have to be wrapped in this type to be simulated. +pub trait Peer: Deref> + DerefMut> + 'static { + /// Initialize the peer. This should at minimum initialize the service with the /// current time. fn init(&mut self); /// Get the peer address. fn addr(&self) -> net::SocketAddr; } -/// Simulated protocol input. +/// Simulated service input. #[derive(Debug, Clone)] pub enum Input { /// Connection attempt underway. @@ -63,7 +63,7 @@ pub enum Input { Wake, } -/// A scheduled protocol input. +/// A scheduled service input. #[derive(Debug, Clone)] pub struct Scheduled { /// The node for which this input is scheduled. @@ -349,8 +349,8 @@ impl<'r, S: WriteStorage<'r>> Simulation { trace!(target: "sim", "{:05} {}", elapsed, next); } else { // TODO: This can be confusing, since this event may not actually be passed to - // the protocol. It would be best to only log the events that are being sent - // to the protocol, or to log when an input is being dropped. + // the service. It would be best to only log the events that are being sent + // to the service, or to log when an input is being dropped. info!(target: "sim", "{:05} {} ({})", elapsed, next, self.inbox.messages.len()); } assert!(time >= self.time, "Time only moves forwards!"); @@ -415,7 +415,7 @@ impl<'r, S: WriteStorage<'r>> Simulation { !self.is_done() } - /// Process a protocol output event from a node. + /// Process a service output event from a node. pub fn schedule(&mut self, node: &NodeId, out: Io) { let node = *node; @@ -491,7 +491,7 @@ impl<'r, S: WriteStorage<'r>> Simulation { if self.is_partitioned(node, remote.ip()) { log::info!(target: "sim", "{} -/-> {} (partitioned)", node, remote.ip()); - // Sometimes, the protocol gets a failure input, other times it just hangs. + // Sometimes, the service gets a failure input, other times it just hangs. if self.rng.bool() { self.inbox.insert( self.time + MIN_LATENCY, diff --git a/node/src/test/tests.rs b/node/src/test/tests.rs index 29a4dd01..313a5d8f 100644 --- a/node/src/test/tests.rs +++ b/node/src/test/tests.rs @@ -5,10 +5,10 @@ use crossbeam_channel as chan; use nakamoto_net as nakamoto; use crate::collections::{HashMap, HashSet}; -use crate::protocol::config::*; -use crate::protocol::message::*; -use crate::protocol::peer::*; -use crate::protocol::*; +use crate::service::config::*; +use crate::service::message::*; +use crate::service::peer::*; +use crate::service::*; use crate::storage::git::Storage; use crate::storage::ReadStorage; use crate::test::fixtures; @@ -19,7 +19,7 @@ use crate::test::simulator; use crate::test::simulator::{Peer as _, Simulation}; use crate::test::storage::MockStorage; use crate::{assert_matches, Link, LocalTime}; -use crate::{client, identity, protocol, rad, storage, test}; +use crate::{client, identity, rad, service, storage, test}; // NOTE // @@ -39,7 +39,7 @@ fn test_outbound_connection() { alice.connect_to(&eve); let peers = alice - .protocol + .service .peers() .negotiated() .map(|(ip, _)| *ip) @@ -59,7 +59,7 @@ fn test_inbound_connection() { alice.connect_from(&eve); let peers = alice - .protocol + .service .peers() .negotiated() .map(|(ip, _)| *ip) @@ -396,8 +396,8 @@ fn test_push_and_pull() { let mut eve = Peer::new("eve", [9, 9, 9, 9], storage_eve); // Alice and Bob connect to Eve. - alice.command(protocol::Command::Connect(eve.addr())); - bob.command(protocol::Command::Connect(eve.addr())); + alice.command(service::Command::Connect(eve.addr())); + bob.command(service::Command::Connect(eve.addr())); let mut sim = Simulation::new( LocalTime::now(), @@ -422,11 +422,11 @@ fn test_push_and_pull() { // Bob tracks Alice's project. let (sender, _) = chan::bounded(1); - bob.command(protocol::Command::Track(proj_id.clone(), sender)); + bob.command(service::Command::Track(proj_id.clone(), sender)); // Eve tracks Alice's project. let (sender, _) = chan::bounded(1); - eve.command(protocol::Command::Track(proj_id.clone(), sender)); + eve.command(service::Command::Track(proj_id.clone(), sender)); // Neither of them have it in the beginning. assert!(eve.get(&proj_id).unwrap().is_none()); @@ -435,7 +435,7 @@ fn test_push_and_pull() { // Alice announces her refs. // We now expect Eve to fetch Alice's project from Alice. // Then we expect Bob to fetch Alice's project from Eve. - alice.command(protocol::Command::AnnounceRefs(proj_id.clone())); + alice.command(service::Command::AnnounceRefs(proj_id.clone())); sim.run_while([&mut alice, &mut bob, &mut eve], |s| !s.is_settled()); assert!(eve @@ -450,7 +450,7 @@ fn test_push_and_pull() { .is_some()); assert_matches!( sim.events(&bob.ip).next(), - Some(protocol::Event::RefsFetched { from, .. }) + Some(service::Event::RefsFetched { from, .. }) if from == eve.git_url(), "Bob fetched from Eve" ); diff --git a/node/src/transport.rs b/node/src/transport.rs index 8daddd68..4d6e42f3 100644 --- a/node/src/transport.rs +++ b/node/src/transport.rs @@ -8,8 +8,8 @@ use nakamoto_net::{Io, Link}; use crate::address_book; use crate::collections::HashMap; use crate::crypto; -use crate::protocol::wire::Wire; -use crate::protocol::{Command, DisconnectReason, Event, Protocol}; +use crate::service::wire::Wire; +use crate::service::{Command, DisconnectReason, Event, Service}; use crate::storage::WriteStorage; #[derive(Debug)] @@ -93,7 +93,7 @@ impl Iterator for Transport { } impl Deref for Transport { - type Target = Protocol; + type Target = Service; fn deref(&self) -> &Self::Target { &self.inner