-
Notifications
You must be signed in to change notification settings - Fork 140
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
integration_tests_sv2
docs cleanup
#1340
Open
plebhash
wants to merge
4
commits into
stratum-mining:main
Choose a base branch
from
plebhash:integration-test-docs-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a188b6
rename InterceptMessage.response_message to replacement_message..
plebhash c7eeeaa
remove interrupt functionality from `Sniffer`..
plebhash f7f58fd
expand `test_sniffer_intercept` to make test comprehensive..
plebhash b193189
`integration_tests_sv2` docs cleanup..
plebhash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,29 +31,26 @@ type MsgType = u8; | |
enum SnifferError { | ||
DownstreamClosed, | ||
UpstreamClosed, | ||
MessageInterrupted, | ||
} | ||
|
||
/// Allows to intercept messages sent between two roles. | ||
/// | ||
/// 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. | ||
/// | ||
/// The downstream (or client) role connects to the [`Sniffer`] `listening_address` and the | ||
/// [`Sniffer`] connects to the `upstream` server. This way, the Sniffer can intercept messages sent | ||
/// between the downstream and upstream roles. The downstream will send its messages to the | ||
/// [`Sniffer`] which will save those in the `messages_from_downstream` aggregator and forward them | ||
/// to the upstream role. When a response is received it is saved in `messages_from_upstream` and | ||
/// forwarded to the downstream role. Both `messages_from_downstream` and `messages_from_upstream` | ||
/// can be accessed as FIFO queues. | ||
Comment on lines
-41
to
-45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was re-rewitten below, as it implies that messages from upstream are always a response, which is not necessarily true |
||
/// | ||
/// In order to alter the messages sent between the roles, the [`Sniffer::intercept_messages`] | ||
/// field can be used. It will look for the [`InterceptMessage::expected_message_type`] in the | ||
/// specified [`InterceptMessage::direction`] and replace it with | ||
/// [`InterceptMessage::response_message`]. | ||
/// between the downstream and upstream roles. | ||
/// | ||
/// If `break_on` is set to `true`, the [`Sniffer`] will stop the communication after sending the | ||
/// response message. | ||
/// Messages received from downstream are stored in the `messages_from_downstream` aggregator and | ||
/// forward them to the upstream role. Alternatively, messages received from upstream are stored in | ||
/// the `messages_from_upstream` and forwarded to the downstream role. Both | ||
/// `messages_from_downstream` and `messages_from_upstream` aggregators can be accessed as FIFO | ||
/// queues via [`Sniffer::next_message_from_downstream`] and | ||
/// [`Sniffer::next_message_from_upstream`], respectively. | ||
/// | ||
/// 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. | ||
/// In order to replace the messages sent between the roles, a set of [`InterceptMessage`] can be | ||
/// used in [`Sniffer::new`]. | ||
#[derive(Debug, Clone)] | ||
pub struct Sniffer { | ||
identifier: String, | ||
|
@@ -65,29 +62,27 @@ pub struct Sniffer { | |
intercept_messages: Vec<InterceptMessage>, | ||
} | ||
|
||
/// Allows [`Sniffer`] to replace some intercepted message before forwarding it. | ||
#[derive(Debug, Clone)] | ||
pub struct InterceptMessage { | ||
direction: MessageDirection, | ||
expected_message_type: MsgType, | ||
response_message: PoolMessages<'static>, | ||
response_message_type: MsgType, | ||
break_on: bool, | ||
replacement_message: PoolMessages<'static>, | ||
replacement_message_type: MsgType, | ||
} | ||
|
||
impl InterceptMessage { | ||
pub fn new( | ||
direction: MessageDirection, | ||
expected_message_type: MsgType, | ||
response_message: PoolMessages<'static>, | ||
response_message_type: MsgType, | ||
break_on: bool, | ||
replacement_message: PoolMessages<'static>, | ||
replacement_message_type: MsgType, | ||
) -> Self { | ||
Self { | ||
direction, | ||
expected_message_type, | ||
response_message, | ||
response_message_type, | ||
break_on, | ||
replacement_message, | ||
replacement_message_type, | ||
} | ||
} | ||
} | ||
|
@@ -234,21 +229,16 @@ impl Sniffer { | |
let channel_msg = false; | ||
let frame = StandardEitherFrame::<AnyMessage<'_>>::Sv2( | ||
Sv2Frame::from_message( | ||
intercept_message.response_message.clone(), | ||
intercept_message.response_message_type, | ||
intercept_message.replacement_message.clone(), | ||
intercept_message.replacement_message_type, | ||
extension_type, | ||
channel_msg, | ||
) | ||
.expect("Failed to create the frame"), | ||
); | ||
downstream_messages | ||
.add_message(msg_type, intercept_message.response_message.clone()); | ||
.add_message(msg_type, intercept_message.replacement_message.clone()); | ||
let _ = send.send(frame).await; | ||
if intercept_message.break_on { | ||
return Err(SnifferError::MessageInterrupted); | ||
} else { | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -276,21 +266,16 @@ impl Sniffer { | |
let channel_msg = false; | ||
let frame = StandardEitherFrame::<AnyMessage<'_>>::Sv2( | ||
Sv2Frame::from_message( | ||
intercept_message.response_message.clone(), | ||
intercept_message.response_message_type, | ||
intercept_message.replacement_message.clone(), | ||
intercept_message.replacement_message_type, | ||
extension_type, | ||
channel_msg, | ||
) | ||
.expect("Failed to create the frame"), | ||
); | ||
upstream_messages | ||
.add_message(msg_type, intercept_message.response_message.clone()); | ||
.add_message(msg_type, intercept_message.replacement_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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 paragraph was just moved from the bottom to the top, as it feels more like an introduction about
Sniffer
it was a bit confusing to read it on the bottom, as it wasn't clear what it was referring to (
Sniffer
in general vs some internal detail)