-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sniffer block from message #1510
base: main
Are you sure you want to change the base?
sniffer block from message #1510
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1510 +/- ##
==========================================
- Coverage 17.88% 17.88% -0.01%
==========================================
Files 132 132
Lines 10068 10072 +4
==========================================
Hits 1801 1801
- Misses 8267 8271 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you please add a test or expand another test under sniffer_integration
to cover BlockFromMessage
behavior?
0219b08
to
4e70894
Compare
BlockFromMessage(BlockFromMessage), | ||
/// Intercepts and modifies a message before forwarding it. | ||
InterceptMessage(Box<InterceptMessage>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Box
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy suggests Box<InterceptMessage>
to optimize enum size by storing large variants on the heap, preventing excessive stack usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is probably because of replacement_message: PoolMessages<'static>
. It feels like something to actually fix in a different PR. i.e., try to optimize PoolMessages
size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming is a bit confusing around here: Maybe Action
should be InterceptAction
and InterceptMessage
should be ReplaceMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming is a bit confusing around here: Maybe
Action
should beInterceptAction
andInterceptMessage
should beReplaceMessage
I agree
BlockFromMessage(BlockFromMessage), | ||
/// Intercepts and modifies a message before forwarding it. | ||
InterceptMessage(Box<InterceptMessage>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is probably because of replacement_message: PoolMessages<'static>
. It feels like something to actually fix in a different PR. i.e., try to optimize PoolMessages
size.
db527fe
to
70ee5c9
Compare
BlockFromMessage(BlockFromMessage), | ||
/// Intercepts and modifies a message before forwarding it. | ||
InterceptMessage(Box<InterceptMessage>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming is a bit confusing around here: Maybe Action
should be InterceptAction
and InterceptMessage
should be ReplaceMessage
This commit introduces an action construct that encapsulates all sniffer actions. Additionally, it adds the `BlockFromMessage` action, allowing message streams to be blocked after a specific message is encountered. something
95b7cce
to
3a40244
Compare
3a40244
to
0afdf9b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Added a few nits but still approving this as it blocking a couple of tests. I can handle the nits in a followup
impl InterceptAction { | ||
/// Returns the action if it is `IgnoreFromMessage` or `ReplaceMessage` | ||
/// with the specified message type. | ||
pub fn find_matching_action( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like the following to reduce duplicated code(and also receive &self
instead of Option<action>
, otherwise why would you call this function with a None
value?):
pub fn find_matching_action( | |
pub fn find_matching_action( | |
&self, | |
msg_type: MsgType, | |
direction: MessageDirection, | |
) -> Option<InterceptAction> { | |
match self { | |
InterceptAction::IgnoreFromMessage(bm) | |
| InterceptAction::ReplaceMessage(bm) | |
if bm.direction == direction && bm.expected_message_type == msg_type => | |
{ | |
Some(action) | |
} | |
_ => None, | |
} | |
} |
MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS, | ||
); | ||
|
||
// `sniffer_a` intercepts and blocks `SetupConnectionSuccess` messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sniffer_a
is just forwarding the messages, I think this is for sniffer_b
// `sniffer_a` intercepts and blocks `SetupConnectionSuccess` messages. | ||
let (sniffer_a, sniffer_a_addr) = start_sniffer("A".to_string(), tp_addr, false, None).await; | ||
|
||
// `sniffer_b` is placed downstream of `sniffer_a` and should receive nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should receive and block
This PR adds Block from message Action to sniffer. Closes #1506