Skip to content

Commit 7d5dd6b

Browse files
committed
Refactor: Rename Request & Response to Ping & Pong
1. These two variants will be modified in an upcoming commit to be each other's response. 2. The names are updated to better fit their new roles.
1 parent 6904786 commit 7d5dd6b

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ impl OffersMessageHandler for TestOffersMessageHandler {
8181

8282
#[derive(Clone, Debug, PartialEq)]
8383
enum TestCustomMessage {
84-
Request,
85-
Response,
84+
Ping,
85+
Pong,
8686
}
8787

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];
9292

9393
impl OnionMessageContents for TestCustomMessage {
9494
fn tlv_type(&self) -> u64 {
9595
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,
9898
}
9999
}
100100
fn msg_type(&self) -> &'static str {
@@ -105,8 +105,8 @@ impl OnionMessageContents for TestCustomMessage {
105105
impl Writeable for TestCustomMessage {
106106
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
107107
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)?),
110110
}
111111
}
112112
}
@@ -144,8 +144,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
144144
None => panic!("Unexpected message: {:?}", msg),
145145
}
146146
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,
149149
};
150150
if let (Some(response), Some(responder)) = (response_option, responder) {
151151
responder.respond(response)
@@ -155,15 +155,15 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
155155
}
156156
fn read_custom_message<R: io::Read>(&self, message_type: u64, buffer: &mut R) -> Result<Option<Self::CustomMessage>, DecodeError> where Self: Sized {
157157
match message_type {
158-
CUSTOM_REQUEST_MESSAGE_TYPE => {
158+
CUSTOM_PING_MESSAGE_TYPE => {
159159
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))
162162
},
163-
CUSTOM_RESPONSE_MESSAGE_TYPE => {
163+
CUSTOM_PONG_MESSAGE_TYPE => {
164164
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))
167167
},
168168
_ => Ok(None),
169169
}
@@ -298,18 +298,18 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
298298
#[test]
299299
fn one_unblinded_hop() {
300300
let nodes = create_nodes(2);
301-
let test_msg = TestCustomMessage::Response;
301+
let test_msg = TestCustomMessage::Pong;
302302

303303
let destination = Destination::Node(nodes[1].node_id);
304304
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);
306306
pass_along_path(&nodes);
307307
}
308308

309309
#[test]
310310
fn two_unblinded_hops() {
311311
let nodes = create_nodes(3);
312-
let test_msg = TestCustomMessage::Response;
312+
let test_msg = TestCustomMessage::Pong;
313313

314314
let path = OnionMessagePath {
315315
intermediate_nodes: vec![nodes[1].node_id],
@@ -318,27 +318,27 @@ fn two_unblinded_hops() {
318318
};
319319

320320
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);
322322
pass_along_path(&nodes);
323323
}
324324

325325
#[test]
326326
fn one_blinded_hop() {
327327
let nodes = create_nodes(2);
328-
let test_msg = TestCustomMessage::Response;
328+
let test_msg = TestCustomMessage::Pong;
329329

330330
let secp_ctx = Secp256k1::new();
331331
let blinded_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
332332
let destination = Destination::BlindedPath(blinded_path);
333333
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);
335335
pass_along_path(&nodes);
336336
}
337337

338338
#[test]
339339
fn two_unblinded_two_blinded() {
340340
let nodes = create_nodes(5);
341-
let test_msg = TestCustomMessage::Response;
341+
let test_msg = TestCustomMessage::Pong;
342342

343343
let secp_ctx = Secp256k1::new();
344344
let intermediate_nodes = [ForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
@@ -350,14 +350,14 @@ fn two_unblinded_two_blinded() {
350350
};
351351

352352
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);
354354
pass_along_path(&nodes);
355355
}
356356

357357
#[test]
358358
fn three_blinded_hops() {
359359
let nodes = create_nodes(4);
360-
let test_msg = TestCustomMessage::Response;
360+
let test_msg = TestCustomMessage::Pong;
361361

362362
let secp_ctx = Secp256k1::new();
363363
let intermediate_nodes = [
@@ -368,7 +368,7 @@ fn three_blinded_hops() {
368368
let destination = Destination::BlindedPath(blinded_path);
369369

370370
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);
372372
pass_along_path(&nodes);
373373
}
374374

@@ -382,7 +382,7 @@ fn async_response_over_one_blinded_hop() {
382382
let bob = &nodes[1];
383383

384384
// 2. Define the message sent from Bob to Alice.
385-
let message = TestCustomMessage::Request;
385+
let message = TestCustomMessage::Ping;
386386
let path_id = Some([2; 32]);
387387

388388
// 3. Simulate the creation of a Blinded Reply path provided by Bob.
@@ -402,7 +402,7 @@ fn async_response_over_one_blinded_hop() {
402402
Ok(Some(SendSuccess::Buffered)),
403403
);
404404

405-
bob.custom_message_handler.expect_message(TestCustomMessage::Response);
405+
bob.custom_message_handler.expect_message(TestCustomMessage::Pong);
406406

407407
pass_along_path(&nodes);
408408
}
@@ -411,7 +411,7 @@ fn async_response_over_one_blinded_hop() {
411411
fn too_big_packet_error() {
412412
// Make sure we error as expected if a packet is too big to send.
413413
let nodes = create_nodes(2);
414-
let test_msg = TestCustomMessage::Response;
414+
let test_msg = TestCustomMessage::Pong;
415415

416416
let hop_node_id = nodes[1].node_id;
417417
let hops = vec![hop_node_id; 400];
@@ -429,7 +429,7 @@ fn we_are_intro_node() {
429429
// If we are sending straight to a blinded path and we are the introduction node, we need to
430430
// advance the blinded path by 1 hop so the second hop is the new introduction node.
431431
let mut nodes = create_nodes(3);
432-
let test_msg = TestCustomMessage::Response;
432+
let test_msg = TestCustomMessage::Pong;
433433

434434
let secp_ctx = Secp256k1::new();
435435
let intermediate_nodes = [
@@ -440,15 +440,15 @@ fn we_are_intro_node() {
440440
let destination = Destination::BlindedPath(blinded_path);
441441

442442
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);
444444
pass_along_path(&nodes);
445445

446446
// Try with a two-hop blinded path where we are the introduction node.
447447
let intermediate_nodes = [ForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
448448
let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
449449
let destination = Destination::BlindedPath(blinded_path);
450450
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);
452452
nodes.remove(2);
453453
pass_along_path(&nodes);
454454
}
@@ -457,7 +457,7 @@ fn we_are_intro_node() {
457457
fn invalid_blinded_path_error() {
458458
// Make sure we error as expected if a provided blinded path has 0 hops.
459459
let nodes = create_nodes(3);
460-
let test_msg = TestCustomMessage::Response;
460+
let test_msg = TestCustomMessage::Pong;
461461

462462
let secp_ctx = Secp256k1::new();
463463
let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
@@ -471,7 +471,7 @@ fn invalid_blinded_path_error() {
471471
#[test]
472472
fn reply_path() {
473473
let mut nodes = create_nodes(4);
474-
let test_msg = TestCustomMessage::Request;
474+
let test_msg = TestCustomMessage::Ping;
475475
let secp_ctx = Secp256k1::new();
476476

477477
// Destination::Node
@@ -486,10 +486,10 @@ fn reply_path() {
486486
];
487487
let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
488488
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);
490490
pass_along_path(&nodes);
491491
// 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);
493493
nodes.reverse();
494494
pass_along_path(&nodes);
495495

@@ -507,11 +507,11 @@ fn reply_path() {
507507
let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
508508

509509
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);
511511
pass_along_path(&nodes);
512512

513513
// 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);
515515
nodes.reverse();
516516
pass_along_path(&nodes);
517517
}
@@ -545,7 +545,7 @@ fn invalid_custom_message_type() {
545545
#[test]
546546
fn peer_buffer_full() {
547547
let nodes = create_nodes(2);
548-
let test_msg = TestCustomMessage::Request;
548+
let test_msg = TestCustomMessage::Ping;
549549
let destination = Destination::Node(nodes[1].node_id);
550550
for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
551551
nodes[0].messenger.send_onion_message(test_msg.clone(), destination.clone(), None).unwrap();
@@ -560,7 +560,7 @@ fn many_hops() {
560560
// of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`].
561561
let num_nodes: usize = 25;
562562
let nodes = create_nodes(num_nodes as u8);
563-
let test_msg = TestCustomMessage::Response;
563+
let test_msg = TestCustomMessage::Pong;
564564

565565
let mut intermediate_nodes = vec![];
566566
for i in 1..(num_nodes-1) {
@@ -573,14 +573,14 @@ fn many_hops() {
573573
first_node_addresses: None,
574574
};
575575
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);
577577
pass_along_path(&nodes);
578578
}
579579

580580
#[test]
581581
fn requests_peer_connection_for_buffered_messages() {
582582
let nodes = create_nodes(3);
583-
let message = TestCustomMessage::Request;
583+
let message = TestCustomMessage::Ping;
584584
let secp_ctx = Secp256k1::new();
585585
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
586586

@@ -618,7 +618,7 @@ fn requests_peer_connection_for_buffered_messages() {
618618
#[test]
619619
fn drops_buffered_messages_waiting_for_peer_connection() {
620620
let nodes = create_nodes(3);
621-
let message = TestCustomMessage::Request;
621+
let message = TestCustomMessage::Ping;
622622
let secp_ctx = Secp256k1::new();
623623
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
624624

@@ -670,7 +670,7 @@ fn intercept_offline_peer_oms() {
670670
}
671671
}
672672

673-
let message = TestCustomMessage::Response;
673+
let message = TestCustomMessage::Pong;
674674
let secp_ctx = Secp256k1::new();
675675
let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
676676
let blinded_path = BlindedPath::new_for_message(
@@ -710,7 +710,7 @@ fn intercept_offline_peer_oms() {
710710
}
711711

712712
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);
714714
pass_along_path(&vec![nodes.remove(1), final_node_vec.remove(0)]);
715715
}
716716

0 commit comments

Comments
 (0)