Просмотр исходного кода

merged src/net/error.rs with src/error.rs. deleted src/net/error and updated all code in /net to accept change

rachel-rose 5 лет назад
Родитель
Сommit
2b78f0adb2

+ 0 - 20
src/error.rs

@@ -1,19 +1,12 @@
 use rusqlite;
 use std::fmt;
 
-use crate::net::error::NetError;
 use crate::state;
 use crate::vm::ZKVMError;
 
 pub type Result<T> = std::result::Result<T, Error>;
 
 #[derive(Debug, Clone)]
-//#[derive(Debug, Copy, Clone)]
-
-// need to be able to copy the errors into theads
-// net error has clone and copy attribute 
-// copy vs clone
-//struct Error;
 
 pub enum Error {
     Foo,
@@ -160,19 +153,6 @@ impl From<std::num::ParseIntError> for Error {
     }
 }
 
-impl From<NetError> for Error {
-    fn from(err: NetError) -> Error {
-        match err {
-            NetError::OperationFailed => Error::OperationFailed,
-            NetError::ConnectFailed => Error::ConnectFailed,
-            NetError::ConnectTimeout => Error::ConnectTimeout,
-            NetError::ChannelStopped => Error::ChannelStopped,
-            NetError::ChannelTimeout => Error::ChannelTimeout,
-            NetError::ServiceStopped => Error::ServiceStopped,
-        }
-    }
-}
-
 impl From<std::string::FromUtf8Error> for Error {
     fn from(_err: std::string::FromUtf8Error) -> Error {
         Error::Utf8Error

+ 13 - 12
src/net/acceptor.rs

@@ -3,7 +3,8 @@ use smol::{Async, Executor};
 use std::net::{SocketAddr, TcpListener};
 use std::sync::Arc;
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
+//use crate::net::error::{, Result};
 use crate::net::{Channel, ChannelPtr};
 use crate::system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription};
 
@@ -12,7 +13,7 @@ pub type AcceptorPtr = Arc<Acceptor>;
 
 /// Create inbound socket connections.
 pub struct Acceptor {
-    channel_subscriber: SubscriberPtr<NetResult<ChannelPtr>>,
+    channel_subscriber: SubscriberPtr<Result<ChannelPtr>>,
     task: StoppableTaskPtr,
 }
 
@@ -31,7 +32,7 @@ impl Acceptor {
         self: Arc<Self>,
         accept_addr: SocketAddr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         let listener = Self::setup(accept_addr)?;
 
         // Start detached task and return instantly
@@ -47,24 +48,24 @@ impl Acceptor {
     }
 
     /// Start receiving network messages.
-    pub async fn subscribe(self: Arc<Self>) -> Subscription<NetResult<ChannelPtr>> {
+    pub async fn subscribe(self: Arc<Self>) -> Subscription<Result<ChannelPtr>> {
         self.channel_subscriber.clone().subscribe().await
     }
 
     /// Start listening on a local socket address.
-    fn setup(accept_addr: SocketAddr) -> NetResult<Async<TcpListener>> {
+    fn setup(accept_addr: SocketAddr) -> Result<Async<TcpListener>> {
         let listener = match Async::<TcpListener>::bind(accept_addr) {
             Ok(listener) => listener,
             Err(err) => {
                 error!("Bind listener failed: {}", err);
-                return Err(NetError::OperationFailed);
+                return Err(Error::OperationFailed);
             }
         };
         let local_addr = match listener.get_ref().local_addr() {
             Ok(addr) => addr,
             Err(err) => {
                 error!("Failed to get local address: {}", err);
-                return Err(NetError::OperationFailed);
+                return Err(Error::OperationFailed);
             }
         };
         info!("Listening on {}", local_addr);
@@ -78,13 +79,13 @@ impl Acceptor {
         self.task.clone().start(
             self.clone().run_accept_loop(listener),
             |result| self.handle_stop(result),
-            NetError::ServiceStopped,
+            Error::ServiceStopped,
             executor,
         );
     }
 
     /// Run the accept loop.
-    async fn run_accept_loop(self: Arc<Self>, listener: Async<TcpListener>) -> NetResult<()> {
+    async fn run_accept_loop(self: Arc<Self>, listener: Async<TcpListener>) -> Result<()> {
         loop {
             let channel = self.tick_accept(&listener).await?;
             self.channel_subscriber.notify(Ok(channel)).await;
@@ -93,7 +94,7 @@ impl Acceptor {
 
     /// Handles network errors. Panics if error passes silently, otherwise
     /// broadcasts the error.
-    async fn handle_stop(self: Arc<Self>, result: NetResult<()>) {
+    async fn handle_stop(self: Arc<Self>, result: Result<()>) {
         match result {
             Ok(()) => panic!("Acceptor task should never complete without error status"),
             Err(err) => {
@@ -106,12 +107,12 @@ impl Acceptor {
 
     /// Single attempt to accept an incoming connection. Stops after one
     /// attempt.
-    async fn tick_accept(&self, listener: &Async<TcpListener>) -> NetResult<ChannelPtr> {
+    async fn tick_accept(&self, listener: &Async<TcpListener>) -> Result<ChannelPtr> {
         let (stream, peer_addr) = match listener.accept().await {
             Ok((s, a)) => (s, a),
             Err(err) => {
                 error!("Error listening for connections: {}", err);
-                return Err(NetError::ServiceStopped);
+                return Err(Error::ServiceStopped);
             }
         };
         info!("Accepted client: {}", peer_addr);

+ 17 - 18
src/net/channel.rs

@@ -9,8 +9,7 @@ use std::net::{SocketAddr, TcpStream};
 use std::sync::atomic::{AtomicBool, Ordering};
 use std::sync::Arc;
 
-use crate::error;
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::message_subscriber::{MessageSubscription, MessageSubsystem};
 use crate::net::messages;
 use crate::system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription};
@@ -24,7 +23,7 @@ pub struct Channel {
     writer: Mutex<WriteHalf<Async<TcpStream>>>,
     address: SocketAddr,
     message_subsystem: MessageSubsystem,
-    stop_subscriber: SubscriberPtr<NetError>,
+    stop_subscriber: SubscriberPtr<Error>,
     receive_task: StoppableTaskPtr,
     stopped: AtomicBool,
 }
@@ -61,7 +60,7 @@ impl Channel {
             self.clone().main_receive_loop(),
             // Ignore stop handler
             |result| self2.handle_stop(result),
-            NetError::ServiceStopped,
+            Error::ServiceStopped,
             executor,
         );
         debug!(target: "net", "Channel::start() [END, address={}]", self.address());
@@ -75,16 +74,16 @@ impl Channel {
         assert_eq!(self.stopped.load(Ordering::Relaxed), false);
         // Changes memory ordering to relaxed. We don't need strict thread locking here.
         self.stopped.store(false, Ordering::Relaxed);
-        self.stop_subscriber.notify(NetError::ChannelStopped).await;
+        self.stop_subscriber.notify(Error::ChannelStopped).await;
         self.receive_task.stop().await;
         self.message_subsystem
-            .trigger_error(NetError::ChannelStopped)
+            .trigger_error(Error::ChannelStopped)
             .await;
         debug!(target: "net", "Channel::stop() [END, address={}]", self.address());
     }
 
     /// Creates a subscription to a stopped signal.
-    pub async fn subscribe_stop(&self) -> Subscription<NetError> {
+    pub async fn subscribe_stop(&self) -> Subscription<Error> {
         debug!(target: "net",
             "Channel::subscribe_stop() [START, address={}]",
             self.address()
@@ -102,14 +101,14 @@ impl Channel {
     /// Sends a message across a channel. Calls function 'send_message' that
     /// creates a new payload and sends it over the TCP connection as a
     /// packet. Returns an error if something goes wrong.
-    pub async fn send<M: messages::Message>(&self, message: M) -> NetResult<()> {
+    pub async fn send<M: messages::Message>(&self, message: M) -> Result<()> {
         debug!(target: "net",
             "Channel::send() [START, command={:?}, address={}]",
             M::name(),
             self.address()
         );
         if self.stopped.load(Ordering::Relaxed) {
-            return Err(NetError::ChannelStopped);
+            return Err(Error::ChannelStopped);
         }
 
         // Catch failure and stop channel, return a net error
@@ -118,7 +117,7 @@ impl Channel {
             Err(err) => {
                 error!("Channel send error for [{}]: {}", self.address(), err);
                 self.stop().await;
-                Err(NetError::ChannelStopped)
+                Err(Error::ChannelStopped)
             }
         };
         debug!(target: "net",
@@ -133,7 +132,7 @@ impl Channel {
     /// it. Then creates a message packet- the base type of the network- and
     /// copies the payload into it. Then we send the packet over the TCP
     /// stream.
-    async fn send_message<M: messages::Message>(&self, message: M) -> error::Result<()> {
+    async fn send_message<M: messages::Message>(&self, message: M) -> Result<()> {
         let mut payload = Vec::new();
         message.encode(&mut payload)?;
         let packet = messages::Packet {
@@ -146,7 +145,7 @@ impl Channel {
     }
 
     /// Subscribe to a messages on the message subsystem.
-    pub async fn subscribe_msg<M: messages::Message>(&self) -> NetResult<MessageSubscription<M>> {
+    pub async fn subscribe_msg<M: messages::Message>(&self) -> Result<MessageSubscription<M>> {
         debug!(target: "net",
             "Channel::subscribe_msg() [START, command={:?}, address={}]",
             M::name(),
@@ -167,9 +166,9 @@ impl Channel {
     }
 
     /// End of file error. Triggered when unexpected end of file occurs.
-    fn is_eof_error(err: &error::Error) -> bool {
+    fn is_eof_error(err: Error) -> bool {
         match err {
-            error::Error::Io(io_err) => io_err.clone() == std::io::ErrorKind::UnexpectedEof,
+            Error::Io(io_err) => io_err.clone() == std::io::ErrorKind::UnexpectedEof,
             _ => false,
         }
     }
@@ -203,7 +202,7 @@ impl Channel {
 
     /// Run the receive loop. Start receiving messages or handle network
     /// failure.
-    async fn main_receive_loop(self: Arc<Self>) -> NetResult<()> {
+    async fn main_receive_loop(self: Arc<Self>) -> Result<()> {
         debug!(target: "net",
             "Channel::receive_loop() [START, address={}]",
             self.address()
@@ -215,7 +214,7 @@ impl Channel {
             let packet = match messages::read_packet(reader).await {
                 Ok(packet) => packet,
                 Err(err) => {
-                    if Self::is_eof_error(&err) {
+                    if Self::is_eof_error(err.clone()) {
                         info!("Channel {} disconnected", self.address());
                     } else {
                         error!("Read error on channel: {}", err);
@@ -225,7 +224,7 @@ impl Channel {
                         self.address()
                     );
                     self.stop().await;
-                    return Err(NetError::ChannelStopped);
+                    return Err(Error::ChannelStopped);
                 }
             };
 
@@ -238,7 +237,7 @@ impl Channel {
 
     /// Handle network errors. Panic if error passes silently, otherwise
     /// broadcast the error.
-    async fn handle_stop(self: Arc<Self>, result: NetResult<()>) {
+    async fn handle_stop(self: Arc<Self>, result: Result<()>) {
         debug!(target: "net", "Channel::handle_stop() [START, address={}]", self.address());
         match result {
             Ok(()) => panic!("Channel task should never complete without error status"),

+ 5 - 4
src/net/connector.rs

@@ -2,7 +2,8 @@ use futures::FutureExt;
 use smol::Async;
 use std::net::{SocketAddr, TcpStream};
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
+//use crate::net::error::{Error, Result};
 use crate::net::utility::sleep;
 use crate::net::{Channel, ChannelPtr, SettingsPtr};
 
@@ -18,15 +19,15 @@ impl Connector {
     }
 
     /// Establish an outbound connection.
-    pub async fn connect(&self, hostaddr: SocketAddr) -> NetResult<ChannelPtr> {
+    pub async fn connect(&self, hostaddr: SocketAddr) -> Result<ChannelPtr> {
         futures::select! {
             stream_result = Async::<TcpStream>::connect(hostaddr).fuse() => {
                 match stream_result {
                     Ok(stream) => Ok(Channel::new(stream, hostaddr).await),
-                    Err(_) => Err(NetError::ConnectFailed)
+                    Err(_) => Err(Error::ConnectFailed)
                 }
             }
-            _ = sleep(self.settings.connect_timeout_seconds).fuse() => Err(NetError::ConnectTimeout)
+            _ = sleep(self.settings.connect_timeout_seconds).fuse() => Err(Error::ConnectTimeout)
         }
     }
 }

+ 0 - 30
src/net/error.rs

@@ -1,30 +0,0 @@
-use std::fmt;
-
-/// Returns the relevant network error if a program fails.
-pub type NetResult<T> = std::result::Result<T, NetError>;
-
-/// An enum representing the main network errors.
-#[derive(Debug, Clone)]
-pub enum NetError {
-    OperationFailed,
-    ConnectFailed,
-    ConnectTimeout,
-    ChannelStopped,
-    ChannelTimeout,
-    ServiceStopped,
-}
-
-impl std::error::Error for NetError {}
-
-impl fmt::Display for NetError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
-        match *self {
-            NetError::OperationFailed => f.write_str("Operation failed"),
-            NetError::ConnectFailed => f.write_str("Connection failed"),
-            NetError::ConnectTimeout => f.write_str("Connection timed out"),
-            NetError::ChannelStopped => f.write_str("Channel stopped"),
-            NetError::ChannelTimeout => f.write_str("Channel timed out"),
-            NetError::ServiceStopped => f.write_str("Service stopped"),
-        }
-    }
-}

+ 8 - 9
src/net/message_subscriber.rs

@@ -8,14 +8,13 @@ use std::io;
 use std::io::Cursor;
 use std::sync::Arc;
 
-use crate::error::Result;
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::messages::Message;
 use crate::serial::{Decodable, Encodable};
 
 /// 64bit identifier for message subscription.
 pub type MessageSubscriptionID = u64;
-type MessageResult<M> = NetResult<Arc<M>>;
+type MessageResult<M> = Result<Arc<M>>;
 
 /// Handles message subscriptions through a subscription ID and a receiver
 /// channel.
@@ -47,7 +46,7 @@ impl<M: Message> MessageSubscription<M> {
 trait MessageDispatcherInterface: Send + Sync {
     async fn trigger(&self, payload: Vec<u8>);
 
-    async fn trigger_error(&self, err: NetError);
+    async fn trigger_error(&self, err: Error);
 
     fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
 }
@@ -155,7 +154,7 @@ impl<M: Message> MessageDispatcherInterface for MessageDispatcher<M> {
 
     /// Sends a message to all subscriber channels. Clears any inactive
     /// channels.
-    async fn trigger_error(&self, err: NetError) {
+    async fn trigger_error(&self, err: Error) {
         self.trigger_all(Err(err)).await;
     }
 
@@ -188,7 +187,7 @@ impl MessageSubsystem {
     }
 
     /// Add a dispatcher to the list of subscribers.
-    pub async fn subscribe<M: Message>(&self) -> NetResult<MessageSubscription<M>> {
+    pub async fn subscribe<M: Message>(&self) -> Result<MessageSubscription<M>> {
         let dispatcher = self.dispatchers.lock().await.get(M::name()).cloned();
 
         let sub = match dispatcher {
@@ -203,7 +202,7 @@ impl MessageSubsystem {
             None => {
                 // normall return failure here
                 // for now panic
-                return Err(NetError::OperationFailed);
+                return Err(Error::OperationFailed);
             }
         };
 
@@ -229,7 +228,7 @@ impl MessageSubsystem {
     }
 
     /// Send a message to all subscriber channels. Clear any inactive channels.
-    pub async fn trigger_error(&self, err: NetError) {
+    pub async fn trigger_error(&self, err: Error) {
         // TODO: this could be parallelized
         for dispatcher in self.dispatchers.lock().await.values() {
             dispatcher.trigger_error(err.clone()).await;
@@ -294,7 +293,7 @@ async fn _do_message_subscriber_test() {
     assert_eq!(msg2.x, 110);
     println!("{}", msg2.x);
 
-    subsystem.trigger_error(NetError::ChannelStopped).await;
+    subsystem.trigger_error(Error::ChannelStopped).await;
 
     let msg2 = sub.receive().await;
     assert!(msg2.is_err());

+ 0 - 3
src/net/mod.rs

@@ -14,9 +14,6 @@ pub mod channel;
 /// connection.
 pub mod connector;
 
-/// Defines a set of common network errors. Used for error handling.
-pub mod error;
-
 /// Hosts are a list of network addresses used when establishing an outbound
 /// connection. Hosts are shared across the network through the address
 /// protocol. When attempting to connect, a node will loop through addresses in

+ 8 - 8
src/net/p2p.rs

@@ -5,7 +5,7 @@ use std::collections::{HashMap, HashSet};
 use std::net::SocketAddr;
 use std::sync::Arc;
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::messages::Message;
 use crate::net::sessions::{InboundSession, OutboundSession, SeedSession};
 use crate::net::{Channel, ChannelPtr, Hosts, HostsPtr, Settings, SettingsPtr};
@@ -22,9 +22,9 @@ pub type P2pPtr = Arc<P2p>;
 pub struct P2p {
     pending: PendingChannels,
     channels: ConnectedChannels<Channel>,
-    channel_subscriber: SubscriberPtr<NetResult<ChannelPtr>>,
+    channel_subscriber: SubscriberPtr<Result<ChannelPtr>>,
     // Used both internally and externally
-    stop_subscriber: SubscriberPtr<NetError>,
+    stop_subscriber: SubscriberPtr<Error>,
     hosts: HostsPtr,
     settings: SettingsPtr,
 }
@@ -44,7 +44,7 @@ impl P2p {
     }
 
     /// Invoke startup and seeding sequence. Call from constructing thread.
-    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "P2p::start() [BEGIN]");
         // Start manual connections
 
@@ -59,7 +59,7 @@ impl P2p {
 
     /// Synchronize the blockchain and then begin long running sessions,
     /// call after start() is invoked.
-    pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "P2p::run() [BEGIN]");
 
         let inbound = InboundSession::new(Arc::downgrade(&self));
@@ -81,7 +81,7 @@ impl P2p {
     }
 
     /// Broadcasts a message across all channels.
-    pub async fn broadcast<M: Message + Clone>(&self, message: M) -> NetResult<()> {
+    pub async fn broadcast<M: Message + Clone>(&self, message: M) -> Result<()> {
         for channel in self.channels.lock().await.values() {
             channel.send(message.clone()).await?;
         }
@@ -133,12 +133,12 @@ impl P2p {
     }
 
     /// Subscribe to a channel.
-    pub async fn subscribe_channel(&self) -> Subscription<NetResult<ChannelPtr>> {
+    pub async fn subscribe_channel(&self) -> Subscription<Result<ChannelPtr>> {
         self.channel_subscriber.clone().subscribe().await
     }
 
     /// Subscribe to a stop signal.
-    pub async fn subscribe_stop(&self) -> Subscription<NetError> {
+    pub async fn subscribe_stop(&self) -> Subscription<Error> {
         self.stop_subscriber.clone().subscribe().await
     }
 }

+ 3 - 3
src/net/protocols/protocol_address.rs

@@ -2,7 +2,7 @@ use log::*;
 use smol::Executor;
 use std::sync::Arc;
 
-use crate::net::error::NetResult;
+use crate::error::Result;
 use crate::net::message_subscriber::MessageSubscription;
 use crate::net::messages;
 use crate::net::protocols::{ProtocolJobsManager, ProtocolJobsManagerPtr};
@@ -68,7 +68,7 @@ impl ProtocolAddress {
     /// Handles receiving the address message. Loops to continually recieve
     /// address messages on the address subsciption. Adds the recieved
     /// addresses to the list of hosts.
-    async fn handle_receive_addrs(self: Arc<Self>) -> NetResult<()> {
+    async fn handle_receive_addrs(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolAddress::handle_receive_addrs() [START]");
         loop {
             let addrs_msg = self.addrs_sub.receive().await?;
@@ -88,7 +88,7 @@ impl ProtocolAddress {
     /// Handles receiving the get-address message. Continually recieves
     /// get-address messages on the get-address subsciption. Then replies
     /// with an address message.
-    async fn handle_receive_get_addrs(self: Arc<Self>) -> NetResult<()> {
+    async fn handle_receive_get_addrs(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolAddress::handle_receive_get_addrs() [START]");
         loop {
             let _get_addrs = self.get_addrs_sub.receive().await?;

+ 3 - 3
src/net/protocols/protocol_jobs_manager.rs

@@ -4,7 +4,7 @@ use log::*;
 use smol::Task;
 use std::sync::Arc;
 
-use crate::net::error::NetResult;
+use crate::error::Result;
 use crate::net::ChannelPtr;
 use crate::system::ExecutorPtr;
 
@@ -17,7 +17,7 @@ pub type ProtocolJobsManagerPtr = Arc<ProtocolJobsManager>;
 pub struct ProtocolJobsManager {
     name: &'static str,
     channel: ChannelPtr,
-    tasks: Mutex<Vec<Task<NetResult<()>>>>,
+    tasks: Mutex<Vec<Task<Result<()>>>>,
 }
 
 impl ProtocolJobsManager {
@@ -39,7 +39,7 @@ impl ProtocolJobsManager {
     /// Spawns a new task and adds it to the internal queue.
     pub async fn spawn<'a, F>(&self, future: F, executor: ExecutorPtr<'a>)
     where
-        F: Future<Output = NetResult<()>> + Send + 'a,
+        F: Future<Output = Result<()>> + Send + 'a,
     {
         self.tasks.lock().await.push(executor.spawn(future))
     }

+ 4 - 4
src/net/protocols/protocol_ping.rs

@@ -4,7 +4,7 @@ use smol::Executor;
 use std::sync::Arc;
 use std::time::Instant;
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::messages;
 use crate::net::protocols::{ProtocolJobsManager, ProtocolJobsManagerPtr};
 use crate::net::utility::sleep;
@@ -48,7 +48,7 @@ impl ProtocolPing {
     /// loop. Loop sleeps for the duration of the channel heartbeat, then
     /// sends a ping message with a random nonce. Loop starts a timer, waits
     /// for the pong reply and insures the nonce is the same.
-    async fn run_ping_pong(self: Arc<Self>) -> NetResult<()> {
+    async fn run_ping_pong(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolPing::run_ping_pong() [START]");
         // Creates a subscription to pong message.
         let pong_sub = self
@@ -77,7 +77,7 @@ impl ProtocolPing {
             if pong_msg.nonce != nonce {
                 error!("Wrong nonce for ping reply. Disconnecting from channel.");
                 self.channel.stop().await;
-                return Err(NetError::ChannelStopped);
+                return Err(Error::ChannelStopped);
             }
             let duration = start.elapsed().as_millis();
             debug!(target: "net", "Received Pong message {}ms from [{:?}]", duration, self.channel.address());
@@ -86,7 +86,7 @@ impl ProtocolPing {
 
     /// Waits for ping, then replies with pong. Copies ping's nonce into the
     /// pong reply.
-    async fn reply_to_ping(self: Arc<Self>) -> NetResult<()> {
+    async fn reply_to_ping(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolPing::reply_to_ping() [START]");
         // Creates a subscription to ping message.
         let ping_sub = self

+ 3 - 3
src/net/protocols/protocol_seed.rs

@@ -2,7 +2,7 @@ use log::*;
 use smol::Executor;
 use std::sync::Arc;
 
-use crate::net::error::NetResult;
+use crate::error::Result;
 use crate::net::messages;
 use crate::net::{ChannelPtr, HostsPtr, SettingsPtr};
 
@@ -26,7 +26,7 @@ impl ProtocolSeed {
     /// Starts the seed protocol. Creates a subscription to the address message,
     /// then sends our address to the seed server. Sends a get-address
     /// message and receives an address message.
-    pub async fn start(self: Arc<Self>, _executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn start(self: Arc<Self>, _executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "ProtocolSeed::start() [START]");
         // Create a subscription to address message.
         let addr_sub = self
@@ -55,7 +55,7 @@ impl ProtocolSeed {
     /// Sends own external address over a channel. Imports own external address
     /// from settings, then adds that address to an address message and
     /// sends it out over the channel.
-    pub async fn send_self_address(&self) -> NetResult<()> {
+    pub async fn send_self_address(&self) -> Result<()> {
         match self.settings.external_addr {
             Some(addr) => {
                 debug!(target: "net", "ProtocolSeed::send_own_address() addr={}", addr);

+ 6 - 6
src/net/protocols/protocol_version.rs

@@ -3,7 +3,7 @@ use log::*;
 use smol::Executor;
 use std::sync::Arc;
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::message_subscriber::MessageSubscription;
 use crate::net::messages;
 use crate::net::utility::sleep;
@@ -47,7 +47,7 @@ impl ProtocolVersion {
     /// Start version information exchange. Start the timer. Send version info
     /// and wait for version acknowledgement. Wait for version info and send
     /// version acknowledgement.
-    pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "ProtocolVersion::run() [START]");
         // Start timer
         // Send version, wait for verack
@@ -55,13 +55,13 @@ impl ProtocolVersion {
         // Fin.
         let result = futures::select! {
             _ = self.clone().exchange_versions(executor).fuse() => Ok(()),
-            _ = sleep(self.settings.channel_handshake_seconds).fuse() => Err(NetError::ChannelTimeout)
+            _ = sleep(self.settings.channel_handshake_seconds).fuse() => Err(Error::ChannelTimeout)
         };
         debug!(target: "net", "ProtocolVersion::run() [END]");
         result
     }
     /// Send and recieve version information.
-    async fn exchange_versions(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    async fn exchange_versions(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "ProtocolVersion::exchange_versions() [START]");
 
         let send = executor.spawn(self.clone().send_version());
@@ -72,7 +72,7 @@ impl ProtocolVersion {
         Ok(())
     }
     /// Send version info and wait for version acknowledgement.
-    async fn send_version(self: Arc<Self>) -> NetResult<()> {
+    async fn send_version(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolVersion::send_version() [START]");
         let version = messages::VersionMessage {};
         self.channel.clone().send(version).await?;
@@ -85,7 +85,7 @@ impl ProtocolVersion {
     }
     /// Recieve version info, check the message is okay and send version
     /// acknowledgement.
-    async fn recv_version(self: Arc<Self>) -> NetResult<()> {
+    async fn recv_version(self: Arc<Self>) -> Result<()> {
         debug!(target: "net", "ProtocolVersion::recv_version() [START]");
         // Rec
         let _version_msg = self.version_sub.receive().await?;

+ 8 - 7
src/net/sessions/inbound_session.rs

@@ -3,7 +3,8 @@ use log::*;
 use std::net::SocketAddr;
 use std::sync::{Arc, Weak};
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
+//use crate::net::error::{Error, Result};
 use crate::net::protocols::{ProtocolAddress, ProtocolPing};
 use crate::net::sessions::Session;
 use crate::net::{Acceptor, AcceptorPtr};
@@ -31,7 +32,7 @@ impl InboundSession {
     /// Starts the inbound session. Begins by accepting connections and fails if
     /// the address is not configured. Then runs the channel subscription
     /// loop.
-    pub fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         match self.p2p().settings().inbound {
             Some(accept_addr) => {
                 self.clone()
@@ -47,7 +48,7 @@ impl InboundSession {
             self.clone().channel_sub_loop(executor.clone()),
             // Ignore stop handler
             |_| async {},
-            NetError::ServiceStopped,
+            Error::ServiceStopped,
             executor,
         );
 
@@ -63,7 +64,7 @@ impl InboundSession {
         self: Arc<Self>,
         accept_addr: SocketAddr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         info!("Starting inbound session on {}", accept_addr);
         let result = self.acceptor.clone().start(accept_addr, executor);
         if let Err(err) = result.clone() {
@@ -74,7 +75,7 @@ impl InboundSession {
 
     /// Wait for all new channels created by the acceptor and call
     /// setup_channel() on them.
-    async fn channel_sub_loop(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    async fn channel_sub_loop(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         let channel_sub = self.acceptor.clone().subscribe().await;
         loop {
             let channel = channel_sub.receive().await?;
@@ -93,7 +94,7 @@ impl InboundSession {
         self: Arc<Self>,
         channel: ChannelPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         info!("Connected inbound [{}]", channel.address());
 
         self.clone()
@@ -108,7 +109,7 @@ impl InboundSession {
         self: Arc<Self>,
         channel: ChannelPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         let settings = self.p2p().settings().clone();
         let hosts = self.p2p().hosts().clone();
 

+ 7 - 7
src/net/sessions/outbound_session.rs

@@ -4,7 +4,7 @@ use log::*;
 use std::net::SocketAddr;
 use std::sync::{Arc, Weak};
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
 use crate::net::protocols::{ProtocolAddress, ProtocolPing};
 use crate::net::sessions::Session;
 use crate::net::{ChannelPtr, Connector, P2p};
@@ -25,7 +25,7 @@ impl OutboundSession {
         })
     }
     /// Start the outbound session. Runs the channel connect loop.
-    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         let slots_count = self.p2p().settings().outbound_connections;
         info!("Starting {} outbound connection slots.", slots_count);
         // Activate mutex lock on connection slots.
@@ -38,7 +38,7 @@ impl OutboundSession {
                 self.clone().channel_connect_loop(i, executor.clone()),
                 // Ignore stop handler
                 |_| async {},
-                NetError::ServiceStopped,
+                Error::ServiceStopped,
                 executor.clone(),
             );
 
@@ -66,7 +66,7 @@ impl OutboundSession {
         self: Arc<Self>,
         slot_number: u32,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         let connector = Connector::new(self.p2p().settings().clone());
 
         loop {
@@ -109,7 +109,7 @@ impl OutboundSession {
     /// our own inbound address, then checks whether it is already connected
     /// (exists) or connecting (pending). Keeps looping until address is
     /// found that passes all checks.
-    async fn load_address(&self, slot_number: u32) -> NetResult<SocketAddr> {
+    async fn load_address(&self, slot_number: u32) -> Result<SocketAddr> {
         let p2p = self.p2p();
         let hosts = p2p.hosts();
         let inbound_addr = p2p.settings().inbound;
@@ -122,7 +122,7 @@ impl OutboundSession {
                     "Hosts address pool is empty. Closing connect slot #{}",
                     slot_number
                 );
-                return Err(NetError::ServiceStopped);
+                return Err(Error::ServiceStopped);
             }
             let addr = addr.unwrap();
 
@@ -158,7 +158,7 @@ impl OutboundSession {
         self: Arc<Self>,
         channel: ChannelPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         let settings = self.p2p().settings().clone();
         let hosts = self.p2p().hosts().clone();
 

+ 7 - 6
src/net/sessions/seed_session.rs

@@ -4,7 +4,8 @@ use log::*;
 use std::net::SocketAddr;
 use std::sync::{Arc, Weak};
 
-use crate::net::error::{NetError, NetResult};
+use crate::error::{Error, Result};
+//use crate::net::error::{Error, Result};
 use crate::net::protocols::{ProtocolPing, ProtocolSeed};
 use crate::net::sessions::Session;
 use crate::net::utility::sleep;
@@ -23,7 +24,7 @@ impl SeedSession {
 
     /// Start the seed session. Creates a new task for every seed connection and
     /// starts the seed on each task.
-    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "SeedSession::start() [START]");
         let settings = self.p2p().settings();
 
@@ -56,14 +57,14 @@ impl SeedSession {
             }
             _ = sleep(settings.seed_query_timeout_seconds).fuse() => {
                 error!("Querying seeds timed out");
-                return Err(NetError::OperationFailed);
+                return Err(Error::OperationFailed);
             }
         }
 
         // Seed process complete
         if self.p2p().hosts().is_empty().await {
             error!("Hosts pool still empty after seeding");
-            return Err(NetError::OperationFailed);
+            return Err(Error::OperationFailed);
         }
 
         debug!(target: "net", "SeedSession::start() [END]");
@@ -78,7 +79,7 @@ impl SeedSession {
         seed_index: usize,
         seed: SocketAddr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         debug!(target: "net", "SeedSession::start_seed(i={}) [START]", seed_index);
         let (hosts, settings) = {
             let p2p = self.p2p.upgrade().unwrap();
@@ -119,7 +120,7 @@ impl SeedSession {
         hosts: HostsPtr,
         settings: SettingsPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         let protocol_ping = ProtocolPing::new(channel.clone(), settings.clone());
         protocol_ping.start(executor.clone()).await;
 

+ 3 - 3
src/net/sessions/session.rs

@@ -3,7 +3,7 @@ use log::*;
 use smol::Executor;
 use std::sync::Arc;
 
-use crate::net::error::NetResult;
+use crate::error::Result;
 use crate::net::p2p::P2pPtr;
 use crate::net::protocols::ProtocolVersion;
 use crate::net::ChannelPtr;
@@ -34,7 +34,7 @@ pub trait Session: Sync {
         self: Arc<Self>,
         channel: ChannelPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         debug!(target: "net", "Session::register_channel() [START]");
 
         let protocol_version = ProtocolVersion::new(channel.clone(), self.p2p().settings()).await;
@@ -58,7 +58,7 @@ pub trait Session: Sync {
         protocol_version: Arc<ProtocolVersion>,
         channel: ChannelPtr,
         executor: Arc<Executor<'_>>,
-    ) -> NetResult<()> {
+    ) -> Result<()> {
         // Perform handshake
         protocol_version.run(executor.clone()).await?;