Skip to content

Commit

Permalink
remove interrupt functionality from Sniffer..
Browse files Browse the repository at this point in the history
it's not fully designed and motivation is not clear, we can re-design if needed
  • Loading branch information
plebhash committed Jan 9, 2025
1 parent 17568c6 commit 32101ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
17 changes: 0 additions & 17 deletions roles/tests-integration/lib/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type MsgType = u8;
enum SnifferError {
DownstreamClosed,
UpstreamClosed,
MessageInterrupted,
}

/// Allows to intercept messages sent between two roles.
Expand All @@ -49,9 +48,6 @@ enum SnifferError {
/// specified [`InterceptMessage::direction`] and replace it with
/// [`InterceptMessage::replace_message`].
///
/// If `break_on` is set to `true`, the [`Sniffer`] will stop the communication after sending the
/// new message.
///
/// Can be useful for testing purposes, as it allows to assert that the roles have sent specific
/// messages in a specific order and to inspect the messages details.
#[derive(Debug, Clone)]
Expand All @@ -71,7 +67,6 @@ pub struct InterceptMessage {
expected_message_type: MsgType,
replace_message: PoolMessages<'static>,
replace_message_type: MsgType,
break_on: bool,
}

impl InterceptMessage {
Expand All @@ -80,14 +75,12 @@ impl InterceptMessage {
expected_message_type: MsgType,
replace_message: PoolMessages<'static>,
replace_message_type: MsgType,
break_on: bool,
) -> Self {
Self {
direction,
expected_message_type,
replace_message,
replace_message_type,
break_on,
}
}
}
Expand Down Expand Up @@ -244,11 +237,6 @@ impl Sniffer {
downstream_messages
.add_message(msg_type, intercept_message.replace_message.clone());
let _ = send.send(frame).await;
if intercept_message.break_on {
return Err(SnifferError::MessageInterrupted);
} else {
continue;
}
}
}

Expand Down Expand Up @@ -286,11 +274,6 @@ impl Sniffer {
upstream_messages
.add_message(msg_type, intercept_message.replace_message.clone());
let _ = send.send(frame).await;
if intercept_message.break_on {
return Err(SnifferError::MessageInterrupted);
} else {
continue;
}
}
}
if send.send(frame).await.is_err() {
Expand Down
11 changes: 5 additions & 6 deletions roles/tests-integration/tests/sniffer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use sniffer::{InterceptMessage, MessageDirection};
use std::convert::TryInto;

#[tokio::test]
async fn test_sniffer_interrupter() {
async fn test_sniffer_intercept() {
let (_tp, tp_addr) = start_template_provider(None).await;
use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS;
let message =
let message_replacement =
PoolMessages::Common(CommonMessages::SetupConnectionError(SetupConnectionError {
flags: 0,
error_code: "unsupported-feature-flags"
Expand All @@ -20,15 +20,14 @@ async fn test_sniffer_interrupter() {
.try_into()
.unwrap(),
}));
let interrupt_msgs = InterceptMessage::new(
let intercept = InterceptMessage::new(
MessageDirection::ToDownstream,
MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS,
message,
message_replacement,
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
true,
);
let (sniffer, sniffer_addr) =
start_sniffer("".to_string(), tp_addr, false, Some(vec![interrupt_msgs])).await;
start_sniffer("".to_string(), tp_addr, false, Some(vec![intercept])).await;
let _ = start_pool(Some(sniffer_addr)).await;
assert_common_message!(&sniffer.next_message_from_downstream(), SetupConnection);
assert_common_message!(&sniffer.next_message_from_upstream(), SetupConnectionError);
Expand Down

0 comments on commit 32101ff

Please sign in to comment.