@@ -530,6 +530,25 @@ pub enum Event {
530530 /// serialized prior to LDK version 0.0.117.
531531 sender_intended_total_msat : Option < u64 > ,
532532 } ,
533+ /// Indicates that a peer connection with a node is needed in order to send an [`OnionMessage`].
534+ ///
535+ /// Typically, this happens when a [`MessageRouter`] is unable to find a complete path to a
536+ /// [`Destination`]. Once a connection is established, any messages buffered by an
537+ /// [`OnionMessageHandler`] may be sent.
538+ ///
539+ /// This event will not be generated for onion message forwards; only for sends including
540+ /// replies. Handlers should connect to the node otherwise any buffered messages may be lost.
541+ ///
542+ /// [`OnionMessage`]: msgs::OnionMessage
543+ /// [`MessageRouter`]: crate::onion_message::MessageRouter
544+ /// [`Destination`]: crate::onion_message::Destination
545+ /// [`OnionMessageHandler`]: crate::ln::msgs::OnionMessageHandler
546+ ConnectionNeeded {
547+ /// The node id for the node needing a connection.
548+ node_id : PublicKey ,
549+ /// Sockets for connecting to the node.
550+ addresses : Vec < msgs:: SocketAddress > ,
551+ } ,
533552 /// Indicates a request for an invoice failed to yield a response in a reasonable amount of time
534553 /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an
535554 /// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed.
@@ -1190,6 +1209,10 @@ impl Writeable for Event {
11901209 ( 0 , payment_id, required) ,
11911210 } )
11921211 } ,
1212+ & Event :: ConnectionNeeded { .. } => {
1213+ 35u8 . write ( writer) ?;
1214+ // Never write ConnectionNeeded events as buffered onion messages aren't serialized.
1215+ } ,
11931216 // Note that, going forward, all new events must only write data inside of
11941217 // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
11951218 // data via `write_tlv_fields`.
@@ -1200,8 +1223,7 @@ impl Writeable for Event {
12001223impl MaybeReadable for Event {
12011224 fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , msgs:: DecodeError > {
12021225 match Readable :: read ( reader) ? {
1203- // Note that we do not write a length-prefixed TLV for FundingGenerationReady events,
1204- // unlike all other events, thus we return immediately here.
1226+ // Note that we do not write a length-prefixed TLV for FundingGenerationReady events.
12051227 0u8 => Ok ( None ) ,
12061228 1u8 => {
12071229 let f = || {
@@ -1588,6 +1610,8 @@ impl MaybeReadable for Event {
15881610 } ;
15891611 f ( )
15901612 } ,
1613+ // Note that we do not write a length-prefixed TLV for ConnectionNeeded events.
1614+ 35u8 => Ok ( None ) ,
15911615 // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
15921616 // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
15931617 // reads.
0 commit comments