libp2p_pubsub_core/protocol/
protocol_trait.rs

1use crate::upgrade::ProtocolUpgradeSend;
2
3use super::router_trait::ProtocolRouter;
4
5/// The pubsub protocol trait.
6///
7/// This trait is used by the [`Behaviour`](crate::behaviour::Behaviour) to identify the pubsub
8/// protocol and create a connection handler instance for the protocol as well as the
9/// [`ProtocolRouter`] instance responsible for routing messages to the appropriate peers.
10pub trait Protocol {
11    type Upgrade: ProtocolUpgradeSend + Clone;
12    type RouterService: ProtocolRouter;
13
14    /// Returns the protocol's upgrade.
15    ///
16    /// See [`ProtocolUpgrade`](crate::upgrade::ProtocolUpgrade) for more information.
17    fn upgrade() -> Self::Upgrade;
18
19    /// Returns the protocol's router service.
20    ///
21    /// See [`ProtocolRouter`] for more information.
22    fn router(&self) -> Self::RouterService;
23}