Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

@Teebor-Choka Teebor-Choka commented Sep 24, 2024

To be run with a setup and existing tunnel at a specified URL as:
HOPR_TEST_RUNNING_WIREGUARD_TUNNEL=wireguard.tunnel.link:51820 .venv/bin/python3 -m pytest tests/test_integration.py -k test_session_with_wireguard_tunnel

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new dependency on the arrayvec crate and modify existing dependencies in the Cargo.toml files across various modules. The UdpStreamBuilder in common/network-types/src/udp.rs is updated to enhance socket binding and parallelism handling, specifically for Linux systems. The session.rs file sees a renaming of a configuration key and adjustments to session initialization retry strategies. Additionally, new metrics related to Prometheus are introduced, and a new asynchronous test function is added to validate sessions over a Wireguard tunnel.

Changes

Files Change Summary
Cargo.toml Added arrayvec dependency and modified prometheus dependencies across various modules.
common/network-types/src/udp.rs Enhanced UdpStreamBuilder for socket binding and parallelism handling specific to Linux.
common/network-types/src/utils.rs Introduced SocketAddrStr struct for optimized socket address representation.
common/network-types/src/types.rs Refactored test function for clarity.
hoprd/rest-api/src/session.rs Renamed configuration key from "listen_host" to "listenHost"; updated retry strategy.
hoprd/hoprd/src/lib.rs Modified ConnectedUdpStream instantiation for conditional parallelism on Linux.
tests/hopr.py Updated session_client method to include a new listen_on parameter.
tests/test_session.py Added new async test function test_session_with_wireguard_tunnel.
transport/session/src/types.rs Introduced static variable METRIC_SESSION_INNER_SIZES for tracking data chunk sizes.

Possibly related PRs

Suggested labels

feature, crate:hopr-lib, crate:core-network, crate:hopr-crypto-types

Suggested reviewers

  • Teebor-Choka

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added testing Related to tests crate:hoprd-api labels Sep 24, 2024
@Teebor-Choka Teebor-Choka requested a review from a team September 24, 2024 10:09
@Teebor-Choka Teebor-Choka self-assigned this Sep 24, 2024
@Teebor-Choka Teebor-Choka added this to the 2.2.0-rc.1 milestone Sep 24, 2024
@Teebor-Choka Teebor-Choka marked this pull request as ready for review September 24, 2024 10:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 3327cb6 and 6842083.

Files selected for processing (3)
  • hoprd/rest-api/src/session.rs (1 hunks)
  • tests/hopr.py (1 hunks)
  • tests/test_integration.py (2 hunks)
Additional context used
Ruff
tests/test_integration.py

880-880: Module level import not at top of file

(E402)


885-885: f-string without any placeholders

Remove extraneous f prefix

(F541)


922-922: Line too long (125 > 120)

(E501)

Additional comments not posted (2)
tests/hopr.py (1)

388-393: Changes align with PR objectives

The modification to the session_client method, which now allows specifying the host for the session client, aligns well with the PR objective of adding a separate test for the WireGuard tunnel. This change provides the flexibility needed to test different network configurations, which is crucial for thoroughly testing WireGuard tunnel functionality.

hoprd/rest-api/src/session.rs (1)

52-52: 🛠️ Refactor suggestion

Ensure consistency in field naming and update documentation

The renaming of "listen_host" to "listenHost" aligns with the #[serde(rename_all = "camelCase")] attribute. However, other fields in the struct still use snake_case naming. Consider the following actions:

  1. Update all field names in the struct to use camelCase for consistency with the serde attribute.
  2. Update any documentation or API specifications that reference the old field name.
  3. Ensure that this change doesn't break existing clients that may be using the old field name.

Consider updating all field names in the struct to camelCase:

 #[serde(rename_all = "camelCase")]
 pub(crate) struct SessionClientRequest {
     #[serde_as(as = "DisplayFromStr")]
-    pub destination: PeerId,
-    pub path: RoutingOptions,
-    pub target: String,
+    pub destination: PeerId,
+    pub path: RoutingOptions,
+    pub target: String,
     pub listen_host: Option<String>,
     #[serde_as(as = "Option<Vec<DisplayFromStr>>")]
-    pub capabilities: Option<Vec<SessionCapability>>,
+    pub capabilities: Option<Vec<SessionCapability>>,
 }

To ensure this change doesn't break existing usage, run the following script:

@github-actions github-actions bot added dependencies Pull requests that update a dependency file crate:core-transport labels Sep 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range comments (1)
transport/session/Cargo.toml (1)

Line range hint 28-49: Consider grouping related dependencies

While the changes look good, you might want to consider grouping related dependencies together for better readability. For example, you could move the "hopr-metrics" dependency closer to other HOPR-related dependencies.

Here's a suggested regrouping:

[dependencies]
# ... other dependencies ...

hopr-network-types = { workspace = true }
hopr-crypto-random = { workspace = true }
hopr-crypto-types = { workspace = true }
hopr-internal-types = { workspace = true }
hopr-metrics = { workspace = true, optional = true }
hopr-primitive-types = { workspace = true }

# ... rest of the file ...
Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 6842083 and 7689e1b.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (4)
  • METRICS.md (1 hunks)
  • transport/api/Cargo.toml (1 hunks)
  • transport/session/Cargo.toml (2 hunks)
  • transport/session/src/types.rs (2 hunks)
Additional comments not posted (5)
transport/session/Cargo.toml (3)

28-28: LGTM: New "prometheus" feature added

The addition of the "prometheus" feature is a good way to introduce optional Prometheus metrics support. It correctly depends on "hopr-metrics" and "lazy_static".


34-34: LGTM: Optional "lazy_static" dependency added

The "lazy_static" dependency is correctly added as optional and uses the workspace version, which is good for maintaining consistency across the project.


49-49: LGTM: Optional "hopr-metrics" dependency added

The "hopr-metrics" dependency is correctly added as optional and uses the workspace version, ensuring consistency with other parts of the project.

transport/session/src/types.rs (2)

299-301: LGTM! Metric observation correctly implemented.

The addition of the metric observation in the poll_write method is well-placed and correctly implemented. It will provide valuable insights into the sizes of data chunks being written in each session.


Line range hint 24-301: Overall, the changes look good and improve observability.

The addition of Prometheus metrics for session inner sizes is a valuable improvement to the codebase. The implementation is correct, follows best practices, and is properly integrated into the existing code. These changes will provide useful insights into the performance and behavior of the session data transfers.

Teebor-Choka and others added 5 commits September 24, 2024 16:28
Adjusted the session initialization retry strategy by reducing the backoff delay to 1000 milliseconds and the number of retries to 3. Additionally, fixed the logic for handling UDP parallelism by ensuring the parallelism value cannot be lower than the available parallelism.
…test' into kauki/test/add-wireguard-tunnel-test
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0cd816a and 245979e.

Files selected for processing (3)
  • common/network-types/src/udp.rs (1 hunks)
  • hoprd/hoprd/src/lib.rs (1 hunks)
  • hoprd/rest-api/src/session.rs (3 hunks)
Additional comments not posted (4)
hoprd/hoprd/src/lib.rs (1)

139-151: Improved code structure and platform-specific configuration.

The changes to the ConnectedUdpStream construction improve the code structure by separating the builder configuration from the instantiation. This enhances readability and maintainability. The conditional compilation for Linux-specific configuration is a good practice for handling platform differences.

However, there are a couple of points to consider:

  1. The TODO comment about MacOS behavior suggests that there might be platform-specific issues that need to be addressed. It would be beneficial to elaborate on this comment or create a separate issue to track and resolve the MacOS-specific behavior.

  2. Consider adding a comment explaining why parallelism is set to 0 for Linux. This would help other developers understand the reasoning behind this platform-specific configuration.

To ensure that this change doesn't introduce any regressions, please run the following command to check for any existing tests related to UDP stream creation:

If there are no existing tests, consider adding a new test case to verify the behavior of ConnectedUdpStream creation on different platforms.

hoprd/rest-api/src/session.rs (2)

52-52: LGTM: Consistent naming convention applied.

The renaming of listen_host to listenHost aligns with the camelCase formatting specified by the #[serde(rename_all = "camelCase")] attribute on the struct. This change enhances consistency in the JSON structure.


182-182: Verify the impact of the modified retry strategy.

The retry strategy has been adjusted:

  • Backoff duration reduced from 2000ms to 1000ms
  • Number of retries decreased from 5 to 3

While this change reduces the total retry time, it might affect the reliability of session initialization in unstable network conditions.

Please confirm that this modification doesn't negatively impact the session establishment success rate. Consider running the following test:

Verification successful

Retry strategy modification appears safe.

No evidence of increased session initialization failures was found based on the recent code analysis. The reduced backoff duration and fewer retries do not seem to negatively impact the reliability under current conditions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any recent changes or issues related to session initialization failures

# Test: Look for any recent changes or issues related to session initialization
rg --type rust -i "session.*initiali[sz]ation|connect.*fail" --glob '!target/'

Length of output: 94056

common/network-types/src/udp.rs (1)

170-177: Improved parallelism calculation logic

The changes in this segment enhance the robustness and clarity of the parallelism calculation:

  1. The avail_parallelism calculation now ensures a minimum value of 1, preventing potential issues with zero parallelism.
  2. The num_socks calculation has been simplified and made more explicit, improving readability.

These modifications make the code more resilient and easier to understand.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 245979e and 9f23c68.

Files selected for processing (3)
  • common/network-types/src/udp.rs (3 hunks)
  • tests/hopr.py (1 hunks)
  • tests/test_integration.py (2 hunks)
Additional context used
Ruff
tests/hopr.py

388-388: Line too long (143 > 120)

(E501)


396-396: Line too long (136 > 120)

(E501)

tests/test_integration.py

880-880: Module level import not at top of file

(E402)


885-885: f-string without any placeholders

Remove extraneous f prefix

(F541)


925-925: Line too long (125 > 120)

(E501)

Additional comments not posted (1)
common/network-types/src/udp.rs (1)

175-182: Ensure num_socks calculation behaves correctly on all platforms

The calculation of num_socks relies on self.parallelism and avail_parallelism. On non-Linux systems, self.parallelism will be None, resulting in num_socks being set to 1. Verify that this behavior is intended and that the code does not attempt to create multiple sockets on unsupported platforms.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 54b4c4b and 2b73e54.

Files selected for processing (2)
  • hoprd/rest-api/src/session.rs (3 hunks)
  • transport/session/src/types.rs (3 hunks)
Additional context used
Learnings (1)
transport/session/src/types.rs (1)
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6506
File: transport/session/src/types.rs:24-33
Timestamp: 2024-09-24T13:15:42.300Z
Learning: When adding metrics, if the description is already contained in the metric definition, no additional comments are necessary.
Additional comments not posted (4)
hoprd/rest-api/src/session.rs (2)

52-52: LGTM: Consistent camelCase naming in SessionClientRequest struct

The renaming of listen_host to listenHost in the example JSON aligns with the #[serde(rename_all = "camelCase")] attribute on the struct. This change improves consistency in the JSON representation of the SessionClientRequest.


Line range hint 1-605: Overall improvements, but no direct relation to PR objective

The changes in this file represent general improvements to the session handling code, including:

  1. Consistent naming in struct fields
  2. Adjusted retry strategy for session initialization
  3. Improved UDP socket configuration

While these changes are positive, they don't seem directly related to the stated PR objective of "Add a separate test for wireguard tunnel".

To ensure we're not missing any WireGuard-related changes, let's check for any mentions of WireGuard in the file:

If this search doesn't yield any results, it might be worth clarifying with the PR author how these changes relate to the stated objective, or if the PR description needs updating to reflect these additional improvements.

Verification successful

Overall improvements, but no direct relation to PR objective

The changes in hoprd/rest-api/src/session.rs represent general improvements to the session handling code, including:

  1. Consistent Naming: Streamlined struct field names for better readability.
  2. Retry Strategy: Adjusted the retry mechanism for session initialization to enhance reliability.
  3. UDP Socket Configuration: Improved the configuration settings for UDP sockets to optimize performance.

These modifications are positive and contribute to the overall quality of the codebase. However, they do not appear to be directly related to the PR's stated objective of adding a separate test for the WireGuard tunnel.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any mentions of WireGuard in the file
rg -i "wireguard" hoprd/rest-api/src/session.rs

Length of output: 47


Script:

#!/bin/bash
# Search for any mentions of WireGuard in the entire codebase
rg -i "wireguard"

Length of output: 2928

transport/session/src/types.rs (2)

24-33: LGTM! The metric definition is well-structured.

The new METRIC_SESSION_INNER_SIZES metric is appropriately defined with conditional compilation and uses a MultiHistogram with well-chosen bucket sizes. This will provide valuable insights into the sizes of data chunks processed by the inner session of the HOPR protocol.


486-494: LGTM! Excellent performance optimization.

The introduction of BufWriter for buffering writes into the session is a great performance optimization. This change can significantly reduce the number of write operations, especially when dealing with small writes, by batching them together.

Key improvements:

  1. The buffer capacity is correctly set to into_session_len, ensuring optimal buffering.
  2. The use of FuturesAsyncReadCompatExt::compat adapter ensures compatibility with tokio's AsyncRead/AsyncWrite traits.
  3. The copy_duplex function now works with the buffered session writer, potentially improving overall data transfer efficiency.

These changes should lead to more efficient data transfer between the session and the stream.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 2b73e54 and de164b8.

Files selected for processing (1)
  • transport/session/src/types.rs (3 hunks)
Additional context used
Learnings (1)
transport/session/src/types.rs (1)
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6506
File: transport/session/src/types.rs:24-33
Timestamp: 2024-09-24T13:15:42.300Z
Learning: When adding metrics, if the description is already contained in the metric definition, no additional comments are necessary.
Additional comments not posted (2)
transport/session/src/types.rs (2)

24-33: No issues found in metric declaration

The metric METRIC_SESSION_INNER_SIZES is correctly defined and initialized with appropriate labels and buckets.


299-301: Optimize string allocation in metric observation

As previously suggested, consider caching the string representation of self.id to avoid allocating a new String on each call to to_string(). This can enhance performance if poll_write is called frequently.

Modified `tests/hopr.py` to handle capabilities conditionally when creating a session client request. Updated `transport/protocol/src/lib.rs` to replace `debug` log levels with `trace` for packet delay information.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c4bd4cb and 0a44693.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • tests/hopr.py (1 hunks)
  • transport/protocol/src/lib.rs (2 hunks)
🧰 Additional context used
🪛 Ruff
tests/hopr.py

388-388: Line too long (143 > 120)

(E501)


401-401: Line too long (140 > 120)

(E501)

🔇 Additional comments (2)
Cargo.toml (1)

49-49: LGTM! Consider documenting the usage of arrayvec.

The addition of the arrayvec dependency with the "serde" feature is appropriate for projects requiring fixed-size arrays with serialization capabilities. This is consistent with the project's existing use of serialization-related crates.

To improve maintainability, consider adding a comment in the Cargo.toml file or updating the project documentation to explain the intended use of arrayvec in the codebase.

transport/protocol/src/lib.rs (1)

289-292: Approved: Improved logging granularity

The change from debug! to trace! for logging the mixer's random packet delay is a good improvement. This modification reduces log verbosity in production environments while still preserving the ability to access this information when needed.

Key points:

  1. The log message content remains unchanged, maintaining the important information about the delay.
  2. Using trace! instead of debug! allows for finer-grained control over log output.
  3. This change doesn't affect the functionality of the code, only its observability.

@NumberFour8 NumberFour8 merged commit 49f3639 into master Sep 27, 2024
25 checks passed
@NumberFour8 NumberFour8 deleted the kauki/test/add-wireguard-tunnel-test branch September 27, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:core-protocol crate:core-transport crate:hoprd-api dependencies Pull requests that update a dependency file testing Related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants