From 3c225550ee22dbcb07391ab568c01d61ce352b1a Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 23 Feb 2021 10:54:48 +1000 Subject: [PATCH] Revert "rename transitions from Exit to Close" This reverts commit cfc4717b987f3b6642eabfecb0750ece5d92c9e4. --- zebra-network/src/peer/connection.rs | 58 +++++++++++++--------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/zebra-network/src/peer/connection.rs b/zebra-network/src/peer/connection.rs index 7be5b8ee4..3d952d66f 100644 --- a/zebra-network/src/peer/connection.rs +++ b/zebra-network/src/peer/connection.rs @@ -335,19 +335,17 @@ impl State { State::AwaitingRequest => { trace!("awaiting client request or peer message"); match future::select(peer_rx.next(), conn.client_rx.next()).await { - Either::Left((None, _)) => { - Transition::Close(PeerError::ConnectionClosed.into()) - } - Either::Left((Some(Err(e)), _)) => Transition::Close(e.into()), + Either::Left((None, _)) => Transition::Exit(PeerError::ConnectionClosed.into()), + Either::Left((Some(Err(e)), _)) => Transition::Exit(e.into()), Either::Left((Some(Ok(msg)), _)) => { match conn.handle_message_as_request(msg).await { Ok(()) => Transition::AwaitRequest, - Err(e) => Transition::Close(e.into()), + Err(e) => Transition::Exit(e.into()), } } Either::Right((None, _)) => { trace!("client_rx closed, ending connection"); - Transition::ClientClose + Transition::ExitClient } Either::Right((Some(req), _)) => { if req.tx.is_canceled() { @@ -380,13 +378,11 @@ impl State { .instrument(span.clone()) .await { - Either::Left((None, _)) => Transition::CloseResponse { + Either::Left((None, _)) => Transition::ExitResponse { e: PeerError::ConnectionClosed.into(), tx, }, - Either::Left((Some(Err(e)), _)) => { - Transition::CloseResponse { e: e.into(), tx } - } + Either::Left((Some(Err(e)), _)) => Transition::ExitResponse { e: e.into(), tx }, Either::Left((Some(Ok(peer_msg)), _cancel)) => { let request_msg = span.in_scope(|| handler.process_message(peer_msg)); // If the message was not consumed, check whether it @@ -399,7 +395,7 @@ impl State { Transition::AwaitResponse { tx, handler, span } // Transition::AwaitRequest } - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } else { // Otherwise, check whether the handler is finished @@ -417,7 +413,7 @@ impl State { trace!(parent: &span, "client request timed out"); let e = PeerError::ClientRequestTimeout; match handler { - Handler::Ping(_) => Transition::CloseResponse { e: e.into(), tx }, + Handler::Ping(_) => Transition::ExitResponse { e: e.into(), tx }, _ => { let _ = tx.send(Err(e.into())); Transition::AwaitRequest @@ -443,13 +439,13 @@ enum Transition { tx: MustUseOneshotSender>, span: tracing::Span, }, - /// Closing because the client was closed or dropped, and there are + /// Exiting because the client was closed or dropped, and there are /// no more client requests. - ClientClose, - /// Closing while awaiting further client requests - Close(SharedPeerError), - /// Closing while processing a peer response to a client request - CloseResponse { + ExitClient, + /// Exiting while awaiting further client requests + Exit(SharedPeerError), + /// Exiting while processing a peer response to a client request + ExitResponse { tx: MustUseOneshotSender>, e: SharedPeerError, }, @@ -464,9 +460,9 @@ impl TryFrom for State { Transition::AwaitResponse { handler, tx, span } => { Ok(State::AwaitingResponse { handler, tx, span }) } - Transition::ClientClose => Err(None), - Transition::Close(e) => Err(Some(e)), - Transition::CloseResponse { tx, e } => { + Transition::ExitClient => Err(None), + Transition::Exit(e) => Err(Some(e)), + Transition::ExitResponse { tx, e } => { let _ = tx.send(Err(e.clone())); Err(Some(e)) } @@ -571,7 +567,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, }, Ping(nonce) => match self.peer_tx.send(Message::Ping(nonce)).await { Ok(()) => Transition::AwaitResponse { @@ -579,7 +575,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, }, BlocksByHash(hashes) => { match self @@ -597,7 +593,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } TransactionsByHash(hashes) => { @@ -616,7 +612,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } FindBlocks { known_blocks, stop } => { @@ -630,7 +626,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } FindHeaders { known_blocks, stop } => { @@ -644,7 +640,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } MempoolTransactions => match self.peer_tx.send(Message::Mempool).await { @@ -653,7 +649,7 @@ where tx, span, }, - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, }, PushTransaction(transaction) => { match self.peer_tx.send(Message::Tx(transaction)).await { @@ -663,7 +659,7 @@ where let _ = tx.send(Ok(Response::Nil)); Transition::AwaitRequest } - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } AdvertiseTransactions(hashes) => { @@ -678,7 +674,7 @@ where let _ = tx.send(Ok(Response::Nil)); Transition::AwaitRequest } - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } AdvertiseBlock(hash) => { @@ -689,7 +685,7 @@ where let _ = tx.send(Ok(Response::Nil)); Transition::AwaitRequest } - Err(e) => Transition::CloseResponse { e: e.into(), tx }, + Err(e) => Transition::ExitResponse { e: e.into(), tx }, } } }