@@ -29,6 +29,7 @@ use super::packet::{BIG_PACKET_HOP_DATA_LEN, ForwardControlTlvs, Packet, Payload
29
29
use crate :: util:: logger:: Logger ;
30
30
use crate :: util:: ser:: Writeable ;
31
31
32
+ use core:: fmt;
32
33
use core:: ops:: Deref ;
33
34
use crate :: io;
34
35
use crate :: sync:: { Arc , Mutex } ;
@@ -347,52 +348,31 @@ where
347
348
}
348
349
}
349
350
350
- fn respond_with_onion_message < T : CustomOnionMessageContents > (
351
- & self , response : OnionMessageContents < T > , path_id : Option < [ u8 ; 32 ] > ,
352
- reply_path : Option < BlindedPath >
351
+ fn find_path_and_enqueue_onion_message < T : CustomOnionMessageContents > (
352
+ & self , contents : OnionMessageContents < T > , destination : Destination ,
353
+ log_suffix : fmt :: Arguments
353
354
) {
354
355
let sender = match self . node_signer . get_node_id ( Recipient :: Node ) {
355
356
Ok ( node_id) => node_id,
356
357
Err ( _) => {
357
- log_warn ! (
358
- self . logger, "Unable to retrieve node id when responding to onion message with \
359
- path_id {:02x?}", path_id
360
- ) ;
358
+ log_warn ! ( self . logger, "Unable to retrieve node id {}" , log_suffix) ;
361
359
return ;
362
360
}
363
361
} ;
364
362
365
363
let peers = self . pending_messages . lock ( ) . unwrap ( ) . keys ( ) . copied ( ) . collect ( ) ;
366
-
367
- let destination = match reply_path {
368
- Some ( reply_path) => Destination :: BlindedPath ( reply_path) ,
369
- None => {
370
- log_trace ! (
371
- self . logger, "Missing reply path when responding to onion message with path_id \
372
- {:02x?}", path_id
373
- ) ;
374
- return ;
375
- } ,
376
- } ;
377
-
378
364
let path = match self . message_router . find_path ( sender, peers, destination) {
379
365
Ok ( path) => path,
380
366
Err ( ( ) ) => {
381
- log_trace ! (
382
- self . logger, "Failed to find path when responding to onion message with \
383
- path_id {:02x?}", path_id
384
- ) ;
367
+ log_trace ! ( self . logger, "Failed to find path {}" , log_suffix) ;
385
368
return ;
386
369
} ,
387
370
} ;
388
371
389
- log_trace ! ( self . logger, "Responding to onion message with path_id {:02x? }" , path_id ) ;
372
+ log_trace ! ( self . logger, "Sending onion message { }" , log_suffix ) ;
390
373
391
- if let Err ( e) = self . send_onion_message ( path, response, None ) {
392
- log_trace ! (
393
- self . logger, "Failed responding to onion message with path_id {:02x?}: {:?}" ,
394
- path_id, e
395
- ) ;
374
+ if let Err ( e) = self . send_onion_message ( path, contents, None ) {
375
+ log_trace ! ( self . logger, "Failed sending onion message {}: {:?}" , log_suffix, e) ;
396
376
return ;
397
377
}
398
378
}
@@ -493,7 +473,22 @@ where
493
473
} ;
494
474
495
475
if let Some ( response) = response {
496
- self. respond_with_onion_message ( response, path_id, reply_path) ;
476
+ match reply_path {
477
+ Some ( reply_path) => {
478
+ self . find_path_and_enqueue_onion_message (
479
+ response, Destination :: BlindedPath ( reply_path) , format_args ! (
480
+ "when responding to onion message with path_id {:02x?}" , path_id
481
+ )
482
+ ) ;
483
+ } ,
484
+ None => {
485
+ log_trace ! (
486
+ self . logger,
487
+ "Missing reply path when responding to onion message with path_id {:02x?}" ,
488
+ path_id
489
+ ) ;
490
+ } ,
491
+ }
497
492
}
498
493
} ,
499
494
Ok ( ( Payload :: Forward ( ForwardControlTlvs :: Unblinded ( ForwardTlvs {
0 commit comments