Allow buffer sharing between mDNS and Matter transport; const-ify constructors #138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The built-in mDNS implementation is adjusted in such a way, that it can share and re-use the RX/TX pair of buffers which are also used by the exchange/Matter transport layer. While not an enormous memory saving (~ 3K), it paves the way for the upcoming changes to the Exchange layer itself, where the existing
PacketBuffers
structure (~ 25K) is gone and everything works with this single RX/TX pair - at least with regards to the exchange layer (Secure Channel won't need extra RX/TX either, the IM layer is another story but still overall a big win).Additional gains:
const
-ify theMatter::new
/Matter::new_default
constructors (thanks toconst
-ifying the mDNS construction itself which required changing a fewHashMap
s toBTreeMap
s)Matter
object and everything in it at compile time, put the result in therodata
section (= flash), and for creation of a "real"Matter
object, just take the raw memory,memcpy
into it theMatter
object initial state fromrodata
and be done with it - no extra temporary memory necessary.const
constructors would allow us to offer users to allocate theMatter
object statically and not put it on stack or in a Box. As instatic MATTER: Matter<'static> = Matter::new(...)
. Still some work here, but we are approaching this status quo.UdpSend
andUdpReceive
traits are renamed toNetworkSend
andNetworkReceive
. They also now take/return our ownAddress
enum rather than aSocketAddr
. Reason: I'm relatively certain we'll be able to re-use them with minor to no changes for modeling the BLE transport and TCP, as from the POV of Matter, these protocols still operate in a packetized manner (i.e. with a 2-bytes len prefix in front of each packet for TCP)NetworkReceive
has an additional method now -wait_available
which is the key for sharing the RX/TX buffers from above. Basically, I'm only async-locking the RX buffer and giving it to either mDNS or Matter transport when the socket below tells us that there is a packet waiting for us in the OS network stack queue - viawait_available
. This method is already implemented for STD/async-io, can be implemented for baremetalembassy-net
/smoltcp
with a small PR I'll contribute to them, and finally, at the price of... an additional RX buffer can be implemented for exotic OSes, though I doubt there would be any that won't natively support it. :)Finally, the changes from above no longer force the user to create the mDNS service separately - as long as the user is not providing their own one to the
Matter
object (MdnsService::Provided(_)
), theMatter
constructor will just construct our pure-Rust one, or the Bonjour one or the Avahi one, depending on the OS.