@@ -16,7 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
16
16
use bitcoin:: secp256k1:: { self , PublicKey , Scalar , Secp256k1 , SecretKey } ;
17
17
18
18
use 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 } ;
20
20
use crate :: blinded_path:: utils;
21
21
use crate :: events:: { Event , EventHandler , EventsProvider } ;
22
22
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
@@ -795,8 +795,8 @@ pub trait CustomOnionMessageHandler {
795
795
pub enum PeeledOnion < T : OnionMessageContents > {
796
796
/// Forwarded onion, with the next node id and a new onion
797
797
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 > )
800
800
}
801
801
802
802
@@ -946,9 +946,23 @@ where
946
946
( control_tlvs_ss, custom_handler. deref ( ) , logger. deref ( ) )
947
947
) {
948
948
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,
950
950
} , 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
+ }
952
966
} ,
953
967
Ok ( ( Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
954
968
next_hop, next_blinding_override
@@ -1432,11 +1446,11 @@ where
1432
1446
fn handle_onion_message ( & self , peer_node_id : & PublicKey , msg : & OnionMessage ) {
1433
1447
let logger = WithContext :: from ( & self . logger , Some ( * peer_node_id) , None , None ) ;
1434
1448
match self . peel_onion_message ( msg) {
1435
- Ok ( PeeledOnion :: Receive ( message, path_id , reply_path) ) => {
1449
+ Ok ( PeeledOnion :: Receive ( message, _context , reply_path) ) => {
1436
1450
log_trace ! (
1437
1451
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) ;
1440
1454
1441
1455
let responder = reply_path. map ( Responder :: new) ;
1442
1456
match message {
@@ -1727,7 +1741,7 @@ fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + sec
1727
1741
} , prev_control_tlvs_ss. unwrap ( ) ) ) ;
1728
1742
} else {
1729
1743
payloads. push ( ( Payload :: Receive {
1730
- control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { path_id : None , } ) ,
1744
+ control_tlvs : ReceiveControlTlvs :: Unblinded ( ReceiveTlvs { context : None } ) ,
1731
1745
reply_path : reply_path. take ( ) ,
1732
1746
message,
1733
1747
} , prev_control_tlvs_ss. unwrap ( ) ) ) ;
0 commit comments