diff --git a/crates/papyrus_network/src/streamed_data_protocol/behaviour.rs b/crates/papyrus_network/src/streamed_data_protocol/behaviour.rs index e53e23ee61..a1b18fab53 100644 --- a/crates/papyrus_network/src/streamed_data_protocol/behaviour.rs +++ b/crates/papyrus_network/src/streamed_data_protocol/behaviour.rs @@ -25,7 +25,7 @@ use libp2p::swarm::{ }; use libp2p::{Multiaddr, PeerId}; -use super::handler::{Handler, RequestFromBehaviourEvent}; +use super::handler::{Handler, RequestFromBehaviourEvent, SessionError as HandlerSessionError}; use super::protocol::PROTOCOL_NAME; use super::{DataBound, GenericEvent, InboundSessionId, OutboundSessionId, QueryBound}; @@ -42,6 +42,38 @@ pub(crate) enum SessionError { RemoteDoesntSupportProtocol, } +impl From> + for GenericEvent +{ + fn from(event: GenericEvent) -> Self { + match event { + GenericEvent::NewInboundSession { query, inbound_session_id, peer_id } => { + Self::NewInboundSession { query, inbound_session_id, peer_id } + } + GenericEvent::ReceivedData { outbound_session_id, data } => { + Self::ReceivedData { outbound_session_id, data } + } + GenericEvent::SessionFailed { + session_id, + error: HandlerSessionError::Timeout { substream_timeout }, + } => Self::SessionFailed { + session_id, + error: SessionError::Timeout { substream_timeout }, + }, + GenericEvent::SessionFailed { + session_id, + error: HandlerSessionError::IOError(error), + } => Self::SessionFailed { session_id, error: SessionError::IOError(error) }, + GenericEvent::SessionClosedByRequest { session_id } => { + Self::SessionClosedByRequest { session_id } + } + GenericEvent::OutboundSessionClosedByPeer { outbound_session_id } => { + Self::OutboundSessionClosedByPeer { outbound_session_id } + } + } + } +} + pub(crate) type Event = GenericEvent; // TODO(shahak) remove allow dead code.