pub struct OnionMessenger<ES: Deref, NS: Deref, L: Deref, CMH: Deref>where
    ES::Target: EntropySource,
    NS::Target: NodeSigner,
    L::Target: Logger,
    CMH::Target: CustomOnionMessageHandler,{ /* private fields */ }
Expand description

A sender, receiver and forwarder of onion messages. In upcoming releases, this object will be used to retrieve invoices and fulfill invoice requests from offers. Currently, only sending and receiving custom onion messages is supported.

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, &your_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 CustomOnionMessageContents for YourCustomMessage {
	fn tlv_type(&self) -> u64 {
		your_custom_message_type
	}
}
// Send a custom onion message to a node id.
let intermediate_hops = [hop_node_id1, hop_node_id2];
let reply_path = None;
let message = OnionMessageContents::Custom(your_custom_message);
onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, 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(&hops, &keys_manager, &secp_ctx).unwrap();

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

Implementations§

source§

impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessenger<ES, NS, L, CMH>where ES::Target: EntropySource, NS::Target: NodeSigner, L::Target: Logger, CMH::Target: CustomOnionMessageHandler,

source

pub fn new( entropy_source: ES, node_signer: NS, logger: L, 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: CustomOnionMessageContents>( &self, intermediate_nodes: &[PublicKey], destination: Destination, message: OnionMessageContents<T>, reply_path: Option<BlindedPath> ) -> Result<(), SendError>

Send an onion message with contents message to destination, routing it through intermediate_nodes. See OnionMessenger for example usage.

Trait Implementations§

source§

impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessageHandler for OnionMessenger<ES, NS, L, CMH>where ES::Target: EntropySource, NS::Target: NodeSigner, L::Target: Logger, CMH::Target: CustomOnionMessageHandler + Sized,

source§

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

Handle an incoming onion message. Currently, if a message was destined for us we will log, but soon we’ll delegate the onion message to a handler that can generate invoices or send payments.

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

impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessageProvider for OnionMessenger<ES, NS, L, CMH>where ES::Target: EntropySource, NS::Target: NodeSigner, L::Target: Logger, CMH::Target: CustomOnionMessageHandler,

source§

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

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

Auto Trait Implementations§

§

impl<ES, NS, L, CMH> RefUnwindSafe for OnionMessenger<ES, NS, L, CMH>where CMH: RefUnwindSafe, ES: RefUnwindSafe, L: RefUnwindSafe, NS: RefUnwindSafe,

§

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

§

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

§

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

§

impl<ES, NS, L, CMH> UnwindSafe for OnionMessenger<ES, NS, L, CMH>where CMH: UnwindSafe, ES: UnwindSafe, L: UnwindSafe, NS: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.