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

Blockwise: Use hash instead of token for cache #554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpenate-ellenbytech
Copy link

@mpenate-ellenbytech mpenate-ellenbytech commented May 15, 2024

Credit to @zworks-okada for initial work regarding rx transfers. Expanded to include tx.

Closes #512

Needs more thorough testing than what I was able to do. Willing to help address concerns.

Summary by CodeRabbit

  • New Features

    • Introduced a new Request-Tag option for enhanced request handling.
  • Refactor

    • Updated various functions and methods to use hash uint64 instead of message.Token for observation requests, improving consistency and performance.
    • Modified function signatures within Client and Server structs for better data handling.
  • Improvements

    • Added RemoteAddr() method to client interfaces for better address handling.

These changes streamline observation request processing and enhance the overall efficiency of the application.

Copy link

coderabbitai bot commented May 15, 2024

Walkthrough

The recent changes involve updating various functions and methods across multiple files to utilize a uint64 hash parameter instead of a message.Token parameter. This modification aligns the codebase with the CoAP specification, ensuring that blockwise requests are correlated based on message options rather than tokens.

Changes

Files Change Summary
dtls/client.go, dtls/server/server.go, net/client/client.go, udp/client.go, udp/server/server.go Updated function signatures to replace message.Token with uint64 hash for handling observation requests.
message/option.go Added Request-Tag option with OptionID 292 and corresponding definitions.
net/blockwise/blockwise.go, net/blockwise/blockwise_test.go Various modifications related to using uint64 hash instead of message.Token for blockwise operations.
tcp/client.go, tcp/server/server.go Updated function signatures to use uint64 hash instead of message.Token for observation requests.

Assessment against linked issues

Objective Addressed Explanation
Blockwise requests should be correlated based on message options (#512)

Poem

In code's vast sea, a change takes flight,
From tokens to hashes, we set it right.
Observations flow with options clear,
A smoother path, no need to fear.
With uint64 our guide, we stride,
Through blockwise realms, with specs beside.
🌟🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2a95bd6 and bb2fd9b.
Files selected for processing (11)
  • dtls/client.go (1 hunks)
  • dtls/server/server.go (1 hunks)
  • message/option.go (4 hunks)
  • net/blockwise/blockwise.go (21 hunks)
  • net/blockwise/blockwise_test.go (2 hunks)
  • net/client/client.go (1 hunks)
  • net/observation/handler.go (1 hunks)
  • tcp/client.go (2 hunks)
  • tcp/server/server.go (1 hunks)
  • udp/client.go (2 hunks)
  • udp/server/server.go (1 hunks)
Additional comments not posted (21)
tcp/client.go (1)

81-82: Update the parameter type to hash uint64 in the GetObservationRequest function call.

This change aligns with the objective of using a hash instead of a token for cache.

udp/client.go (1)

80-81: Update the parameter type to hash uint64 in the GetObservationRequest function call.

This change aligns with the objective of using a hash instead of a token for cache.

dtls/client.go (1)

93-94: Update the parameter type to hash uint64 in the GetObservationRequest function call.

This change aligns with the objective of using a hash instead of a token for cache.

tcp/server/server.go (1)

196-196: Update the parameter type to hash uint64 in the GetObservationRequest function call.

This change aligns with the objective of using a hash instead of a token for cache.

dtls/server/server.go (1)

201-202: Update the parameter type to hash uint64 in the GetObservationRequest function call.

This change aligns with the objective of using a hash instead of a token for cache.

net/client/client.go (1)

108-109: Update the parameter type to hash uint64 in the GetObservationRequest function.

This change aligns with the objective of using a hash instead of a token for cache.

net/observation/handler.go (1)

111-112: Update method signature to use hash instead of token.

The change to use hash uint64 instead of token message.Token in the GetObservationRequest method aligns with the PR objective and appears correct.

udp/server/server.go (1)

281-286: Update method signature to use hash instead of token.

The change to use hash uint64 instead of token message.Token in the getOrCreateConn method aligns with the PR objective and appears correct.

message/option.go (2)

50-50: Add new option Request-Tag.

The addition of the Request-Tag option with OptionID 292 aligns with the PR objective and appears correct.


77-77: Add RequestTag to optionIDToString map.

The addition of the RequestTag option to the optionIDToString map ensures proper string representation and aligns with the PR objective.

Also applies to: 101-101

net/blockwise/blockwise_test.go (1)

58-60: The addition of the RemoteAddr method looks good and provides a hardcoded IP address for testing purposes.

net/blockwise/blockwise.go (10)

8-8: Import of hash/crc64 is necessary for generating hash values.


146-146: The function signature update to use hash uint64 instead of token message.Token aligns with the new caching mechanism.


168-171: The function signature and default value update to use hash uint64 instead of token message.Token is consistent with the new caching mechanism.


222-223: The addition of the matchableHash variable to store the hash value generated from the message options, remote address, and code is necessary for the new caching mechanism.


291-293: The update of the WriteMessage function to use matchableHash is necessary for the new caching mechanism.


342-343: The addition of the getSendingMessageCode function to retrieve the code of the sending message using the hash value is necessary for the new caching mechanism.


357-358: The update of the Handle function to use matchableHash is necessary for the new caching mechanism.


Line range hint 389-421: The update of the handleReceivedMessage function to use rx_hash is necessary for the new caching mechanism.


Line range hint 540-563: The update of the startSendingMessage function to use rx_hash is necessary for the new caching mechanism.


756-779: The addition of the generateMatchableHash function to generate a hash value from the message options, remote address, and code is necessary for the new caching mechanism.

Copy link

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between bb2fd9b and 7098e70.
Files selected for processing (11)
  • dtls/client.go (1 hunks)
  • dtls/server/server.go (1 hunks)
  • message/option.go (4 hunks)
  • net/blockwise/blockwise.go (21 hunks)
  • net/blockwise/blockwise_test.go (2 hunks)
  • net/client/client.go (1 hunks)
  • net/observation/handler.go (1 hunks)
  • tcp/client.go (2 hunks)
  • tcp/server/server.go (1 hunks)
  • udp/client.go (2 hunks)
  • udp/server/server.go (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • dtls/client.go
  • dtls/server/server.go
  • message/option.go
  • net/blockwise/blockwise_test.go
  • net/client/client.go
  • net/observation/handler.go
  • tcp/client.go
  • tcp/server/server.go
  • udp/client.go
  • udp/server/server.go
Additional comments not posted (10)
net/blockwise/blockwise.go (10)

8-8: The addition of the crc64 import is appropriate for the new hash generation functionality.


146-146: The function signature update to use hash uint64 instead of token message.Token aligns with the new hash-based cache identification approach.


168-171: The update to the New function to accept getSentRequestFromOutside with hash uint64 is consistent with the new hash-based approach.


222-223: The addition of the matchableHash generation in the Do function is crucial for the new hash-based cache mechanism.


291-293: The addition of the matchableHash generation in the WriteMessage function is necessary for the new hash-based cache mechanism.


342-343: The addition of the getSendingMessageCode function to retrieve the message code using the hash is essential for the new hash-based approach.


357-358: The addition of the matchableHash generation in the Handle function is necessary for the new hash-based cache mechanism.


514-515: The addition of the matchableHash generation in the continueSendingMessage function is necessary for the new hash-based cache mechanism.


Line range hint 540-563: The update to the startSendingMessage function to use the rx_hash is consistent with the new hash-based approach.


756-777: The addition of the generateMatchableHash function is a critical component of the new hash-based cache mechanism.

Credit to @zworks-okada for initial work regarding rx transfers. Expanded to include tx.

Closes plgd-dev#512
@mpenate-ellenbytech
Copy link
Author

Fixed linting issues.

I should add that I am not a golang programmer, and addressing test failures will be difficult without any help. I can ask a colleague for some of their input but direct help would be appreciated.

Copy link

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7098e70 and 798345f.
Files selected for processing (11)
  • dtls/client.go (1 hunks)
  • dtls/server/server.go (1 hunks)
  • message/option.go (4 hunks)
  • net/blockwise/blockwise.go (21 hunks)
  • net/blockwise/blockwise_test.go (2 hunks)
  • net/client/client.go (1 hunks)
  • net/observation/handler.go (1 hunks)
  • tcp/client.go (2 hunks)
  • tcp/server/server.go (1 hunks)
  • udp/client.go (2 hunks)
  • udp/server/server.go (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • dtls/client.go
  • dtls/server/server.go
  • message/option.go
  • net/blockwise/blockwise_test.go
  • net/client/client.go
  • net/observation/handler.go
  • tcp/client.go
  • tcp/server/server.go
  • udp/client.go
  • udp/server/server.go
Additional comments not posted (10)
net/blockwise/blockwise.go (10)

8-8: Import of crc64 looks good.


137-138: Addition of RemoteAddr() method to the Client interface looks good.


146-146: Update to use uint64 for caching in BlockWise struct looks good.


168-171: Update to the New constructor function to accept func(hash uint64) (*pool.Message, bool) looks good.


222-227: Update to the Do method to generate and use a matchable hash looks good.


291-293: Update to the WriteMessage method to generate and use a matchable hash looks good.


342-343: Introduction of the getSendingMessageCode method looks good.


357-360: Update to the Handle method to generate and use a matchable hash looks good.


Line range hint 389-421: Update to the handleReceivedMessage method to accept a rxHash uint64 parameter looks good.


756-774: Introduction of the generateMatchableHash function looks good.

@@ -504,7 +511,8 @@ func (b *BlockWise[C]) continueSendingMessage(w *responsewriter.ResponseWriter[C
}
var sendMessage *pool.Message
var more bool
b.sendingMessagesCache.LoadWithFunc(r.Token().Hash(), func(value *cache.Element[*pool.Message]) *cache.Element[*pool.Message] {
matchableHash := generateMatchableHash(r.Options(), w.Conn().RemoteAddr(), r.Code())
Copy link
Member

Choose a reason for hiding this comment

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

@mpenate-ellenbytech Thank you for contribution :)

This is an issue: the hash for the response will not match the request hash because r.Code() is different, and r.Options(), such as the URI, are not part of the response. Therefore, you cannot pair it correctly for block1.

For sending a big payload (Block1):
You can use RemoteAddress and MessageID, which need to be registered for each new request of type Confirmation/NonConfirmation and response. If MessageID is not supported, then only the remote address can be used to verify block1.

For receiving a big payload (Block2):
When you want to locate the sent request, this will not work because the hash will again be different. Therefore, you need to pair it with the request using MessageID. However, you need to set a new MessageID for each exchange (request and response).

BTW: For blockwise transfer via TCP, the token must be used as implemented now.

Therefore, create blockwiseTCP.go (original code) and blockwiseUDP.go, where blockwiseUDP.go will utilize MessageIDs.

for _, opt := range options {
switch opt.ID {
// Skip Blockwise Options and NoCacheKey Options
case message.Block1, message.Block2, message.Size1, message.Size2, message.RequestTag:
Copy link

Choose a reason for hiding this comment

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

I'm not sure what this hash is used for, but you may want to exclude RequestTag here.

Yes, the text says it is not part of the matchable set, but later on it says (roughly) that even if two requests are matchable, if they have different request tags, they should not be matched.

When I wrote RFC9175, we had the choice of wording while not changing the actual mechanism: We went for easier for those implementing the client side (where Request-Tag is excluded for the definition of being matchable, and then if two requests are matchable even if you don't want them to be, you add a Request-Tag and there is an extra rule on it for the server), or easier for those implementing the server side (when Request-Tag would not have been special, but in all the client sections we would have said "if the request are matchable except for possibly differing Request-Tag values"). We went for the former -- I'm not sure it was the right decision, especially if generateMatchableHash is used on the server side. (I can't tell easily without having more context of go-coap, was just pointed to this issue by a colleague).

Copy link

Choose a reason for hiding this comment

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

Also, the NoCacheKey options could more generally be recognzied from their option properties (lower bits of the number) rather than enumerating them (which will not be exhaustive).

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.

Blockwise requests should be correlated based on message options
3 participants