Skip to content

Commit

Permalink
add abstraction for repeatitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 committed Mar 2, 2025
1 parent 717f49b commit 70ee5c9
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions roles/tests-integration/lib/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,7 @@ impl Sniffer {
continue;
}
let (msg_type, msg) = Self::message_from_frame(&mut frame);
let action = action.as_ref().and_then(|action| match action {
Action::BlockFromMessage(bm)
if bm.direction == MessageDirection::ToUpstream
&& bm.expected_message_type == msg_type =>
{
Some(action)
}

Action::InterceptMessage(im)
if im.direction == MessageDirection::ToUpstream
&& im.expected_message_type == msg_type =>
{
Some(action)
}

_ => None,
});
let action = Action::filter_downstream(&action, msg_type, MessageDirection::ToUpstream);
if let Some(ref action) = action {
match action {
Action::IgnoreFromMessage(_) => {
Expand Down Expand Up @@ -354,23 +338,8 @@ impl Sniffer {
}
let (msg_type, msg) = Self::message_from_frame(&mut frame);

let action = action.as_ref().and_then(|action| match action {
Action::BlockFromMessage(bm)
if bm.direction == MessageDirection::ToDownstream
&& bm.expected_message_type == msg_type =>
{
Some(action)
}

Action::InterceptMessage(im)
if im.direction == MessageDirection::ToDownstream
&& im.expected_message_type == msg_type =>
{
Some(action)
}

_ => None,
});
let action =
Action::filter_downstream(&action, msg_type, MessageDirection::ToDownstream);

if let Some(ref action) = action {
match action {
Expand Down

0 comments on commit 70ee5c9

Please sign in to comment.