pub trait BaseMessageHandler {
// Required methods
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>;
fn peer_disconnected(&self, their_node_id: PublicKey);
fn provided_node_features(&self) -> NodeFeatures;
fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures;
fn peer_connected(
&self,
their_node_id: PublicKey,
msg: &Init,
inbound: bool,
) -> Result<(), ()>;
}Expand description
A trait to describe an object which handles when peers connect + disconnect and generates outbound messages.
It acts as a supertrait for all the P2P message handlers and can contribute to the
InitFeatures which we send to peers or decide to refuse connection to peers.
Required Methods§
Sourcefn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>
Gets the list of pending events which were generated by previous actions, clearing the list in the process.
Sourcefn peer_disconnected(&self, their_node_id: PublicKey)
fn peer_disconnected(&self, their_node_id: PublicKey)
Indicates a connection to the peer failed/an existing connection was lost.
Sourcefn provided_node_features(&self) -> NodeFeatures
fn provided_node_features(&self) -> NodeFeatures
Gets the node feature flags which this handler itself supports. All available handlers are
queried similarly and their feature flags are OR’d together to form the NodeFeatures
which are broadcasted in our NodeAnnouncement message.
Sourcefn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures
fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures
Gets the init feature flags which should be sent to the given peer. All available handlers
are queried similarly and their feature flags are OR’d together to form the InitFeatures
which are sent in our Init message.
Note that this method is called before Self::peer_connected.
Sourcefn peer_connected(
&self,
their_node_id: PublicKey,
msg: &Init,
inbound: bool,
) -> Result<(), ()>
fn peer_connected( &self, their_node_id: PublicKey, msg: &Init, inbound: bool, ) -> Result<(), ()>
Handle a peer (re)connecting.
May return an Err(()) to indicate that we should immediately disconnect from the peer
(e.g. because the features they support are not sufficient to communicate with us).
Note, of course, that other message handlers may wish to communicate with the peer, which disconnecting them will prevent.
Self::peer_disconnected will not be called if Err(()) is returned.