@@ -16,7 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1616use bitcoin:: secp256k1:: { self , PublicKey , Scalar , Secp256k1 , SecretKey } ;
1717
1818use crate :: blinded_path:: { BlindedPath , IntroductionNode , NextMessageHop , NodeIdLookUp } ;
19- use crate :: blinded_path:: message:: { advance_path_by_one, ForwardNode , ForwardTlvs , ReceiveTlvs } ;
19+ use crate :: blinded_path:: message:: { advance_path_by_one, ForwardNode , ForwardTlvs , ReceiveTlvs , MessageContext } ;
2020use crate :: blinded_path:: utils;
2121use crate :: events:: { Event , EventHandler , EventsProvider } ;
2222use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
@@ -795,8 +795,8 @@ pub trait CustomOnionMessageHandler {
795795pub enum PeeledOnion < T : OnionMessageContents > {
796796 /// Forwarded onion, with the next node id and a new onion
797797 Forward ( NextMessageHop , OnionMessage ) ,
798- /// Received onion message, with decrypted contents, path_id , and reply path
799- Receive ( ParsedOnionMessageContents < T > , Option < [ u8 ; 32 ] > , Option < BlindedPath > )
798+ /// Received onion message, with decrypted contents, context , and reply path
799+ Receive ( ParsedOnionMessageContents < T > , Option < MessageContext > , Option < BlindedPath > )
800800}
801801
802802
@@ -946,9 +946,23 @@ where
946946 ( control_tlvs_ss, custom_handler. deref ( ) , logger. deref ( ) )
947947 ) {
948948 Ok ( ( Payload :: Receive :: < ParsedOnionMessageContents < <<CMH as Deref >:: Target as CustomOnionMessageHandler >:: CustomMessage > > {
949- message, control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { path_id } ) , reply_path,
949+ message, control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { context } ) , reply_path,
950950 } , None) ) => {
951- Ok ( PeeledOnion : : Receive ( message, path_id, reply_path) )
951+ match ( & message, & context) {
952+ ( _, None ) => {
953+ Ok ( PeeledOnion :: Receive ( message, None , reply_path) )
954+ }
955+ ( ParsedOnionMessageContents :: Offers ( _) , Some ( MessageContext :: Offers ( _) ) ) => {
956+ Ok ( PeeledOnion :: Receive ( message, context, reply_path) )
957+ }
958+ ( ParsedOnionMessageContents :: Custom ( _) , Some ( MessageContext :: Custom ( _) ) ) => {
959+ Ok ( PeeledOnion :: Receive ( message, context, reply_path) )
960+ }
961+ _ => {
962+ log_trace ! ( logger, "Received message was sent on a blinded path with the wrong context." ) ;
963+ Err ( ( ) )
964+ }
965+ }
952966 } ,
953967 Ok ( ( Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
954968 next_hop, next_blinding_override
@@ -1432,11 +1446,11 @@ where
14321446 fn handle_onion_message ( & self , peer_node_id : & PublicKey , msg : & OnionMessage ) {
14331447 let logger = WithContext :: from ( & self . logger , Some ( * peer_node_id) , None , None ) ;
14341448 match self . peel_onion_message ( msg) {
1435- Ok ( PeeledOnion :: Receive ( message, path_id , reply_path) ) => {
1449+ Ok ( PeeledOnion :: Receive ( message, _context , reply_path) ) => {
14361450 log_trace ! (
14371451 logger,
1438- "Received an onion message with path_id {:02x?} and {} reply_path: {:?}" ,
1439- path_id , if reply_path. is_some( ) { "a" } else { "no" } , message) ;
1452+ "Received an onion message with {} reply_path: {:?}" ,
1453+ if reply_path. is_some( ) { "a" } else { "no" } , message) ;
14401454
14411455 let responder = reply_path. map ( Responder :: new) ;
14421456 match message {
@@ -1727,7 +1741,7 @@ fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + sec
17271741 } , prev_control_tlvs_ss. unwrap ( ) ) ) ;
17281742 } else {
17291743 payloads. push ( ( Payload :: Receive {
1730- control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { path_id : None , } ) ,
1744+ control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { context : None } ) ,
17311745 reply_path : reply_path. take ( ) ,
17321746 message,
17331747 } , prev_control_tlvs_ss. unwrap ( ) ) ) ;
0 commit comments