Skip to content

Commit 66c214b

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 8f79c91 commit 66c214b

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
@@ -80,20 +80,20 @@ impl OffersMessageHandler for TestOffersMessageHandler {
8080

8181
#[derive(Clone, Debug, PartialEq)]
8282
enum TestCustomMessage {
83-
Request,
84-
Response,
83+
Ping,
84+
Pong,
8585
}
8686

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

9292
impl OnionMessageContents for TestCustomMessage {
9393
fn tlv_type(&self) -> u64 {
9494
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,
9797
}
9898
}
9999
fn msg_type(&self) -> &'static str {
@@ -104,8 +104,8 @@ impl OnionMessageContents for TestCustomMessage {
104104
impl Writeable for TestCustomMessage {
105105
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
106106
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)?),
109109
}
110110
}
111111
}
@@ -143,8 +143,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
143143
None => panic!("Unexpected message: {:?}", msg),
144144
}
145145
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,
148148
};
149149
if let (Some(response), Some(responder)) = (response_option, responder) {
150150
responder.respond(response)
@@ -154,15 +154,15 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
154154
}
155155
fn read_custom_message<R: io::Read>(&self, message_type: u64, buffer: &mut R) -> Result<Option<Self::CustomMessage>, DecodeError> where Self: Sized {
156156
match message_type {
157-
CUSTOM_REQUEST_MESSAGE_TYPE => {
157+
CUSTOM_PING_MESSAGE_TYPE => {
158158
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))
161161
},
162-
CUSTOM_RESPONSE_MESSAGE_TYPE => {
162+
CUSTOM_PONG_MESSAGE_TYPE => {
163163
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))
166166
},
167167
_ => Ok(None),
168168
}
@@ -297,18 +297,18 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
297297
#[test]
298298
fn one_unblinded_hop() {
299299
let nodes = create_nodes(2);
300-
let test_msg = TestCustomMessage::Response;
300+
let test_msg = TestCustomMessage::Pong;
301301

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

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

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

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

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

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

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

342342
let secp_ctx = Secp256k1::new();
343343
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() {
348348
};
349349

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

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

360360
let secp_ctx = Secp256k1::new();
361361
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();
362362
let destination = Destination::BlindedPath(blinded_path);
363363

364364
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);
366366
pass_along_path(&nodes);
367367
}
368368

@@ -376,7 +376,7 @@ fn async_response_over_one_blinded_hop() {
376376
let bob = &nodes[1];
377377

378378
// 2. Define the message sent from Bob to Alice.
379-
let message = TestCustomMessage::Request;
379+
let message = TestCustomMessage::Ping;
380380
let path_id = Some([2; 32]);
381381

382382
// 3. Simulate the creation of a Blinded Reply path provided by Bob.
@@ -396,7 +396,7 @@ fn async_response_over_one_blinded_hop() {
396396
Ok(Some(SendSuccess::Buffered)),
397397
);
398398

399-
bob.custom_message_handler.expect_message(TestCustomMessage::Response);
399+
bob.custom_message_handler.expect_message(TestCustomMessage::Pong);
400400

401401
pass_along_path(&nodes);
402402
}
@@ -405,7 +405,7 @@ fn async_response_over_one_blinded_hop() {
405405
fn too_big_packet_error() {
406406
// Make sure we error as expected if a packet is too big to send.
407407
let nodes = create_nodes(2);
408-
let test_msg = TestCustomMessage::Response;
408+
let test_msg = TestCustomMessage::Pong;
409409

410410
let hop_node_id = nodes[1].node_id;
411411
let hops = vec![hop_node_id; 400];
@@ -423,21 +423,21 @@ fn we_are_intro_node() {
423423
// If we are sending straight to a blinded path and we are the introduction node, we need to
424424
// advance the blinded path by 1 hop so the second hop is the new introduction node.
425425
let mut nodes = create_nodes(3);
426-
let test_msg = TestCustomMessage::Response;
426+
let test_msg = TestCustomMessage::Pong;
427427

428428
let secp_ctx = Secp256k1::new();
429429
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();
430430
let destination = Destination::BlindedPath(blinded_path);
431431

432432
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);
434434
pass_along_path(&nodes);
435435

436436
// Try with a two-hop blinded path where we are the introduction node.
437437
let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
438438
let destination = Destination::BlindedPath(blinded_path);
439439
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);
441441
nodes.remove(2);
442442
pass_along_path(&nodes);
443443
}
@@ -446,7 +446,7 @@ fn we_are_intro_node() {
446446
fn invalid_blinded_path_error() {
447447
// Make sure we error as expected if a provided blinded path has 0 hops.
448448
let nodes = create_nodes(3);
449-
let test_msg = TestCustomMessage::Response;
449+
let test_msg = TestCustomMessage::Pong;
450450

451451
let secp_ctx = Secp256k1::new();
452452
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() {
459459
#[test]
460460
fn reply_path() {
461461
let mut nodes = create_nodes(4);
462-
let test_msg = TestCustomMessage::Request;
462+
let test_msg = TestCustomMessage::Ping;
463463
let secp_ctx = Secp256k1::new();
464464

465465
// Destination::Node
@@ -470,10 +470,10 @@ fn reply_path() {
470470
};
471471
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();
472472
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);
474474
pass_along_path(&nodes);
475475
// 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);
477477
nodes.reverse();
478478
pass_along_path(&nodes);
479479

@@ -483,11 +483,11 @@ fn reply_path() {
483483
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();
484484

485485
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);
487487
pass_along_path(&nodes);
488488

489489
// 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);
491491
nodes.reverse();
492492
pass_along_path(&nodes);
493493
}
@@ -521,7 +521,7 @@ fn invalid_custom_message_type() {
521521
#[test]
522522
fn peer_buffer_full() {
523523
let nodes = create_nodes(2);
524-
let test_msg = TestCustomMessage::Request;
524+
let test_msg = TestCustomMessage::Ping;
525525
let destination = Destination::Node(nodes[1].node_id);
526526
for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
527527
nodes[0].messenger.send_onion_message(test_msg.clone(), destination.clone(), None).unwrap();
@@ -536,7 +536,7 @@ fn many_hops() {
536536
// of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`].
537537
let num_nodes: usize = 25;
538538
let nodes = create_nodes(num_nodes as u8);
539-
let test_msg = TestCustomMessage::Response;
539+
let test_msg = TestCustomMessage::Pong;
540540

541541
let mut intermediate_nodes = vec![];
542542
for i in 1..(num_nodes-1) {
@@ -549,14 +549,14 @@ fn many_hops() {
549549
first_node_addresses: None,
550550
};
551551
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);
553553
pass_along_path(&nodes);
554554
}
555555

556556
#[test]
557557
fn requests_peer_connection_for_buffered_messages() {
558558
let nodes = create_nodes(3);
559-
let message = TestCustomMessage::Request;
559+
let message = TestCustomMessage::Ping;
560560
let secp_ctx = Secp256k1::new();
561561
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
562562

@@ -593,7 +593,7 @@ fn requests_peer_connection_for_buffered_messages() {
593593
#[test]
594594
fn drops_buffered_messages_waiting_for_peer_connection() {
595595
let nodes = create_nodes(3);
596-
let message = TestCustomMessage::Request;
596+
let message = TestCustomMessage::Ping;
597597
let secp_ctx = Secp256k1::new();
598598
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
599599

@@ -644,7 +644,7 @@ fn intercept_offline_peer_oms() {
644644
}
645645
}
646646

647-
let message = TestCustomMessage::Response;
647+
let message = TestCustomMessage::Pong;
648648
let secp_ctx = Secp256k1::new();
649649
let blinded_path = BlindedPath::new_for_message(
650650
&[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx
@@ -683,7 +683,7 @@ fn intercept_offline_peer_oms() {
683683
}
684684

685685
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);
687687
pass_along_path(&vec![nodes.remove(1), final_node_vec.remove(0)]);
688688
}
689689

0 commit comments

Comments
 (0)