-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Define internal message flags in PacketHeader to contain the flags for internal use #4571
Conversation
src/transport/raw/MessageHeader.h
Outdated
bool IsPeerGroupMsgIdNotSynchronized() const { return mFlags.Has(Header::FlagValues::kPeerGroupMsgIdNotSynchronized); } | ||
|
||
/** Check if the message buffer should not be freed after sending. */ | ||
bool IsRetainedBuffer() const { return mFlags.Has(Header::FlagValues::kRetainedBuffer); } |
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.
Where and why would this get used? We used to have a thing for this, and we removed it, due to lack of use cases and the caller being able to just hold a handle if that's what they want.
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.
We do. #4372
When retaining a buffer with CRMP, the caller expects the msg to be unmodified. LwIP stack will normally prepend the packet headers as the packet traverses the UDP/IP/netif layers, which normally modifies the packet.
We need to deep-copies msg into a fresh object, and queues that for transmission, leaving the original msg available after return.
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.
I'll follow up in #4372, but I don't see why that needs this API on the packet header.
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 flag finally needs to be passed to Inet layer
INET_ERROR UDPEndPoint::SendMsg(const IPPacketInfo * pktInfo, System::PacketBufferHandle msg, uint16_t sendFlags)
The buffer is retained in messaging layer, currently, we only have PacketHeader and PayloadHeader passed to transport layer. Passing this flag from Messaging layer to Transport layer via PacketHeader seems the only viable path.
I will post another PR to pass this flag to Inet::UDP for #4372
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.
Couldn't agree more with @turon - if this is just API between layers, why not codify it as such - do we even need flags here? Seems like some simple parameters may even make this easier?
We already have PacketHeader to pass all flags from Messaging layer to Transport layer. |
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.
We should not be using flags here. Can we either use a struct with 1 bit members that we need, and add to it, or just have 1 bit members that we add to over time?
It is doable, but this struct will be similar to class BitFlags. The two internal flags defined in this PR are immediately needed now, more need to be added. Here is the full set of message flags defined in messaging layer: https://github.com/project-chip/connectedhomeip/blob/master/src/messaging/Flags.h /**
enum class SendMessageFlags : uint16_t Some of them are inherited from Weave and we might not need it eventually, but most of them will be passed to transport layer as corresponding feature comes in. |
Size increase report for "esp32-example-build" from a83086a
Full report output
|
Size increase report for "nrfconnect-example-build" from a83086a
Full report output
|
@woody-apple |
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.
Having internal flags that's uint16_t, plus another member that's uint16_t, plus another uint8_t seems super wasteful memory structure wise. I really suggest using bits for these, instead of a uint16_t, given it will save space, but also be more reasonable.
We already used bits for those feature flags, BitFlags is manipulating on bit directly. Here is the current allocations: PayloadHeader:
PacketHeader: |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Problem
Current packet header flags in transport are 16 bits and only contains the flags need to be encoded into the packet sent out on the wire.
We need to define more flags associated with a inbound or outbound CHIP message for internal use, such as:
The flag indicates if the peer's group key message counter is not synchronized, this is used by MCSP in secure channel.
The flag indicates if the message buffer should not be freed after sending, this is to tell LwIP stack not free the buffer after sending.
Those flags are used internally and not get encoded to the packet sent over the wire.
Summary of Changes
Define internal message flags in PacketHeader to contain the flags for internal use.