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