project-chip / rs-matter

Rust implementation of the Matter protocol. Status: Experimental
Apache License 2.0
323 stars 45 forks source link

Remove duplicate state from system clusters #197

Closed ivmarkov closed 3 months ago

ivmarkov commented 3 months ago

( This is a mechanical change that I had to apply laboriously everywhere, hence the large number of changed files. But otherwise, no big semantic changes. )

What

Currently, a lot of the system clusters contain state, in the form of various Matter objects that are borrowed upon the system cluster creation. For example:

The culprit for me is the NOC cluster, which contains a ton of data.

Moreover, I would argue that caching this data in the cluster is even incorrect! What happens if the user has created the cluster on one Matter instance, but then erroneously uses the cluster for another Matter instance? Havoc.

(This problem by the way was fixed in the Pase / Case SC handlers with the transport rework, but I did not touch the DM clusters back then.)

Scope of changes

The changes are completely mechanical and should NOT introduce any semantic changes:

What is NOT part of the changes

Why now?

  1. Our handling of commissioning completion is currently wrong. We need to register the new Fabric ONLY when we get CommissioningComplete and not before that. Currently, we do it on AddNoc and that's not OK. The C++ SDK does it properly

  2. To fix (1) from above, without introducing even more temporary space on the program stack I need to rework a bit how fabrics are handled - in that each fabric needs to have a pending/non-commissioned flag. This would also allow me to get rid of the NocData thing which is a looping 400 bytes and is stored in each session. If I do this, ideally I need to merge the ACLs which are per-fabric really into the Fabric object (tracking them in the AclMgr is simply not convenient - for the same reasons why having separate sessions from exchanges was not convenient and now all exchanges for a session are aggregated within its corresponding Session struct)

... but then (2) means I had to introduce even more cached state to the NOC and General Commissioning handlers, hence this PR to just stop this.