Revert "rename transitions from Exit to Close"
This reverts commit cfc4717b98
.
This commit is contained in:
parent
86dc66dfa9
commit
3c225550ee
|
@ -335,19 +335,17 @@ impl State {
|
||||||
State::AwaitingRequest => {
|
State::AwaitingRequest => {
|
||||||
trace!("awaiting client request or peer message");
|
trace!("awaiting client request or peer message");
|
||||||
match future::select(peer_rx.next(), conn.client_rx.next()).await {
|
match future::select(peer_rx.next(), conn.client_rx.next()).await {
|
||||||
Either::Left((None, _)) => {
|
Either::Left((None, _)) => Transition::Exit(PeerError::ConnectionClosed.into()),
|
||||||
Transition::Close(PeerError::ConnectionClosed.into())
|
Either::Left((Some(Err(e)), _)) => Transition::Exit(e.into()),
|
||||||
}
|
|
||||||
Either::Left((Some(Err(e)), _)) => Transition::Close(e.into()),
|
|
||||||
Either::Left((Some(Ok(msg)), _)) => {
|
Either::Left((Some(Ok(msg)), _)) => {
|
||||||
match conn.handle_message_as_request(msg).await {
|
match conn.handle_message_as_request(msg).await {
|
||||||
Ok(()) => Transition::AwaitRequest,
|
Ok(()) => Transition::AwaitRequest,
|
||||||
Err(e) => Transition::Close(e.into()),
|
Err(e) => Transition::Exit(e.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Either::Right((None, _)) => {
|
Either::Right((None, _)) => {
|
||||||
trace!("client_rx closed, ending connection");
|
trace!("client_rx closed, ending connection");
|
||||||
Transition::ClientClose
|
Transition::ExitClient
|
||||||
}
|
}
|
||||||
Either::Right((Some(req), _)) => {
|
Either::Right((Some(req), _)) => {
|
||||||
if req.tx.is_canceled() {
|
if req.tx.is_canceled() {
|
||||||
|
@ -380,13 +378,11 @@ impl State {
|
||||||
.instrument(span.clone())
|
.instrument(span.clone())
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Either::Left((None, _)) => Transition::CloseResponse {
|
Either::Left((None, _)) => Transition::ExitResponse {
|
||||||
e: PeerError::ConnectionClosed.into(),
|
e: PeerError::ConnectionClosed.into(),
|
||||||
tx,
|
tx,
|
||||||
},
|
},
|
||||||
Either::Left((Some(Err(e)), _)) => {
|
Either::Left((Some(Err(e)), _)) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
Transition::CloseResponse { e: e.into(), tx }
|
|
||||||
}
|
|
||||||
Either::Left((Some(Ok(peer_msg)), _cancel)) => {
|
Either::Left((Some(Ok(peer_msg)), _cancel)) => {
|
||||||
let request_msg = span.in_scope(|| handler.process_message(peer_msg));
|
let request_msg = span.in_scope(|| handler.process_message(peer_msg));
|
||||||
// If the message was not consumed, check whether it
|
// If the message was not consumed, check whether it
|
||||||
|
@ -399,7 +395,7 @@ impl State {
|
||||||
Transition::AwaitResponse { tx, handler, span }
|
Transition::AwaitResponse { tx, handler, span }
|
||||||
// Transition::AwaitRequest
|
// Transition::AwaitRequest
|
||||||
}
|
}
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, check whether the handler is finished
|
// Otherwise, check whether the handler is finished
|
||||||
|
@ -417,7 +413,7 @@ impl State {
|
||||||
trace!(parent: &span, "client request timed out");
|
trace!(parent: &span, "client request timed out");
|
||||||
let e = PeerError::ClientRequestTimeout;
|
let e = PeerError::ClientRequestTimeout;
|
||||||
match handler {
|
match handler {
|
||||||
Handler::Ping(_) => Transition::CloseResponse { e: e.into(), tx },
|
Handler::Ping(_) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
_ => {
|
_ => {
|
||||||
let _ = tx.send(Err(e.into()));
|
let _ = tx.send(Err(e.into()));
|
||||||
Transition::AwaitRequest
|
Transition::AwaitRequest
|
||||||
|
@ -443,13 +439,13 @@ enum Transition {
|
||||||
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
|
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
|
||||||
span: tracing::Span,
|
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.
|
/// no more client requests.
|
||||||
ClientClose,
|
ExitClient,
|
||||||
/// Closing while awaiting further client requests
|
/// Exiting while awaiting further client requests
|
||||||
Close(SharedPeerError),
|
Exit(SharedPeerError),
|
||||||
/// Closing while processing a peer response to a client request
|
/// Exiting while processing a peer response to a client request
|
||||||
CloseResponse {
|
ExitResponse {
|
||||||
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
|
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
|
||||||
e: SharedPeerError,
|
e: SharedPeerError,
|
||||||
},
|
},
|
||||||
|
@ -464,9 +460,9 @@ impl TryFrom<Transition> for State {
|
||||||
Transition::AwaitResponse { handler, tx, span } => {
|
Transition::AwaitResponse { handler, tx, span } => {
|
||||||
Ok(State::AwaitingResponse { handler, tx, span })
|
Ok(State::AwaitingResponse { handler, tx, span })
|
||||||
}
|
}
|
||||||
Transition::ClientClose => Err(None),
|
Transition::ExitClient => Err(None),
|
||||||
Transition::Close(e) => Err(Some(e)),
|
Transition::Exit(e) => Err(Some(e)),
|
||||||
Transition::CloseResponse { tx, e } => {
|
Transition::ExitResponse { tx, e } => {
|
||||||
let _ = tx.send(Err(e.clone()));
|
let _ = tx.send(Err(e.clone()));
|
||||||
Err(Some(e))
|
Err(Some(e))
|
||||||
}
|
}
|
||||||
|
@ -571,7 +567,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
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 {
|
Ping(nonce) => match self.peer_tx.send(Message::Ping(nonce)).await {
|
||||||
Ok(()) => Transition::AwaitResponse {
|
Ok(()) => Transition::AwaitResponse {
|
||||||
|
@ -579,7 +575,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
},
|
},
|
||||||
BlocksByHash(hashes) => {
|
BlocksByHash(hashes) => {
|
||||||
match self
|
match self
|
||||||
|
@ -597,7 +593,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TransactionsByHash(hashes) => {
|
TransactionsByHash(hashes) => {
|
||||||
|
@ -616,7 +612,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FindBlocks { known_blocks, stop } => {
|
FindBlocks { known_blocks, stop } => {
|
||||||
|
@ -630,7 +626,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FindHeaders { known_blocks, stop } => {
|
FindHeaders { known_blocks, stop } => {
|
||||||
|
@ -644,7 +640,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
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 {
|
MempoolTransactions => match self.peer_tx.send(Message::Mempool).await {
|
||||||
|
@ -653,7 +649,7 @@ where
|
||||||
tx,
|
tx,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
},
|
},
|
||||||
PushTransaction(transaction) => {
|
PushTransaction(transaction) => {
|
||||||
match self.peer_tx.send(Message::Tx(transaction)).await {
|
match self.peer_tx.send(Message::Tx(transaction)).await {
|
||||||
|
@ -663,7 +659,7 @@ where
|
||||||
let _ = tx.send(Ok(Response::Nil));
|
let _ = tx.send(Ok(Response::Nil));
|
||||||
Transition::AwaitRequest
|
Transition::AwaitRequest
|
||||||
}
|
}
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdvertiseTransactions(hashes) => {
|
AdvertiseTransactions(hashes) => {
|
||||||
|
@ -678,7 +674,7 @@ where
|
||||||
let _ = tx.send(Ok(Response::Nil));
|
let _ = tx.send(Ok(Response::Nil));
|
||||||
Transition::AwaitRequest
|
Transition::AwaitRequest
|
||||||
}
|
}
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdvertiseBlock(hash) => {
|
AdvertiseBlock(hash) => {
|
||||||
|
@ -689,7 +685,7 @@ where
|
||||||
let _ = tx.send(Ok(Response::Nil));
|
let _ = tx.send(Ok(Response::Nil));
|
||||||
Transition::AwaitRequest
|
Transition::AwaitRequest
|
||||||
}
|
}
|
||||||
Err(e) => Transition::CloseResponse { e: e.into(), tx },
|
Err(e) => Transition::ExitResponse { e: e.into(), tx },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue