@@ -81,20 +81,20 @@ impl OffersMessageHandler for TestOffersMessageHandler {
81
81
82
82
#[ derive( Clone , Debug , PartialEq ) ]
83
83
enum TestCustomMessage {
84
- Request ,
85
- Response ,
84
+ Ping ,
85
+ Pong ,
86
86
}
87
87
88
- const CUSTOM_REQUEST_MESSAGE_TYPE : u64 = 4242 ;
89
- const CUSTOM_RESPONSE_MESSAGE_TYPE : u64 = 4343 ;
90
- const CUSTOM_REQUEST_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
91
- const CUSTOM_RESPONSE_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 43 ; 32 ] ;
88
+ const CUSTOM_PING_MESSAGE_TYPE : u64 = 4242 ;
89
+ const CUSTOM_PONG_MESSAGE_TYPE : u64 = 4343 ;
90
+ const CUSTOM_PING_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
91
+ const CUSTOM_PONG_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 43 ; 32 ] ;
92
92
93
93
impl OnionMessageContents for TestCustomMessage {
94
94
fn tlv_type ( & self ) -> u64 {
95
95
match self {
96
- TestCustomMessage :: Request => CUSTOM_REQUEST_MESSAGE_TYPE ,
97
- TestCustomMessage :: Response => CUSTOM_RESPONSE_MESSAGE_TYPE ,
96
+ TestCustomMessage :: Ping => CUSTOM_PING_MESSAGE_TYPE ,
97
+ TestCustomMessage :: Pong => CUSTOM_PONG_MESSAGE_TYPE ,
98
98
}
99
99
}
100
100
fn msg_type ( & self ) -> & ' static str {
@@ -105,8 +105,8 @@ impl OnionMessageContents for TestCustomMessage {
105
105
impl Writeable for TestCustomMessage {
106
106
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
107
107
match self {
108
- TestCustomMessage :: Request => Ok ( CUSTOM_REQUEST_MESSAGE_CONTENTS . write ( w) ?) ,
109
- TestCustomMessage :: Response => Ok ( CUSTOM_RESPONSE_MESSAGE_CONTENTS . write ( w) ?) ,
108
+ TestCustomMessage :: Ping => Ok ( CUSTOM_PING_MESSAGE_CONTENTS . write ( w) ?) ,
109
+ TestCustomMessage :: Pong => Ok ( CUSTOM_PONG_MESSAGE_CONTENTS . write ( w) ?) ,
110
110
}
111
111
}
112
112
}
@@ -144,8 +144,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
144
144
None => panic ! ( "Unexpected message: {:?}" , msg) ,
145
145
}
146
146
let response_option = match msg {
147
- TestCustomMessage :: Request => Some ( TestCustomMessage :: Response ) ,
148
- TestCustomMessage :: Response => None ,
147
+ TestCustomMessage :: Ping => Some ( TestCustomMessage :: Pong ) ,
148
+ TestCustomMessage :: Pong => None ,
149
149
} ;
150
150
if let ( Some ( response) , Some ( responder) ) = ( response_option, responder) {
151
151
responder. respond ( response)
@@ -155,15 +155,15 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
155
155
}
156
156
fn read_custom_message < R : io:: Read > ( & self , message_type : u64 , buffer : & mut R ) -> Result < Option < Self :: CustomMessage > , DecodeError > where Self : Sized {
157
157
match message_type {
158
- CUSTOM_REQUEST_MESSAGE_TYPE => {
158
+ CUSTOM_PING_MESSAGE_TYPE => {
159
159
let buf = read_to_end ( buffer) ?;
160
- assert_eq ! ( buf, CUSTOM_REQUEST_MESSAGE_CONTENTS ) ;
161
- Ok ( Some ( TestCustomMessage :: Request ) )
160
+ assert_eq ! ( buf, CUSTOM_PING_MESSAGE_CONTENTS ) ;
161
+ Ok ( Some ( TestCustomMessage :: Ping ) )
162
162
} ,
163
- CUSTOM_RESPONSE_MESSAGE_TYPE => {
163
+ CUSTOM_PONG_MESSAGE_TYPE => {
164
164
let buf = read_to_end ( buffer) ?;
165
- assert_eq ! ( buf, CUSTOM_RESPONSE_MESSAGE_CONTENTS ) ;
166
- Ok ( Some ( TestCustomMessage :: Response ) )
165
+ assert_eq ! ( buf, CUSTOM_PONG_MESSAGE_CONTENTS ) ;
166
+ Ok ( Some ( TestCustomMessage :: Pong ) )
167
167
} ,
168
168
_ => Ok ( None ) ,
169
169
}
@@ -298,18 +298,18 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
298
298
#[ test]
299
299
fn one_unblinded_hop ( ) {
300
300
let nodes = create_nodes ( 2 ) ;
301
- let test_msg = TestCustomMessage :: Response ;
301
+ let test_msg = TestCustomMessage :: Pong ;
302
302
303
303
let destination = Destination :: Node ( nodes[ 1 ] . node_id ) ;
304
304
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
305
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
305
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
306
306
pass_along_path ( & nodes) ;
307
307
}
308
308
309
309
#[ test]
310
310
fn two_unblinded_hops ( ) {
311
311
let nodes = create_nodes ( 3 ) ;
312
- let test_msg = TestCustomMessage :: Response ;
312
+ let test_msg = TestCustomMessage :: Pong ;
313
313
314
314
let path = OnionMessagePath {
315
315
intermediate_nodes : vec ! [ nodes[ 1 ] . node_id] ,
@@ -318,27 +318,27 @@ fn two_unblinded_hops() {
318
318
} ;
319
319
320
320
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
321
- nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
321
+ nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
322
322
pass_along_path ( & nodes) ;
323
323
}
324
324
325
325
#[ test]
326
326
fn one_blinded_hop ( ) {
327
327
let nodes = create_nodes ( 2 ) ;
328
- let test_msg = TestCustomMessage :: Response ;
328
+ let test_msg = TestCustomMessage :: Pong ;
329
329
330
330
let secp_ctx = Secp256k1 :: new ( ) ;
331
331
let blinded_path = BlindedPath :: new_for_message ( & [ ] , nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
332
332
let destination = Destination :: BlindedPath ( blinded_path) ;
333
333
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
334
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
334
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
335
335
pass_along_path ( & nodes) ;
336
336
}
337
337
338
338
#[ test]
339
339
fn two_unblinded_two_blinded ( ) {
340
340
let nodes = create_nodes ( 5 ) ;
341
- let test_msg = TestCustomMessage :: Response ;
341
+ let test_msg = TestCustomMessage :: Pong ;
342
342
343
343
let secp_ctx = Secp256k1 :: new ( ) ;
344
344
let intermediate_nodes = [ ForwardNode { node_id : nodes[ 3 ] . node_id , short_channel_id : None } ] ;
@@ -350,14 +350,14 @@ fn two_unblinded_two_blinded() {
350
350
} ;
351
351
352
352
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
353
- nodes[ 4 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
353
+ nodes[ 4 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
354
354
pass_along_path ( & nodes) ;
355
355
}
356
356
357
357
#[ test]
358
358
fn three_blinded_hops ( ) {
359
359
let nodes = create_nodes ( 4 ) ;
360
- let test_msg = TestCustomMessage :: Response ;
360
+ let test_msg = TestCustomMessage :: Pong ;
361
361
362
362
let secp_ctx = Secp256k1 :: new ( ) ;
363
363
let intermediate_nodes = [
@@ -368,7 +368,7 @@ fn three_blinded_hops() {
368
368
let destination = Destination :: BlindedPath ( blinded_path) ;
369
369
370
370
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
371
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
371
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
372
372
pass_along_path ( & nodes) ;
373
373
}
374
374
@@ -382,7 +382,7 @@ fn async_response_over_one_blinded_hop() {
382
382
let bob = & nodes[ 1 ] ;
383
383
384
384
// 2. Define the message sent from Bob to Alice.
385
- let message = TestCustomMessage :: Request ;
385
+ let message = TestCustomMessage :: Ping ;
386
386
let path_id = Some ( [ 2 ; 32 ] ) ;
387
387
388
388
// 3. Simulate the creation of a Blinded Reply path provided by Bob.
@@ -402,7 +402,7 @@ fn async_response_over_one_blinded_hop() {
402
402
Ok ( Some ( SendSuccess :: Buffered ) ) ,
403
403
) ;
404
404
405
- bob. custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
405
+ bob. custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
406
406
407
407
pass_along_path ( & nodes) ;
408
408
}
@@ -411,7 +411,7 @@ fn async_response_over_one_blinded_hop() {
411
411
fn too_big_packet_error ( ) {
412
412
// Make sure we error as expected if a packet is too big to send.
413
413
let nodes = create_nodes ( 2 ) ;
414
- let test_msg = TestCustomMessage :: Response ;
414
+ let test_msg = TestCustomMessage :: Pong ;
415
415
416
416
let hop_node_id = nodes[ 1 ] . node_id ;
417
417
let hops = vec ! [ hop_node_id; 400 ] ;
@@ -429,7 +429,7 @@ fn we_are_intro_node() {
429
429
// If we are sending straight to a blinded path and we are the introduction node, we need to
430
430
// advance the blinded path by 1 hop so the second hop is the new introduction node.
431
431
let mut nodes = create_nodes ( 3 ) ;
432
- let test_msg = TestCustomMessage :: Response ;
432
+ let test_msg = TestCustomMessage :: Pong ;
433
433
434
434
let secp_ctx = Secp256k1 :: new ( ) ;
435
435
let intermediate_nodes = [
@@ -440,15 +440,15 @@ fn we_are_intro_node() {
440
440
let destination = Destination :: BlindedPath ( blinded_path) ;
441
441
442
442
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination, None ) . unwrap ( ) ;
443
- nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
443
+ nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
444
444
pass_along_path ( & nodes) ;
445
445
446
446
// Try with a two-hop blinded path where we are the introduction node.
447
447
let intermediate_nodes = [ ForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ] ;
448
448
let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
449
449
let destination = Destination :: BlindedPath ( blinded_path) ;
450
450
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
451
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
451
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
452
452
nodes. remove ( 2 ) ;
453
453
pass_along_path ( & nodes) ;
454
454
}
@@ -457,7 +457,7 @@ fn we_are_intro_node() {
457
457
fn invalid_blinded_path_error ( ) {
458
458
// Make sure we error as expected if a provided blinded path has 0 hops.
459
459
let nodes = create_nodes ( 3 ) ;
460
- let test_msg = TestCustomMessage :: Response ;
460
+ let test_msg = TestCustomMessage :: Pong ;
461
461
462
462
let secp_ctx = Secp256k1 :: new ( ) ;
463
463
let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
@@ -471,7 +471,7 @@ fn invalid_blinded_path_error() {
471
471
#[ test]
472
472
fn reply_path ( ) {
473
473
let mut nodes = create_nodes ( 4 ) ;
474
- let test_msg = TestCustomMessage :: Request ;
474
+ let test_msg = TestCustomMessage :: Ping ;
475
475
let secp_ctx = Secp256k1 :: new ( ) ;
476
476
477
477
// Destination::Node
@@ -486,10 +486,10 @@ fn reply_path() {
486
486
] ;
487
487
let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
488
488
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) ) . unwrap ( ) ;
489
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
489
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Ping ) ;
490
490
pass_along_path ( & nodes) ;
491
491
// Make sure the last node successfully decoded the reply path.
492
- nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
492
+ nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
493
493
nodes. reverse ( ) ;
494
494
pass_along_path ( & nodes) ;
495
495
@@ -507,11 +507,11 @@ fn reply_path() {
507
507
let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
508
508
509
509
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, Some ( reply_path) ) . unwrap ( ) ;
510
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
510
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Ping ) ;
511
511
pass_along_path ( & nodes) ;
512
512
513
513
// Make sure the last node successfully decoded the reply path.
514
- nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
514
+ nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
515
515
nodes. reverse ( ) ;
516
516
pass_along_path ( & nodes) ;
517
517
}
@@ -545,7 +545,7 @@ fn invalid_custom_message_type() {
545
545
#[ test]
546
546
fn peer_buffer_full ( ) {
547
547
let nodes = create_nodes ( 2 ) ;
548
- let test_msg = TestCustomMessage :: Request ;
548
+ let test_msg = TestCustomMessage :: Ping ;
549
549
let destination = Destination :: Node ( nodes[ 1 ] . node_id ) ;
550
550
for _ in 0 ..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
551
551
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination. clone ( ) , None ) . unwrap ( ) ;
@@ -560,7 +560,7 @@ fn many_hops() {
560
560
// of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`].
561
561
let num_nodes: usize = 25 ;
562
562
let nodes = create_nodes ( num_nodes as u8 ) ;
563
- let test_msg = TestCustomMessage :: Response ;
563
+ let test_msg = TestCustomMessage :: Pong ;
564
564
565
565
let mut intermediate_nodes = vec ! [ ] ;
566
566
for i in 1 ..( num_nodes-1 ) {
@@ -573,14 +573,14 @@ fn many_hops() {
573
573
first_node_addresses : None ,
574
574
} ;
575
575
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
576
- nodes[ num_nodes-1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
576
+ nodes[ num_nodes-1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
577
577
pass_along_path ( & nodes) ;
578
578
}
579
579
580
580
#[ test]
581
581
fn requests_peer_connection_for_buffered_messages ( ) {
582
582
let nodes = create_nodes ( 3 ) ;
583
- let message = TestCustomMessage :: Request ;
583
+ let message = TestCustomMessage :: Ping ;
584
584
let secp_ctx = Secp256k1 :: new ( ) ;
585
585
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
586
586
@@ -618,7 +618,7 @@ fn requests_peer_connection_for_buffered_messages() {
618
618
#[ test]
619
619
fn drops_buffered_messages_waiting_for_peer_connection ( ) {
620
620
let nodes = create_nodes ( 3 ) ;
621
- let message = TestCustomMessage :: Request ;
621
+ let message = TestCustomMessage :: Ping ;
622
622
let secp_ctx = Secp256k1 :: new ( ) ;
623
623
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
624
624
@@ -670,7 +670,7 @@ fn intercept_offline_peer_oms() {
670
670
}
671
671
}
672
672
673
- let message = TestCustomMessage :: Response ;
673
+ let message = TestCustomMessage :: Pong ;
674
674
let secp_ctx = Secp256k1 :: new ( ) ;
675
675
let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
676
676
let blinded_path = BlindedPath :: new_for_message (
@@ -710,7 +710,7 @@ fn intercept_offline_peer_oms() {
710
710
}
711
711
712
712
nodes[ 1 ] . messenger . forward_onion_message ( onion_message, & final_node_vec[ 0 ] . node_id ) . unwrap ( ) ;
713
- final_node_vec[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
713
+ final_node_vec[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
714
714
pass_along_path ( & vec ! [ nodes. remove( 1 ) , final_node_vec. remove( 0 ) ] ) ;
715
715
}
716
716
0 commit comments