chore: rename to_session variable (#3359)

This commit is contained in:
Matthias Seitz
2023-06-23 21:56:55 +02:00
committed by GitHub
parent 02673f2301
commit 4c84d22e36
2 changed files with 16 additions and 14 deletions

View File

@ -76,7 +76,7 @@ pub(crate) struct ActiveSession {
/// Incoming commands from the manager
pub(crate) commands_rx: ReceiverStream<SessionCommand>,
/// Sink to send messages to the [`SessionManager`](super::SessionManager).
pub(crate) to_session: MeteredSender<ActiveSessionMessage>,
pub(crate) to_session_manager: MeteredSender<ActiveSessionMessage>,
/// A message that needs to be delivered to the session manager
pub(crate) pending_message_to_session: Option<ActiveSessionMessage>,
/// Incoming request to send to delegate to the remote peer.
@ -300,7 +300,7 @@ impl ActiveSession {
#[allow(clippy::result_large_err)]
fn try_emit_broadcast(&self, message: PeerMessage) -> Result<(), ActiveSessionMessage> {
match self
.to_session
.to_session_manager
.try_send(ActiveSessionMessage::ValidMessage { peer_id: self.remote_peer_id, message })
{
Ok(_) => Ok(()),
@ -325,7 +325,7 @@ impl ActiveSession {
#[allow(clippy::result_large_err)]
fn try_emit_request(&self, message: PeerMessage) -> Result<(), ActiveSessionMessage> {
match self
.to_session
.to_session_manager
.try_send(ActiveSessionMessage::ValidMessage { peer_id: self.remote_peer_id, message })
{
Ok(_) => Ok(()),
@ -350,7 +350,7 @@ impl ActiveSession {
/// Notify the manager that the peer sent a bad message
fn on_bad_message(&self) {
let _ = self
.to_session
.to_session_manager
.try_send(ActiveSessionMessage::BadMessage { peer_id: self.remote_peer_id });
}
@ -358,7 +358,7 @@ impl ActiveSession {
fn emit_disconnect(&self) {
trace!(target: "net::session", remote_peer_id=?self.remote_peer_id, "emitting disconnect");
// NOTE: we clone here so there's enough capacity to deliver this message
let _ = self.to_session.clone().try_send(ActiveSessionMessage::Disconnected {
let _ = self.to_session_manager.clone().try_send(ActiveSessionMessage::Disconnected {
peer_id: self.remote_peer_id,
remote_addr: self.remote_addr,
});
@ -367,11 +367,13 @@ impl ActiveSession {
/// Report back that this session has been closed due to an error
fn close_on_error(&self, error: EthStreamError) {
// NOTE: we clone here so there's enough capacity to deliver this message
let _ = self.to_session.clone().try_send(ActiveSessionMessage::ClosedOnConnectionError {
peer_id: self.remote_peer_id,
remote_addr: self.remote_addr,
error,
});
let _ = self.to_session_manager.clone().try_send(
ActiveSessionMessage::ClosedOnConnectionError {
peer_id: self.remote_peer_id,
remote_addr: self.remote_addr,
error,
},
);
}
/// Starts the disconnect process
@ -530,7 +532,7 @@ impl Future for ActiveSession {
// try to resend the pending message that we could not send because the channel was
// full.
if let Some(msg) = this.pending_message_to_session.take() {
match this.to_session.try_send(msg) {
match this.to_session_manager.try_send(msg) {
Ok(_) => {}
Err(err) => {
match err {
@ -594,7 +596,7 @@ impl Future for ActiveSession {
let _ = this.internal_request_timeout_interval.poll_tick(cx);
// check for timed out requests
if this.check_timed_out_requests(Instant::now()) {
let _ = this.to_session.clone().try_send(
let _ = this.to_session_manager.clone().try_send(
ActiveSessionMessage::ProtocolBreach { peer_id: this.remote_peer_id },
);
}
@ -829,7 +831,7 @@ mod tests {
remote_capabilities: Arc::clone(&capabilities),
session_id,
commands_rx: ReceiverStream::new(commands_rx),
to_session: MeteredSender::new(
to_session_manager: MeteredSender::new(
self.active_session_tx.clone(),
"network_active_session",
),

View File

@ -441,7 +441,7 @@ impl SessionManager {
remote_capabilities: Arc::clone(&capabilities),
session_id,
commands_rx: ReceiverStream::new(commands_rx),
to_session: self.active_session_tx.clone(),
to_session_manager: self.active_session_tx.clone(),
pending_message_to_session: None,
internal_request_tx: ReceiverStream::new(messages_rx).fuse(),
inflight_requests: Default::default(),