pub struct MessageHandler { /* private fields */ }Expand description
MessageHandler is used to send and receive messages through the custom message handling mechanism of the LDK. It also handles message segmentation by splitting large messages when sending and re-constructing them when receiving.
Implementations§
Source§impl MessageHandler
impl MessageHandler
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of a MessageHandler
Sourcepub fn get_and_clear_received_messages(&self) -> Vec<(PublicKey, Message)>
pub fn get_and_clear_received_messages(&self) -> Vec<(PublicKey, Message)>
Returns the messages received by the message handler and empty the receiving buffer.
Sourcepub fn send_message(&self, node_id: PublicKey, msg: Message)
pub fn send_message(&self, node_id: PublicKey, msg: Message)
Send a message to the peer with given node id. Not that the message is not
sent right away, but only when the LDK
lightning::ln::peer_handler::PeerManager::process_events is next called.
Sourcepub fn has_pending_messages(&self) -> bool
pub fn has_pending_messages(&self) -> bool
Returns whether the message handler has any message to be sent.
Trait Implementations§
Source§impl CustomMessageHandler for MessageHandler
Implementation of the CustomMessageHandler trait is required to handle
custom messages in the LDK.
impl CustomMessageHandler for MessageHandler
Implementation of the CustomMessageHandler trait is required to handle
custom messages in the LDK.
Source§fn 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<(), ()>
Source§fn peer_disconnected(&self, _their_node_id: PublicKey)
fn peer_disconnected(&self, _their_node_id: PublicKey)
Source§fn handle_custom_message(
&self,
msg: WireMessage,
org: PublicKey,
) -> Result<(), LightningError>
fn handle_custom_message( &self, msg: WireMessage, org: PublicKey, ) -> Result<(), LightningError>
sender_node_id, possibly producing messages for
CustomMessageHandler::get_and_clear_pending_msg to return and thus for PeerManager
to send.Source§fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)>
fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)>
Source§fn provided_node_features(&self) -> NodeFeatures
fn provided_node_features(&self) -> NodeFeatures
NodeFeatures
which are broadcasted in our NodeAnnouncement message.Source§fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures
fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures
InitFeatures
which are sent in our Init message.Source§impl CustomMessageReader for MessageHandler
Implementation of the CustomMessageReader trait is required to decode
custom messages in the LDK.
impl CustomMessageReader for MessageHandler
Implementation of the CustomMessageReader trait is required to decode
custom messages in the LDK.
Source§type CustomMessage = WireMessage
type CustomMessage = WireMessage
Source§fn read<R: Read>(
&self,
msg_type: u16,
buffer: &mut R,
) -> Result<Option<WireMessage>, DecodeError>
fn read<R: Read>( &self, msg_type: u16, buffer: &mut R, ) -> Result<Option<WireMessage>, DecodeError>
CustomMessageType. If the given message type is known to the
implementation and the message could be decoded, must return Ok(Some(message)). If the
message type is unknown to the implementation, must return Ok(None). If a decoding error
occur, must return Err(DecodeError::X) where X details the encountered error.