Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Shourya742
Copy link
Contributor

This PR adds Block from message Action to sniffer. Closes #1506

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 17.88%. Comparing base (01d6ec6) to head (0afdf9b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
roles/tests-integration/lib/sniffer.rs 0.00% 4 Missing ⚠️
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     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <ø> (ø)
binary_sv2-coverage 6.96% <ø> (ø)
bip32_derivation-coverage 0.00% <ø> (ø)
buffer_sv2-coverage 37.68% <ø> (ø)
codec_sv2-coverage 0.02% <ø> (ø)
common_messages_sv2-coverage 0.17% <ø> (ø)
const_sv2-coverage 0.00% <ø> (ø)
error_handling-coverage 0.00% <ø> (ø)
framing_sv2-coverage 0.37% <ø> (ø)
jd_client-coverage 0.42% <ø> (ø)
jd_server-coverage 13.07% <ø> (ø)
job_declaration_sv2-coverage 0.00% <ø> (ø)
key-utils-coverage 3.61% <ø> (ø)
mining-coverage 3.17% <ø> (ø)
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.82% <ø> (ø)
noise_sv2-coverage 5.79% <ø> (ø)
pool_sv2-coverage 2.46% <ø> (ø)
protocols 23.91% <ø> (ø)
roles 6.96% <0.00%> (-0.01%) ⬇️
roles_logic_sv2-coverage 11.59% <ø> (ø)
sv2_ffi-coverage 0.00% <ø> (ø)
template_distribution_sv2-coverage 0.00% <ø> (ø)
translator_sv2-coverage 9.58% <ø> (ø)
utils 36.39% <ø> (ø)
v1-coverage 3.11% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jbesraa jbesraa left a 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?

@Shourya742 Shourya742 force-pushed the 2025-02-26-sniffer-block-message branch 2 times, most recently from 0219b08 to 4e70894 Compare February 28, 2025 12:56
@Shourya742
Copy link
Contributor Author

@plebhash @jbesraa All suggestions have been incorporated. Kindly review the changes.

Comment on lines 69 to 70
BlockFromMessage(BlockFromMessage),
/// Intercepts and modifies a message before forwarding it.
InterceptMessage(Box<InterceptMessage>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why Box?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Collaborator

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

I agree

Comment on lines 69 to 70
BlockFromMessage(BlockFromMessage),
/// Intercepts and modifies a message before forwarding it.
InterceptMessage(Box<InterceptMessage>),
Copy link
Contributor

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.

@Shourya742 Shourya742 force-pushed the 2025-02-26-sniffer-block-message branch 3 times, most recently from db527fe to 70ee5c9 Compare March 2, 2025 04:55
@Shourya742
Copy link
Contributor Author

@jbesraa @plebhash I added the suggested abstraction and made the test more stable by intercepting SetupConnectionSuccess. Everything is working as expected. I also think Action should have its own module, but this can be deferred to a later PR.

Comment on lines 69 to 70
BlockFromMessage(BlockFromMessage),
/// Intercepts and modifies a message before forwarding it.
InterceptMessage(Box<InterceptMessage>),
Copy link
Contributor

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
@Shourya742 Shourya742 force-pushed the 2025-02-26-sniffer-block-message branch from 95b7cce to 3a40244 Compare March 4, 2025 11:54
@Shourya742 Shourya742 force-pushed the 2025-02-26-sniffer-block-message branch from 3a40244 to 0afdf9b Compare March 4, 2025 14:11
Copy link
Contributor

@jbesraa jbesraa left a 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(
Copy link
Contributor

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?):

Suggested change
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.
Copy link
Contributor

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.
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ITF Sniffer needs functionality to block messages
3 participants