Rename `peer::Server` to `peer::Connection`.

This doesn't change the file path or edit imports so that the diff is easier to review.
This commit is contained in:
Henry de Valence 2020-01-15 19:33:59 -08:00 committed by Deirdre Connolly
parent 619f4c18ea
commit 77ad61331c
3 changed files with 11 additions and 11 deletions

View File

@ -18,4 +18,4 @@ pub use client::Client;
pub use connector::Connector; pub use connector::Connector;
pub use error::{HandshakeError, PeerError, SharedPeerError}; pub use error::{HandshakeError, PeerError, SharedPeerError};
pub use handshake::Handshake; pub use handshake::Handshake;
pub use server::Server; pub use server::Connection;

View File

@ -27,7 +27,7 @@ use crate::{
BoxedStdError, Config, 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 /// A [`Service`] that handshakes with a remote peer and constructs a
/// client/server pair. /// client/server pair.
@ -195,7 +195,7 @@ where
let (peer_tx, peer_rx) = stream.split(); let (peer_tx, peer_rx) = stream.split();
use super::server; use super::server;
let server = Server { let server = Connection {
state: server::State::AwaitingRequest, state: server::State::AwaitingRequest,
svc: internal_service, svc: internal_service,
client_rx: server_rx, client_rx: server_rx,

View File

@ -27,12 +27,12 @@ pub(super) enum State {
AwaitingRequest, AwaitingRequest,
/// Awaiting a peer message we can interpret as a client request. /// Awaiting a peer message we can interpret as a client request.
AwaitingResponse(Request, oneshot::Sender<Result<Response, SharedPeerError>>), AwaitingResponse(Request, oneshot::Sender<Result<Response, SharedPeerError>>),
/// A failure has occurred and we are shutting down the server. /// A failure has occurred and we are shutting down the connection.
Failed, Failed,
} }
/// The "server" duplex half of a peer connection. /// The state associated with a peer connection.
pub struct Server<S, Tx> { pub struct Connection<S, Tx> {
pub(super) state: State, pub(super) state: State,
/// A timeout for a client request. This is stored separately from /// A timeout for a client request. This is stored separately from
/// State so that we can move the future out of it independently of /// State so that we can move the future out of it independently of
@ -40,19 +40,19 @@ pub struct Server<S, Tx> {
pub(super) request_timer: Option<Delay>, pub(super) request_timer: Option<Delay>,
pub(super) svc: S, pub(super) svc: S,
pub(super) client_rx: mpsc::Receiver<ClientRequest>, pub(super) client_rx: mpsc::Receiver<ClientRequest>,
/// 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) error_slot: ErrorSlot,
//pub(super) peer_rx: Rx, //pub(super) peer_rx: Rx,
pub(super) peer_tx: Tx, pub(super) peer_tx: Tx,
} }
impl<S, Tx> Server<S, Tx> impl<S, Tx> Connection<S, Tx>
where where
S: Service<Request, Response = Response, Error = BoxedStdError>, S: Service<Request, Response = Response, Error = BoxedStdError>,
S::Error: Into<BoxedStdError>, S::Error: Into<BoxedStdError>,
Tx: Sink<Message, Error = SerializationError> + Unpin, Tx: Sink<Message, Error = SerializationError> + Unpin,
{ {
/// Run this peer server to completion. /// Consume this `Connection` to form a spawnable future containing its event loop.
pub async fn run<Rx>(mut self, mut peer_rx: Rx) pub async fn run<Rx>(mut self, mut peer_rx: Rx)
where where
Rx: Stream<Item = Result<Message, SerializationError>> + Unpin, Rx: Stream<Item = Result<Message, SerializationError>> + Unpin,
@ -163,7 +163,7 @@ where
.lock() .lock()
.expect("mutex should be unpoisoned"); .expect("mutex should be unpoisoned");
if guard.is_some() { if guard.is_some() {
panic!("called fail_with on already-failed server state"); panic!("called fail_with on already-failed connection state");
} else { } else {
*guard = Some(Arc::new(e).into()); *guard = Some(Arc::new(e).into());
} }
@ -195,7 +195,7 @@ where
// Inner match returns Result with the new state or an error. // Inner match returns Result with the new state or an error.
// Outer match updates state or fails. // Outer match updates state or fails.
match match (&self.state, req) { 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"), (AwaitingResponse { .. }, _) => panic!("tried to update pending request"),
(AwaitingRequest, GetPeers) => self (AwaitingRequest, GetPeers) => self
.peer_tx .peer_tx