breez_sdk_liquid::lightning_125::onion_message::messenger

Struct OnionMessenger

pub struct OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>{ /* private fields */ }
Expand description

A sender, receiver and forwarder of OnionMessages.

§Handling Messages

OnionMessenger implements OnionMessageHandler, making it responsible for either forwarding messages to peers or delegating to the appropriate handler for the message type. Currently, the available handlers are:

§Sending Messages

OnionMessages are sent initially using OnionMessenger::send_onion_message. When handling a message, the matched handler may return a response message which OnionMessenger will send on its behalf.

§Example

// Create the onion messenger. This must use the same `keys_manager` as is passed to your
// ChannelManager.
let onion_messenger = OnionMessenger::new(
    &keys_manager, &keys_manager, logger, &node_id_lookup, message_router,
    &offers_message_handler, &async_payments_message_handler, &custom_message_handler
);
impl Writeable for YourCustomMessage {
	fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
		// Write your custom onion message to `w`
	}
}
impl OnionMessageContents for YourCustomMessage {
	fn tlv_type(&self) -> u64 {
		your_custom_message_type
	}
	fn msg_type(&self) -> &'static str { "YourCustomMessageType" }
}
// Send a custom onion message to a node id.
let destination = Destination::Node(destination_node_id);
let instructions = MessageSendInstructions::WithoutReplyPath { destination };
onion_messenger.send_onion_message(message, instructions);

// Create a blinded path to yourself, for someone to send an onion message to.
let hops = [
	MessageForwardNode { node_id: hop_node_id3, short_channel_id: None },
	MessageForwardNode { node_id: hop_node_id4, short_channel_id: None },
];
let context = MessageContext::Custom(Vec::new());
let blinded_path = BlindedMessagePath::new(&hops, your_node_id, context, &keys_manager, &secp_ctx).unwrap();

// Send a custom onion message to a blinded path.
let destination = Destination::BlindedPath(blinded_path);
let instructions = MessageSendInstructions::WithoutReplyPath { destination };
onion_messenger.send_onion_message(message, instructions);

Implementations§

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

pub fn new( entropy_source: ES, node_signer: NS, logger: L, node_id_lookup: NL, message_router: MR, offers_handler: OMH, async_payments_handler: APH, custom_handler: CMH, ) -> OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

Constructs a new OnionMessenger to send, forward, and delegate received onion messages to their respective handlers.

pub fn new_with_offline_peer_interception( entropy_source: ES, node_signer: NS, logger: L, node_id_lookup: NL, message_router: MR, offers_handler: OMH, async_payments_handler: APH, custom_handler: CMH, ) -> OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

Similar to Self::new, but rather than dropping onion messages that are intended to be forwarded to offline peers, we will intercept them for later forwarding.

Interception flow:

  1. If an onion message for an offline peer is received, OnionMessenger will generate an Event::OnionMessageIntercepted. Event handlers can then choose to persist this onion message for later forwarding, or drop it.
  2. When the offline peer later comes back online, OnionMessenger will generate an Event::OnionMessagePeerConnected. Event handlers will then fetch all previously intercepted onion messages for this peer.
  3. Once the stored onion messages are fetched, they can finally be forwarded to the now-online peer via Self::forward_onion_message.
§Note

LDK will not rate limit how many Event::OnionMessageIntercepteds are generated, so it is the caller’s responsibility to limit how many onion messages are persisted and only persist onion messages for relevant peers.

pub fn send_onion_message<T>( &self, contents: T, instructions: MessageSendInstructions, ) -> Result<SendSuccess, SendError>

Sends an OnionMessage based on its MessageSendInstructions.

pub fn forward_onion_message( &self, message: OnionMessage, peer_node_id: &PublicKey, ) -> Result<(), SendError>

Forwards an OnionMessage to peer_node_id. Useful if we initialized the OnionMessenger with Self::new_with_offline_peer_interception and want to forward a previously intercepted onion message to a peer that has just come online.

pub fn handle_onion_message_response<T>( &self, response: T, instructions: ResponseInstruction, ) -> Result<SendSuccess, SendError>

Handles the response to an OnionMessage based on its ResponseInstruction, enqueueing any response for sending.

This function is useful for asynchronous handling of OnionMessages. Handlers have the option to return None, indicating that no immediate response should be sent. Then, they can transfer the associated Responder to another task responsible for generating the response asynchronously. Subsequently, when the response is prepared and ready for sending, that task can invoke this method to enqueue the response for delivery.

pub fn get_update_future(&self) -> Future

Gets a Future that completes when an event is available via EventsProvider::process_pending_events or Self::process_pending_events_async.

Note that callbacks registered on the Future MUST NOT call back into this OnionMessenger and should instead register actions to be taken later.

pub async fn process_pending_events_async<Future, H>(&self, handler: H)
where Future: Future<Output = Result<(), ReplayEvent>> + Unpin, H: Fn(Event) -> Future,

Processes any events asynchronously using the given handler.

Note that the event handler is called in the order each event was generated, however futures are polled in parallel for some events to allow for parallelism where events do not have an ordering requirement.

See the trait-level documentation of EventsProvider for requirements.

Trait Implementations§

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> AOnionMessenger for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

§

type EntropySource = <ES as Deref>::Target

A type implementing EntropySource
§

type ES = ES

A type that may be dereferenced to Self::EntropySource
§

type NodeSigner = <NS as Deref>::Target

A type implementing NodeSigner
§

type NS = NS

A type that may be dereferenced to Self::NodeSigner
§

type Logger = <L as Deref>::Target

A type implementing Logger
§

type L = L

A type that may be dereferenced to Self::Logger
§

type NodeIdLookUp = <NL as Deref>::Target

A type implementing NodeIdLookUp
§

type NL = NL

A type that may be dereferenced to Self::NodeIdLookUp
§

type MessageRouter = <MR as Deref>::Target

A type implementing MessageRouter
§

type MR = MR

A type that may be dereferenced to Self::MessageRouter
§

type OffersMessageHandler = <OMH as Deref>::Target

A type implementing OffersMessageHandler
§

type OMH = OMH

A type that may be dereferenced to Self::OffersMessageHandler
§

type AsyncPaymentsMessageHandler = <APH as Deref>::Target

A type implementing AsyncPaymentsMessageHandler
§

type APH = APH

A type that may be dereferenced to Self::AsyncPaymentsMessageHandler
§

type CustomOnionMessageHandler = <CMH as Deref>::Target

A type implementing CustomOnionMessageHandler
§

type CMH = CMH

A type that may be dereferenced to Self::CustomOnionMessageHandler
§

fn get_om(&self) -> &OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

Returns a reference to the actual OnionMessenger object.
§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> EventsProvider for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

§

fn process_pending_events<H>(&self, handler: H)
where H: Deref, <H as Deref>::Target: EventHandler,

Processes any events generated since the last call using the given event handler. Read more
§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> OnionMessageHandler for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

§

fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage)

Handle an incoming onion_message message from the given peer.
§

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

Called when a connection is established with a peer. Can be used to track which peers advertise onion message support and are online. Read more
§

fn peer_disconnected(&self, their_node_id: &PublicKey)

Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to drop and refuse to forward onion messages to this peer.
§

fn timer_tick_occurred(&self)

Performs actions that should happen roughly every ten seconds after startup. Allows handlers to drop any buffered onion messages intended for prospective peers.
§

fn provided_node_features(&self) -> Features<NodeContext>

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

fn provided_init_features( &self, _their_node_id: &PublicKey, ) -> Features<InitContext>

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. Read more
§

fn next_onion_message_for_peer( &self, peer_node_id: PublicKey, ) -> Option<OnionMessage>

Returns the next pending onion message for the peer with the given node id.

Auto Trait Implementations§

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> !Freeze for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> RefUnwindSafe for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> Send for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>
where ES: Send, NS: Send, L: Send, NL: Send, MR: Send, OMH: Send, APH: Send, CMH: Send,

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> Sync for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>
where ES: Sync, NS: Sync, L: Sync, NL: Sync, MR: Sync, OMH: Sync, APH: Sync, CMH: Sync,

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> Unpin for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>
where ES: Unpin, NS: Unpin, L: Unpin, NL: Unpin, MR: Unpin, OMH: Unpin, APH: Unpin, CMH: Unpin,

§

impl<ES, NS, L, NL, MR, OMH, APH, CMH> UnwindSafe for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH>
where ES: UnwindSafe, NS: UnwindSafe, L: UnwindSafe, NL: UnwindSafe, MR: UnwindSafe, OMH: UnwindSafe, APH: UnwindSafe, CMH: UnwindSafe,

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

§

impl<T> TaskRetFutTrait for T
where T: Send,