pub struct OnionMessenger<ES, NS, L, MR, OMH, CMH>
where ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref, <ES as Deref>::Target: EntropySource, <NS as Deref>::Target: NodeSigner, <L as Deref>::Target: Logger, <MR as Deref>::Target: MessageRouter, <OMH as Deref>::Target: OffersMessageHandler, <CMH as Deref>::Target: CustomOnionMessageHandler,
{ /* 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 path = OnionMessagePath {
	intermediate_nodes: vec![hop_node_id1, hop_node_id2],
	destination: Destination::Node(destination_node_id),
};
let reply_path = None;
onion_messenger.send_onion_message(path, 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_for_message(&hops, &keys_manager, &secp_ctx).unwrap();

// Send a custom onion message to a blinded path.
let path = OnionMessagePath {
	intermediate_nodes: vec![hop_node_id1, hop_node_id2],
	destination: Destination::BlindedPath(blinded_path),
};
let reply_path = None;
onion_messenger.send_onion_message(path, message, reply_path);

Implementations§

§

impl<ES, NS, L, MR, OMH, CMH> OnionMessenger<ES, NS, L, MR, OMH, CMH>
where ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref, <ES as Deref>::Target: EntropySource, <NS as Deref>::Target: NodeSigner, <L as Deref>::Target: Logger, <MR as Deref>::Target: MessageRouter, <OMH as Deref>::Target: OffersMessageHandler, <CMH as Deref>::Target: CustomOnionMessageHandler,

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

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

pub fn send_onion_message<T>( &self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>, ) -> Result<(), SendError>

Sends an OnionMessage with the given contents for sending to the destination of path.

See OnionMessenger for example usage.

Trait Implementations§

§

impl<ES, NS, L, MR, OMH, CMH> OnionMessageHandler for OnionMessenger<ES, NS, L, MR, OMH, CMH>
where ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref, <ES as Deref>::Target: EntropySource, <NS as Deref>::Target: NodeSigner, <L as Deref>::Target: Logger, <MR as Deref>::Target: MessageRouter, <OMH as Deref>::Target: OffersMessageHandler, <CMH as Deref>::Target: CustomOnionMessageHandler,

§

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

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn type_name(&self) -> &'static str

Gets the type name of self
§

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
§

impl<T> Downcast for T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
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> Same for T

§

type Output = T

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

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