pub struct OnionMessenger<ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref>{ /* 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, message_router, &offers_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
	}
}
// Send a custom onion message to a node id.
let destination = Destination::Node(destination_node_id);
let reply_path = None;
onion_messenger.send_onion_message(message, destination, reply_path);

// Create a blinded path to yourself, for someone to send an onion message to.
let hops = [hop_node_id3, hop_node_id4, your_node_id];
let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();

// Send a custom onion message to a blinded path.
let destination = Destination::BlindedPath(blinded_path);
let reply_path = None;
onion_messenger.send_onion_message(message, destination, reply_path);

Implementations§

source§

impl<ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref> OnionMessenger<ES, NS, L, MR, OMH, CMH>

source

pub fn new( entropy_source: ES, node_signer: NS, logger: L, message_router: MR, offers_handler: OMH, custom_handler: CMH ) -> Self

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

source

pub fn send_onion_message<T: OnionMessageContents>( &self, contents: T, destination: Destination, reply_path: Option<BlindedPath> ) -> Result<SendSuccess, SendError>

Sends an OnionMessage with the given contents to destination.

See OnionMessenger for example usage.

Trait Implementations§

source§

impl<ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref> EventsProvider for OnionMessenger<ES, NS, L, MR, OMH, CMH>

source§

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

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

impl<ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref> OnionMessageHandler for OnionMessenger<ES, NS, L, MR, OMH, CMH>

source§

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

Handle an incoming onion_message message from the given peer.
source§

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

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

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

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, MR, OMH, CMH> !Freeze for OnionMessenger<ES, NS, L, MR, OMH, CMH>

§

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

§

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

§

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

§

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

§

impl<ES, NS, L, MR, OMH, CMH> UnwindSafe for OnionMessenger<ES, NS, L, MR, OMH, CMH>
where ES: UnwindSafe, NS: UnwindSafe, L: UnwindSafe, MR: UnwindSafe, OMH: 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
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>,

§

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>,

§

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.