mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
add a helper function for ActiveSession on_request to safely emit_message (#806)
Co-authored-by: turbofish <junwow@amazon.com>
This commit is contained in:
@ -105,7 +105,7 @@ impl ActiveSession {
|
||||
received: Instant::now(),
|
||||
};
|
||||
if self
|
||||
.try_emit_message(PeerMessage::EthRequest(PeerRequest::$req_item {
|
||||
.safe_emit_message(PeerMessage::EthRequest(PeerRequest::$req_item {
|
||||
request,
|
||||
response: tx,
|
||||
}))
|
||||
@ -255,6 +255,18 @@ impl ActiveSession {
|
||||
});
|
||||
}
|
||||
|
||||
/// Send a message back to the [`SessionsManager`]
|
||||
/// covering both broadcasts and incoming requests
|
||||
fn safe_emit_message(
|
||||
&self,
|
||||
message: PeerMessage,
|
||||
) -> Result<(), mpsc::error::TrySendError<ActiveSessionMessage>> {
|
||||
self.to_session
|
||||
// we want this message to always arrive, so we clone the sender
|
||||
.clone()
|
||||
.try_send(ActiveSessionMessage::ValidMessage { peer_id: self.remote_peer_id, message })
|
||||
}
|
||||
|
||||
/// Send a message back to the [`SessionsManager`]
|
||||
fn try_emit_message(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user