Skip to content

Commit

Permalink
feat(network): convert handler event to behaviour event
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama committed Oct 1, 2023
1 parent 930ec48 commit 638623d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/papyrus_network/src/streamed_data_protocol/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -42,6 +42,38 @@ pub(crate) enum SessionError {
RemoteDoesntSupportProtocol,
}

impl<Query: QueryBound, Data: DataBound> From<GenericEvent<Query, Data, HandlerSessionError>>
for GenericEvent<Query, Data, SessionError>
{
fn from(event: GenericEvent<Query, Data, HandlerSessionError>) -> 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<Query, Data> = GenericEvent<Query, Data, SessionError>;

// TODO(shahak) remove allow dead code.
Expand Down

0 comments on commit 638623d

Please sign in to comment.