@@ -80,20 +80,20 @@ impl OffersMessageHandler for TestOffersMessageHandler {
80
80
81
81
#[ derive( Clone , Debug , PartialEq ) ]
82
82
enum TestCustomMessage {
83
- Request ,
84
- Response ,
83
+ Ping ,
84
+ Pong ,
85
85
}
86
86
87
- const CUSTOM_REQUEST_MESSAGE_TYPE : u64 = 4242 ;
88
- const CUSTOM_RESPONSE_MESSAGE_TYPE : u64 = 4343 ;
89
- const CUSTOM_REQUEST_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
90
- const CUSTOM_RESPONSE_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 43 ; 32 ] ;
87
+ const CUSTOM_PING_MESSAGE_TYPE : u64 = 4242 ;
88
+ const CUSTOM_PONG_MESSAGE_TYPE : u64 = 4343 ;
89
+ const CUSTOM_PING_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
90
+ const CUSTOM_PONG_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 43 ; 32 ] ;
91
91
92
92
impl OnionMessageContents for TestCustomMessage {
93
93
fn tlv_type ( & self ) -> u64 {
94
94
match self {
95
- TestCustomMessage :: Request => CUSTOM_REQUEST_MESSAGE_TYPE ,
96
- TestCustomMessage :: Response => CUSTOM_RESPONSE_MESSAGE_TYPE ,
95
+ TestCustomMessage :: Ping => CUSTOM_PING_MESSAGE_TYPE ,
96
+ TestCustomMessage :: Pong => CUSTOM_PONG_MESSAGE_TYPE ,
97
97
}
98
98
}
99
99
fn msg_type ( & self ) -> & ' static str {
@@ -104,8 +104,8 @@ impl OnionMessageContents for TestCustomMessage {
104
104
impl Writeable for TestCustomMessage {
105
105
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
106
106
match self {
107
- TestCustomMessage :: Request => Ok ( CUSTOM_REQUEST_MESSAGE_CONTENTS . write ( w) ?) ,
108
- TestCustomMessage :: Response => Ok ( CUSTOM_RESPONSE_MESSAGE_CONTENTS . write ( w) ?) ,
107
+ TestCustomMessage :: Ping => Ok ( CUSTOM_PING_MESSAGE_CONTENTS . write ( w) ?) ,
108
+ TestCustomMessage :: Pong => Ok ( CUSTOM_PONG_MESSAGE_CONTENTS . write ( w) ?) ,
109
109
}
110
110
}
111
111
}
@@ -143,8 +143,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
143
143
None => panic ! ( "Unexpected message: {:?}" , msg) ,
144
144
}
145
145
let response_option = match msg {
146
- TestCustomMessage :: Request => Some ( TestCustomMessage :: Response ) ,
147
- TestCustomMessage :: Response => None ,
146
+ TestCustomMessage :: Ping => Some ( TestCustomMessage :: Pong ) ,
147
+ TestCustomMessage :: Pong => None ,
148
148
} ;
149
149
if let ( Some ( response) , Some ( responder) ) = ( response_option, responder) {
150
150
responder. respond ( response)
@@ -154,15 +154,15 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
154
154
}
155
155
fn read_custom_message < R : io:: Read > ( & self , message_type : u64 , buffer : & mut R ) -> Result < Option < Self :: CustomMessage > , DecodeError > where Self : Sized {
156
156
match message_type {
157
- CUSTOM_REQUEST_MESSAGE_TYPE => {
157
+ CUSTOM_PING_MESSAGE_TYPE => {
158
158
let buf = read_to_end ( buffer) ?;
159
- assert_eq ! ( buf, CUSTOM_REQUEST_MESSAGE_CONTENTS ) ;
160
- Ok ( Some ( TestCustomMessage :: Request ) )
159
+ assert_eq ! ( buf, CUSTOM_PING_MESSAGE_CONTENTS ) ;
160
+ Ok ( Some ( TestCustomMessage :: Ping ) )
161
161
} ,
162
- CUSTOM_RESPONSE_MESSAGE_TYPE => {
162
+ CUSTOM_PONG_MESSAGE_TYPE => {
163
163
let buf = read_to_end ( buffer) ?;
164
- assert_eq ! ( buf, CUSTOM_RESPONSE_MESSAGE_CONTENTS ) ;
165
- Ok ( Some ( TestCustomMessage :: Response ) )
164
+ assert_eq ! ( buf, CUSTOM_PONG_MESSAGE_CONTENTS ) ;
165
+ Ok ( Some ( TestCustomMessage :: Pong ) )
166
166
} ,
167
167
_ => Ok ( None ) ,
168
168
}
@@ -297,18 +297,18 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
297
297
#[ test]
298
298
fn one_unblinded_hop ( ) {
299
299
let nodes = create_nodes ( 2 ) ;
300
- let test_msg = TestCustomMessage :: Response ;
300
+ let test_msg = TestCustomMessage :: Pong ;
301
301
302
302
let destination = Destination :: Node ( nodes[ 1 ] . node_id ) ;
303
303
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
304
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
304
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
305
305
pass_along_path ( & nodes) ;
306
306
}
307
307
308
308
#[ test]
309
309
fn two_unblinded_hops ( ) {
310
310
let nodes = create_nodes ( 3 ) ;
311
- let test_msg = TestCustomMessage :: Response ;
311
+ let test_msg = TestCustomMessage :: Pong ;
312
312
313
313
let path = OnionMessagePath {
314
314
intermediate_nodes : vec ! [ nodes[ 1 ] . node_id] ,
@@ -317,27 +317,27 @@ fn two_unblinded_hops() {
317
317
} ;
318
318
319
319
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
320
- nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
320
+ nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
321
321
pass_along_path ( & nodes) ;
322
322
}
323
323
324
324
#[ test]
325
325
fn one_blinded_hop ( ) {
326
326
let nodes = create_nodes ( 2 ) ;
327
- let test_msg = TestCustomMessage :: Response ;
327
+ let test_msg = TestCustomMessage :: Pong ;
328
328
329
329
let secp_ctx = Secp256k1 :: new ( ) ;
330
330
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
331
331
let destination = Destination :: BlindedPath ( blinded_path) ;
332
332
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
333
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
333
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
334
334
pass_along_path ( & nodes) ;
335
335
}
336
336
337
337
#[ test]
338
338
fn two_unblinded_two_blinded ( ) {
339
339
let nodes = create_nodes ( 5 ) ;
340
- let test_msg = TestCustomMessage :: Response ;
340
+ let test_msg = TestCustomMessage :: Pong ;
341
341
342
342
let secp_ctx = Secp256k1 :: new ( ) ;
343
343
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 3 ] . node_id , nodes[ 4 ] . node_id ] , & * nodes[ 4 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
@@ -348,21 +348,21 @@ fn two_unblinded_two_blinded() {
348
348
} ;
349
349
350
350
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
351
- nodes[ 4 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
351
+ nodes[ 4 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
352
352
pass_along_path ( & nodes) ;
353
353
}
354
354
355
355
#[ test]
356
356
fn three_blinded_hops ( ) {
357
357
let nodes = create_nodes ( 4 ) ;
358
- let test_msg = TestCustomMessage :: Response ;
358
+ let test_msg = TestCustomMessage :: Pong ;
359
359
360
360
let secp_ctx = Secp256k1 :: new ( ) ;
361
361
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id , nodes[ 2 ] . node_id , nodes[ 3 ] . node_id ] , & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
362
362
let destination = Destination :: BlindedPath ( blinded_path) ;
363
363
364
364
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
365
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
365
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
366
366
pass_along_path ( & nodes) ;
367
367
}
368
368
@@ -376,7 +376,7 @@ fn async_response_over_one_blinded_hop() {
376
376
let bob = & nodes[ 1 ] ;
377
377
378
378
// 2. Define the message sent from Bob to Alice.
379
- let message = TestCustomMessage :: Request ;
379
+ let message = TestCustomMessage :: Ping ;
380
380
let path_id = Some ( [ 2 ; 32 ] ) ;
381
381
382
382
// 3. Simulate the creation of a Blinded Reply path provided by Bob.
@@ -396,7 +396,7 @@ fn async_response_over_one_blinded_hop() {
396
396
Ok ( Some ( SendSuccess :: Buffered ) ) ,
397
397
) ;
398
398
399
- bob. custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
399
+ bob. custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
400
400
401
401
pass_along_path ( & nodes) ;
402
402
}
@@ -405,7 +405,7 @@ fn async_response_over_one_blinded_hop() {
405
405
fn too_big_packet_error ( ) {
406
406
// Make sure we error as expected if a packet is too big to send.
407
407
let nodes = create_nodes ( 2 ) ;
408
- let test_msg = TestCustomMessage :: Response ;
408
+ let test_msg = TestCustomMessage :: Pong ;
409
409
410
410
let hop_node_id = nodes[ 1 ] . node_id ;
411
411
let hops = vec ! [ hop_node_id; 400 ] ;
@@ -423,21 +423,21 @@ fn we_are_intro_node() {
423
423
// If we are sending straight to a blinded path and we are the introduction node, we need to
424
424
// advance the blinded path by 1 hop so the second hop is the new introduction node.
425
425
let mut nodes = create_nodes ( 3 ) ;
426
- let test_msg = TestCustomMessage :: Response ;
426
+ let test_msg = TestCustomMessage :: Pong ;
427
427
428
428
let secp_ctx = Secp256k1 :: new ( ) ;
429
429
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . node_id , nodes[ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
430
430
let destination = Destination :: BlindedPath ( blinded_path) ;
431
431
432
432
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination, None ) . unwrap ( ) ;
433
- nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
433
+ nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
434
434
pass_along_path ( & nodes) ;
435
435
436
436
// Try with a two-hop blinded path where we are the introduction node.
437
437
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . node_id , nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
438
438
let destination = Destination :: BlindedPath ( blinded_path) ;
439
439
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
440
- nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
440
+ nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
441
441
nodes. remove ( 2 ) ;
442
442
pass_along_path ( & nodes) ;
443
443
}
@@ -446,7 +446,7 @@ fn we_are_intro_node() {
446
446
fn invalid_blinded_path_error ( ) {
447
447
// Make sure we error as expected if a provided blinded path has 0 hops.
448
448
let nodes = create_nodes ( 3 ) ;
449
- let test_msg = TestCustomMessage :: Response ;
449
+ let test_msg = TestCustomMessage :: Pong ;
450
450
451
451
let secp_ctx = Secp256k1 :: new ( ) ;
452
452
let mut blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
@@ -459,7 +459,7 @@ fn invalid_blinded_path_error() {
459
459
#[ test]
460
460
fn reply_path ( ) {
461
461
let mut nodes = create_nodes ( 4 ) ;
462
- let test_msg = TestCustomMessage :: Request ;
462
+ let test_msg = TestCustomMessage :: Ping ;
463
463
let secp_ctx = Secp256k1 :: new ( ) ;
464
464
465
465
// Destination::Node
@@ -470,10 +470,10 @@ fn reply_path() {
470
470
} ;
471
471
let reply_path = BlindedPath :: new_for_message ( & [ nodes[ 2 ] . node_id , nodes[ 1 ] . node_id , nodes[ 0 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
472
472
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) ) . unwrap ( ) ;
473
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
473
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Ping ) ;
474
474
pass_along_path ( & nodes) ;
475
475
// Make sure the last node successfully decoded the reply path.
476
- nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
476
+ nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
477
477
nodes. reverse ( ) ;
478
478
pass_along_path ( & nodes) ;
479
479
@@ -483,11 +483,11 @@ fn reply_path() {
483
483
let reply_path = BlindedPath :: new_for_message ( & [ nodes[ 2 ] . node_id , nodes[ 1 ] . node_id , nodes[ 0 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
484
484
485
485
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, Some ( reply_path) ) . unwrap ( ) ;
486
- nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
486
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Ping ) ;
487
487
pass_along_path ( & nodes) ;
488
488
489
489
// Make sure the last node successfully decoded the reply path.
490
- nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
490
+ nodes[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
491
491
nodes. reverse ( ) ;
492
492
pass_along_path ( & nodes) ;
493
493
}
@@ -521,7 +521,7 @@ fn invalid_custom_message_type() {
521
521
#[ test]
522
522
fn peer_buffer_full ( ) {
523
523
let nodes = create_nodes ( 2 ) ;
524
- let test_msg = TestCustomMessage :: Request ;
524
+ let test_msg = TestCustomMessage :: Ping ;
525
525
let destination = Destination :: Node ( nodes[ 1 ] . node_id ) ;
526
526
for _ in 0 ..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
527
527
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination. clone ( ) , None ) . unwrap ( ) ;
@@ -536,7 +536,7 @@ fn many_hops() {
536
536
// of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`].
537
537
let num_nodes: usize = 25 ;
538
538
let nodes = create_nodes ( num_nodes as u8 ) ;
539
- let test_msg = TestCustomMessage :: Response ;
539
+ let test_msg = TestCustomMessage :: Pong ;
540
540
541
541
let mut intermediate_nodes = vec ! [ ] ;
542
542
for i in 1 ..( num_nodes-1 ) {
@@ -549,14 +549,14 @@ fn many_hops() {
549
549
first_node_addresses : None ,
550
550
} ;
551
551
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg, None ) . unwrap ( ) ;
552
- nodes[ num_nodes-1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
552
+ nodes[ num_nodes-1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
553
553
pass_along_path ( & nodes) ;
554
554
}
555
555
556
556
#[ test]
557
557
fn requests_peer_connection_for_buffered_messages ( ) {
558
558
let nodes = create_nodes ( 3 ) ;
559
- let message = TestCustomMessage :: Request ;
559
+ let message = TestCustomMessage :: Ping ;
560
560
let secp_ctx = Secp256k1 :: new ( ) ;
561
561
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
562
562
@@ -593,7 +593,7 @@ fn requests_peer_connection_for_buffered_messages() {
593
593
#[ test]
594
594
fn drops_buffered_messages_waiting_for_peer_connection ( ) {
595
595
let nodes = create_nodes ( 3 ) ;
596
- let message = TestCustomMessage :: Request ;
596
+ let message = TestCustomMessage :: Ping ;
597
597
let secp_ctx = Secp256k1 :: new ( ) ;
598
598
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
599
599
@@ -644,7 +644,7 @@ fn intercept_offline_peer_oms() {
644
644
}
645
645
}
646
646
647
- let message = TestCustomMessage :: Response ;
647
+ let message = TestCustomMessage :: Pong ;
648
648
let secp_ctx = Secp256k1 :: new ( ) ;
649
649
let blinded_path = BlindedPath :: new_for_message (
650
650
& [ nodes[ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx
@@ -683,7 +683,7 @@ fn intercept_offline_peer_oms() {
683
683
}
684
684
685
685
nodes[ 1 ] . messenger . forward_onion_message ( onion_message, & final_node_vec[ 0 ] . node_id ) . unwrap ( ) ;
686
- final_node_vec[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
686
+ final_node_vec[ 0 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
687
687
pass_along_path ( & vec ! [ nodes. remove( 1 ) , final_node_vec. remove( 0 ) ] ) ;
688
688
}
689
689
0 commit comments