MessageHandler

Struct MessageHandler 

Source
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

Source

pub fn new() -> Self

Creates a new instance of a MessageHandler

Source

pub fn get_and_clear_received_messages(&self) -> Vec<(PublicKey, Message)>

Returns the messages received by the message handler and empty the receiving buffer.

Source

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.

Source

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.

Source§

fn peer_connected( &self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool, ) -> Result<(), ()>

Handle a peer connecting. Read more
Source§

fn peer_disconnected(&self, _their_node_id: PublicKey)

Indicates a peer disconnected.
Source§

fn handle_custom_message( &self, msg: WireMessage, org: PublicKey, ) -> Result<(), LightningError>

Handles the given message sent from 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)>

Returns the list of pending messages that were generated by the handler, clearing the list in the process. Each message is paired with the node id of the intended recipient. If no connection to the node exists, then the message is simply not sent.
Source§

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.
Source§

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.
Source§

impl CustomMessageReader for MessageHandler

Implementation of the CustomMessageReader trait is required to decode custom messages in the LDK.

Source§

type CustomMessage = WireMessage

The type of the message decoded by the implementation.
Source§

fn read<R: Read>( &self, msg_type: u16, buffer: &mut R, ) -> Result<Option<WireMessage>, DecodeError>

Decodes a custom message to 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.
Source§

impl Default for MessageHandler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V