From 77ad61331c40fc89398b7192acf7251da3f3120f Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Wed, 15 Jan 2020 19:33:59 -0800 Subject: [PATCH] Rename `peer::Server` to `peer::Connection`. This doesn't change the file path or edit imports so that the diff is easier to review. --- zebra-network/src/peer.rs | 2 +- zebra-network/src/peer/handshake.rs | 4 ++-- zebra-network/src/peer/server.rs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/zebra-network/src/peer.rs b/zebra-network/src/peer.rs index 1616dce8..90cea0ec 100644 --- a/zebra-network/src/peer.rs +++ b/zebra-network/src/peer.rs @@ -18,4 +18,4 @@ pub use client::Client; pub use connector::Connector; pub use error::{HandshakeError, PeerError, SharedPeerError}; pub use handshake::Handshake; -pub use server::Server; +pub use server::Connection; diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index 68d9e67f..9fd9b650 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -27,7 +27,7 @@ use crate::{ BoxedStdError, Config, }; -use super::{Client, ErrorSlot, HandshakeError, Server}; +use super::{Client, Connection, ErrorSlot, HandshakeError}; /// A [`Service`] that handshakes with a remote peer and constructs a /// client/server pair. @@ -195,7 +195,7 @@ where let (peer_tx, peer_rx) = stream.split(); use super::server; - let server = Server { + let server = Connection { state: server::State::AwaitingRequest, svc: internal_service, client_rx: server_rx, diff --git a/zebra-network/src/peer/server.rs b/zebra-network/src/peer/server.rs index 0d7c67d8..a4d410ed 100644 --- a/zebra-network/src/peer/server.rs +++ b/zebra-network/src/peer/server.rs @@ -27,12 +27,12 @@ pub(super) enum State { AwaitingRequest, /// Awaiting a peer message we can interpret as a client request. AwaitingResponse(Request, oneshot::Sender>), - /// A failure has occurred and we are shutting down the server. + /// A failure has occurred and we are shutting down the connection. Failed, } -/// The "server" duplex half of a peer connection. -pub struct Server { +/// The state associated with a peer connection. +pub struct Connection { pub(super) state: State, /// A timeout for a client request. This is stored separately from /// State so that we can move the future out of it independently of @@ -40,19 +40,19 @@ pub struct Server { pub(super) request_timer: Option, pub(super) svc: S, pub(super) client_rx: mpsc::Receiver, - /// A slot shared between the client and server for storing an error. + /// A slot for an error shared between the Connection and the Client that uses it. pub(super) error_slot: ErrorSlot, //pub(super) peer_rx: Rx, pub(super) peer_tx: Tx, } -impl Server +impl Connection where S: Service, S::Error: Into, Tx: Sink + Unpin, { - /// Run this peer server to completion. + /// Consume this `Connection` to form a spawnable future containing its event loop. pub async fn run(mut self, mut peer_rx: Rx) where Rx: Stream> + Unpin, @@ -163,7 +163,7 @@ where .lock() .expect("mutex should be unpoisoned"); if guard.is_some() { - panic!("called fail_with on already-failed server state"); + panic!("called fail_with on already-failed connection state"); } else { *guard = Some(Arc::new(e).into()); } @@ -195,7 +195,7 @@ where // Inner match returns Result with the new state or an error. // Outer match updates state or fails. match match (&self.state, req) { - (Failed, _) => panic!("failed service cannot handle requests"), + (Failed, _) => panic!("failed connection cannot handle requests"), (AwaitingResponse { .. }, _) => panic!("tried to update pending request"), (AwaitingRequest, GetPeers) => self .peer_tx