Skip to content

Conversation

NumberFour8
Copy link
Contributor

When Session gets created and listed (via create/list REST API) endpoints, the path now gets returned as well reflecting on the routing options for that Session.

Also, new return code has been added when the listening host for a new session is already occupied.

Closes #6693
Closes #6694

When Session gets created and listed (via create/list REST API) endpoints, the `path` now gets returned as well reflecting on the routing options for that Session.

Also, new return code has been added when the listening host for a new session is already occupied.
@NumberFour8 NumberFour8 requested a review from a team December 13, 2024 10:21
@NumberFour8 NumberFour8 self-assigned this Dec 13, 2024
@NumberFour8 NumberFour8 marked this pull request as ready for review December 13, 2024 10:22
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

📝 Walkthrough

Walkthrough

The pull request introduces changes to session management and error handling across multiple files in the Hoprd project. The modifications primarily focus on improving the structure of session-related data by introducing a new StoredSessionEntry struct, updating type definitions, and enhancing error reporting. The changes aim to provide more detailed information about session paths and improve the specificity of error messages when dealing with port conflicts.

Changes

File Change Summary
hoprd/hoprd/src/main.rs Simplified extraction of join handles from session_listener_sockets
hoprd/rest-api/src/lib.rs - Replaced SessionTargetSpec with StoredSessionEntry in ListenerJoinHandles type
- Added ListenHostAlreadyUsed variant to ApiErrorStatus enum
hoprd/rest-api/src/session.rs - Introduced StoredSessionEntry struct
- Updated SessionClientResponse to include path field
- Modified create_client to use more specific error handling

Assessment against linked issues

Objective Addressed Explanation
Return path and exit node in session responses [#6693]
Improve error handling for port conflicts [#6694]

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b0c234 and 2aabe1f.

📒 Files selected for processing (2)
  • hoprd/rest-api/src/lib.rs (3 hunks)
  • hoprd/rest-api/src/session.rs (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hoprd/rest-api/src/lib.rs
🔇 Additional comments (5)
hoprd/rest-api/src/session.rs (5)

119-128: LGTM! Well-structured session entry type.

The new StoredSessionEntry struct provides a clear and type-safe way to store session data, replacing the previous tuple-based storage. The fields are appropriately documented and the structure aligns with the PR objectives.


443-443: LGTM! Response structure updated to include routing path.

The addition of the path field to SessionClientResponse fulfills the PR objective of exposing routing options in the session listing.

Also applies to: 452-452


537-537: LGTM! Improved error handling for occupied hosts.

The error handling has been enhanced to consistently return ListenHostAlreadyUsed status when the listening host is already occupied, both for TCP and UDP protocols. This improves the API's error reporting as specified in the PR objectives.

Also applies to: 557-557, 622-622


608-615: LGTM! Consistent session storage and retrieval implementation.

The implementation consistently uses the new StoredSessionEntry structure for both TCP and UDP sessions, properly storing and retrieving the routing path information. The session listing functionality correctly exposes this information in the API response.

Also applies to: 648-663, 713-718


119-128: Verify consistent usage of StoredSessionEntry across the codebase.

Let's ensure the new structure is used consistently throughout the codebase.

✅ Verification successful

Based on the search results, I can now generate the final response:

StoredSessionEntry is consistently used for session storage across the codebase

The verification shows that:

  • StoredSessionEntry is the only structure used for storing session data in the session registry (ListenerJoinHandles)
  • The structure is properly used with all its fields (target, path, jh) when inserting new sessions
  • Session management code correctly handles the structure when removing sessions
  • No legacy tuple-based storage patterns were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining tuple-based session storage and verify StoredSessionEntry usage

# Check for any remaining tuple storage patterns
rg -A 2 "HashMap<ListenerId,\s*\(" 

# Check for consistent usage of StoredSessionEntry
rg "StoredSessionEntry" 

# Check for any missed path fields in session responses
ast-grep --pattern 'struct $name {
  $$$
  path: $type,
  $$$
}'

Length of output: 639


Script:

#!/bin/bash
# Let's verify more thoroughly with different approaches

# Check for any HashMap usage with session-related types
rg -A 3 "HashMap.*Session"

# Look for all struct definitions with 'Session' in their name
ast-grep --pattern 'struct $name {
  $$$
}'

# Search for any session-related response types
rg -A 5 "struct.*Response"

# Check for any session creation or storage patterns
rg -A 3 "new_session|create_session|store_session"

Length of output: 66072


Script:

#!/bin/bash
# Let's focus on session-related code in the hoprd codebase

# Search for session-related struct definitions and implementations
rg -A 5 "struct.*Session|impl.*Session"

# Look for session creation and storage patterns
rg -A 5 "new_session|create_session|add_session|register_session"

# Check for session registry/storage usage
rg -A 5 "SessionRegistry|session_registry|sessions"

# Look for any session target or path usage
rg -A 5 "SessionTargetSpec|RoutingOptions"

Length of output: 83264


Script:

#!/bin/bash
# Let's focus specifically on the session storage and routing options

# Check for StoredSessionEntry usage and implementation
rg -A 5 "StoredSessionEntry"

# Look for session target and routing options usage
rg -A 5 "SessionTargetSpec|RoutingOptions" hoprd/

# Check for session storage/registry patterns in hoprd
rg -A 5 "HashMap.*Session|session_registry|sessions" hoprd/

# Look for any modifications to session storage
rg -A 5 "insert|remove|add.*session" hoprd/

Length of output: 30592


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@NumberFour8 NumberFour8 added this to the 2.2.0-rc.1 milestone Dec 13, 2024
@github-actions github-actions bot added dependencies Pull requests that update a dependency file crate:hoprd-api crate:hoprd labels Dec 13, 2024
@NumberFour8 NumberFour8 requested a review from tolbrino December 13, 2024 11:04
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: 0

🧹 Outside diff range and nitpick comments (1)
hoprd/rest-api/src/session.rs (1)

552-559: Consider reducing code duplication in session storage.

The session storage logic is duplicated between TCP and UDP handlers. Consider extracting the common storage logic into a helper function.

+ fn store_session(
+     open_listeners: &mut tokio::sync::RwLockWriteGuard<'_, HashMap<ListenerId, StoredSessionEntry>>,
+     listener_id: ListenerId,
+     target: SessionTargetSpec,
+     path: RoutingOptions,
+     jh: hopr_async_runtime::prelude::JoinHandle<()>,
+ ) {
+     open_listeners.insert(
+         listener_id,
+         StoredSessionEntry {
+             target,
+             path,
+             jh,
+         },
+     );
+ }

Also applies to: 592-607

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26e3eb1 and 3b0c234.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • hoprd/rest-api/Cargo.toml (1 hunks)
  • hoprd/rest-api/src/session.rs (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hoprd/rest-api/Cargo.toml
🔇 Additional comments (4)
hoprd/rest-api/src/session.rs (4)

120-129: LGTM! Well-structured session storage.

The new StoredSessionEntry struct provides a clear and well-documented structure for session data, improving code readability and maintainability over the previous tuple-based storage.


481-481: LGTM! Improved error handling for address conflicts.

The consistent use of ListenHostAlreadyUsed error status across TCP and UDP bindings provides clearer feedback when attempting to bind to an already occupied address.

Also applies to: 501-501, 566-566


387-387: LGTM! Response structure properly includes path information.

The SessionClientResponse has been correctly updated to include path information, and this is consistently implemented in both creation and listing endpoints.

Also applies to: 396-396, 618-618, 657-662


735-739: LGTM! Proper async resource cleanup.

The join handle is correctly cancelled during session cleanup, ensuring proper resource management and preventing potential leaks.

@NumberFour8 NumberFour8 changed the title Output routing options in the session listing Output routing options in the Session listing Dec 13, 2024
@NumberFour8
Copy link
Contributor Author

Needs #6737 to be merged first

# Conflicts:
#	hoprd/rest-api/src/session.rs
@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label Dec 17, 2024
@NumberFour8 NumberFour8 merged commit e68fb04 into master Dec 17, 2024
28 checks passed
@NumberFour8 NumberFour8 deleted the lukas/improve-session-rest-api branch December 17, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants