Skip to content

Improve the tag organization for v3 packet payload format #7203

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

Merged
merged 5 commits into from
May 30, 2025

Conversation

Teebor-Choka
Copy link
Contributor

@Teebor-Choka Teebor-Choka commented May 30, 2025

Changes to the packet structure in the tag section and reserved tag allocation:

  • packet: Improve the tag representation
  • Compress v3 tag usage to minimize the session allocated space

Copy link
Contributor

coderabbitai bot commented May 30, 2025

📝 Walkthrough
## Walkthrough

The changes refactor the tag system in the transport packet module, replacing the old `Tag` struct and related types with a new `Tag` enum distinguishing reserved and application tags. All related logic, tests, and APIs are updated to use the new model. Test code and session management are adjusted for compatibility, and error handling is improved for tag-related issues.

## Changes

| File(s)                                                                                   | Change Summary                                                                                                                                                                                                                                                                       |
|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| transport/packet/src/v1.rs                                                                | Refactored `Tag` from struct to enum (`Reserved(u64)`, `Application(u64)`), expanded `ReservedTag`, unified conversions, updated serialization, removed obsolete types, added unit tests.                                                     |
| transport/packet/src/lib.rs                                                               | Stopped re-exporting `CustomTag` and `ResolvedTag` from prelude; only `ApplicationData`, `ReservedTag`, and `Tag` are now re-exported.                                                                                                       |
| transport/packet/src/errors.rs                                                            | Added `TagError(String)` variant to `PacketError` enum.                                                                                                                                                |
| transport/packet/Cargo.toml                                                               | Added `strum` as a workspace dependency.                                                                                                                                                                                                      |
| transport/api/src/lib.rs                                                                  | Renamed `USABLE_TAG_RANGE` to `APPLICATION_TAG_RANGE`, updated range logic, changed session tag handling to use new `Tag` enum, updated `send_message` API and error messages, adjusted imports.                                             |
| transport/session/src/manager.rs                                                          | Changed session tag range from `Range<Tag>` to `Range<u64>`, updated related logic, removed `MIN_SESSION_TAG_RANGE_RESERVATION`, used `ReservedTag::range().end`.                                      |
| transport/session/src/initiation.rs                                                       | Unified encoding/decoding of `StartProtocol<T>` variants under a fixed reserved tag; added versioning and discriminant bytes in payload; updated tag usage and test assertions accordingly.                                                         |
| transport/session/src/errors.rs                                                           | Removed `Tag` variant from `TransportSessionError` enum, added `StartProtocolError(String)`.                                                                                                                                                 |
| transport/session/src/lib.rs                                                              | Removed export of `USABLE_PAYLOAD_CAPACITY_FOR_SESSION`, changed `SESSION_PAYLOAD_SIZE` to use `ApplicationData::PAYLOAD_SIZE`.                                                                                                     |
| transport/session/src/types.rs                                                            | Generalized `SessionId::new` to accept any `Into<Tag>`, replaced `USABLE_PAYLOAD_CAPACITY_FOR_SESSION` with `ApplicationData::PAYLOAD_SIZE`, fixed deserialization and duplicate field error message.                                               |
| hopr/hopr-lib/src/lib.rs                                                                  | Removed export of `USABLE_PAYLOAD_CAPACITY_FOR_SESSION` constant.                                                                                                                                                                                      |
| hopr/hopr-lib/tests/session_integration_tests.rs<br>hoprd/rest-api/src/session.rs         | Updated `SessionId` and `HoprSessionId` construction in tests to use `u64` directly instead of `Tag`, replaced payload size constants with `ApplicationData::PAYLOAD_SIZE`.                                                                    |
| transport/probe/src/probe.rs                                                              | Changed tag comparisons and construction to use `.into()` for `ReservedTag` to `Tag` conversion, adjusted imports and test code accordingly.                                                                                                     |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant App as Application
    participant HoprTransport
    participant Packet as Packet Layer

    App->>HoprTransport: send_message(msg, routing, tag: Tag)
    HoprTransport->>HoprTransport: Check if tag is reserved (Tag::Reserved)
    alt Tag is reserved
        HoprTransport-->>App: Error(TagError)
    else Tag is application
        HoprTransport->>Packet: Create ApplicationData(tag)
        Packet-->>HoprTransport: ApplicationData
        HoprTransport-->>App: Ok
    end

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Teebor-Choka

</details>

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

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


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between ae74423bdd6f7a4874af3d04b8646af9631b9074 and 1abf8b903adc8dc0fcf9c75551b228c0b0a01624.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `hoprd/rest-api/src/prometheus.rs` (1 hunks)

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (1)</summary>

* hoprd/rest-api/src/prometheus.rs

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (9)</summary>

* GitHub Check: tests-smoke-hopli
* GitHub Check: tests-unit-nightly
* GitHub Check: tests-unit
* GitHub Check: tests-smart-contracts
* GitHub Check: hoprd / docker
* GitHub Check: hopli / docker
* GitHub Check: zizmor
* GitHub Check: Linter
* GitHub Check: Cargo Audit

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIASWZefCkw2A9cNCJ+CiJMeAAvanh8LAAzfD4JAGYeNAYAaxJQ7jRZL3w0ejKKZmoAGmj7bAFmdRp6OUhsREoYEhIBcrAAYVh8OrR0ZFtIDEcBGYB2ACYABkrengp8bnxp5AZYTFJkAhSPZvrG+1wKbDFsfz2biieAleAMNA+eTwLC4VJhDL2UTiYroDD0OEefzTChSDGIyFtCEojAaGDw5iKUHgwrFZAwhhebBKFAJK4SGGZTF+Ei8aTsWlYfAlBFEZAAd3UCFh8I+DU0kAAgrRaOoihhCbILtzttpmC98Ao2dIXvCphkPMLIFVRQbICMMPARnk0vC7oh1egfPhiVFEB8SGSAEL4OGsxJSNgYXB27npTL+PnTaOCtH0JjGxAe1FWm3xyaIC3oQEw1W++hoe4sbiRMZk9yeHw8oIhRiYSD7HkckjiqLUSCwXC4biIDgAejHRClQw0GbHq145Fw8+uFCXY+43i8Y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kNFYHQRCgAMIAAnINDQAkB6EAgBgLQDmgC4SAg0AQMjpOAMA5oc0LanjpKAC4GAg0QaETtoAMADgC0EgMjoEALQBcCOx7XNBx3bpBolQA4DUhOALQ2dJQIXYNBF0lAGAlQAnXNFR3I6jgGOo4JUFEDI6BclQI4BzuPCQABcAuI4MjoZ0HABccuhaHNAECVABA9CBgCcAFwCABcHQM3cjvoS0Bjgquw3QcGkwY76AgETXejsZ0LRFdAgFUHNBKAHA0AbOxnZckqC0BBdNuxaHNEuTI65oUuwnScEZ0a6IAndFQJTuT2VAOgDAAXPTpOAS6Sgeug4FunoQE6jgRwKnScAEAnA0AAPOaEcAWgI6DAoOj7eDvsgViD5MOunKeGB1AA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=hoprnet/hoprnet&utm_content=7203):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `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 explain this code block.`
  -	`@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 explain its main purpose.`
  - `@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.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@Teebor-Choka Teebor-Choka marked this pull request as ready for review May 30, 2025 13:05
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 13:05
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the tagging system used across the packet payload format and session management to improve clarity and efficiency. Key changes include:

  • Updating tag types and conversions (e.g. replacing Tag with ReservedTag where appropriate) to better enforce reserved vs. application tag ranges.
  • Modifying encoding/decoding logic for StartProtocol messages and adjusting related tests.
  • Refactoring error handling and API interfaces to reflect the new tag system.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
transport/session/src/manager.rs Updated tag range type and conversions using ReservedTag and u64.
transport/session/src/initiation.rs Adjusted StartProtocol tag encoding/decoding and added new conversion implementations.
transport/session/src/errors.rs Removed the obsolete Tag error variant.
transport/probe/src/probe.rs Updated tag comparisons to use ReservedTag conversions.
transport/packet/src/v1.rs Overhauled the Tag API by introducing a new enum differentiating Reserved and Application tags.
transport/api/src/lib.rs Adjusted API interfaces to use the new tag ranges and improved error message details.
hoprd/rest-api/src/session.rs & hopr-lib tests Updated tag construction using the new conversion syntax.
transport/packet/src/errors.rs & Cargo.toml Added new error variant for tag errors and included a Strum dependency.
Comments suppressed due to low confidence (1)

transport/api/src/lib.rs:631

  • The error message wording is unclear; consider rephrasing it to something like "Application tag must not be from the reserved range: {:?}, but received {reserved_tag:?}" to improve clarity.
return Err(HoprTransportError::Api(format!(
                  "Application tag must not from range: {:?}, but was {reserved_tag:?}",
                  Tag::APPLICATION_TAG_RANGE

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

🧹 Nitpick comments (1)
transport/session/src/initiation.rs (1)

79-79: Consider the future protocol evolution strategy

The TODO comment suggests using a dedicated tag with the entire object as payload. This current approach of embedding version and discriminant bytes provides good flexibility for protocol evolution.

Consider documenting the protocol versioning strategy to help future maintainers understand:

  • When to increment the version byte
  • How to handle backwards compatibility
  • Migration path to the suggested dedicated tag approach
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4591ae5 and 6d65313.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • hopr/hopr-lib/src/lib.rs (1 hunks)
  • hopr/hopr-lib/tests/session_integration_tests.rs (3 hunks)
  • hoprd/rest-api/src/session.rs (3 hunks)
  • transport/api/src/lib.rs (5 hunks)
  • transport/session/Cargo.toml (1 hunks)
  • transport/session/src/errors.rs (1 hunks)
  • transport/session/src/initiation.rs (8 hunks)
  • transport/session/src/lib.rs (1 hunks)
  • transport/session/src/manager.rs (8 hunks)
  • transport/session/src/types.rs (12 hunks)
✅ Files skipped from review due to trivial changes (2)
  • hopr/hopr-lib/src/lib.rs
  • transport/session/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (5)
  • transport/session/src/errors.rs
  • hopr/hopr-lib/tests/session_integration_tests.rs
  • hoprd/rest-api/src/session.rs
  • transport/api/src/lib.rs
  • transport/session/src/manager.rs
🧰 Additional context used
🧠 Learnings (1)
transport/session/src/lib.rs (1)
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6393
File: hoprd/rest-api/src/session.rs:91-91
Timestamp: 2024-07-31T10:24:08.332Z
Learning: The current implementation in `hoprd/rest-api/src/session.rs` assumes all sessions are TCP-like due to the missing implementation of UDP behavior. The commented-out code suggests an intention to support different session types based on `capabilities`.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: Linter
  • GitHub Check: tests-smoke-hopli
  • GitHub Check: tests-unit
  • GitHub Check: tests-unit-nightly
  • GitHub Check: zizmor
🔇 Additional comments (14)
transport/session/src/lib.rs (2)

20-20: LGTM: Import addition aligns with payload size refactoring

The addition of ApplicationData import is consistent with the broader refactoring to unify payload size constants across the transport layers.


31-31: LGTM: Const generic usage correctly references ApplicationData payload size

The update to use ApplicationData::PAYLOAD_SIZE as a const generic parameter properly unifies the session payload size with the packet layer definition. This ensures consistency across the transport stack.

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

73-74: LGTM: Generic constructor improves type flexibility

The change to accept Into<Tag> instead of a strict Tag parameter improves usability by allowing direct construction with u64 values while maintaining type safety through the conversion.


141-142: LGTM: Explicit type annotation ensures correct deserialization

The explicit Tag type annotation ensures the deserializer correctly handles the new Tag enum structure during sequence access.


151-152: LGTM: Consistent type annotations in map visitor

The explicit type annotations for both tag and pseudonym variables improve code clarity and ensure correct deserialization behavior.


157-157: LGTM: Fixed duplicate field error message

Good catch fixing the error message from "tx_tag" to "tag" to match the actual field name.


295-295: LGTM: Consistent payload size usage

The replacement of the removed constant with ApplicationData::PAYLOAD_SIZE maintains consistency with the broader payload size unification effort.


487-491: LGTM: Buffer calculations correctly updated

The buffer size calculations properly use ApplicationData::PAYLOAD_SIZE for chunking logic, maintaining the correct behavior while using the unified constant.


606-606: LGTM: Transfer function buffer size correctly updated

The transfer_session function correctly uses the unified payload size constant for buffer size calculations when segmentation capability is enabled.


668-668: LGTM: Test simplified with generic constructor

The test code correctly leverages the new generic SessionId::new constructor by passing u64 directly instead of converting to Tag first.

transport/session/src/initiation.rs (4)

96-105: LGTM: Well-structured constants and trait implementation

The implementation correctly defines the fixed protocol tag and version constants. The From trait implementation properly returns the fixed tag for all variants, which aligns with the unified tagging approach.


117-140: LGTM: Encode method correctly implements versioned protocol

The encode method properly:

  • Pre-allocates buffer with appropriate capacity
  • Embeds version byte and discriminant for protocol versioning
  • Maintains consistent serialization across all variants
  • Returns the fixed tag for all messages

This design allows for future protocol evolution while maintaining a single tag identifier.


144-183: LGTM: Comprehensive validation in decode method

The decode method implements proper validation:

  • Checks minimum message length (3 bytes for version + discriminant + data)
  • Validates the fixed protocol tag
  • Verifies protocol version for backwards compatibility
  • Handles unknown discriminants gracefully
  • Uses appropriate error types with descriptive messages

The validation logic ensures protocol integrity and provides clear error reporting.


262-263: LGTM: Test assertions correctly updated for fixed tag

All test assertions have been consistently updated to expect the fixed START_PROTOCOL_MESSAGE_TAG instead of variant-specific tags. This validates that the unified tagging approach works correctly across all protocol message types.

Also applies to: 298-299, 316-317, 331-332, 346-347

Copy link
Contributor Author

@Teebor-Choka Teebor-Choka left a comment

Choose a reason for hiding this comment

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

Please, update the tag ranges as well.

@Teebor-Choka Teebor-Choka linked an issue May 30, 2025 that may be closed by this pull request
5 tasks
@Teebor-Choka Teebor-Choka added this to the 3.0.0 milestone May 30, 2025
@Teebor-Choka Teebor-Choka enabled auto-merge May 30, 2025 21:12
@Teebor-Choka Teebor-Choka disabled auto-merge May 30, 2025 21:12
@NumberFour8 NumberFour8 added this pull request to the merge queue May 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2025
@Teebor-Choka Teebor-Choka merged commit 0d1b9c7 into master May 30, 2025
56 of 61 checks passed
@Teebor-Choka Teebor-Choka deleted the kauki/protocol/improve-the-tag-structure branch May 30, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify tag structures into single enum-based design in transport/packet
2 participants