Skip to content

Commit

Permalink
Fewer prints. Ignore unknown sessions and failure to decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Oct 16, 2024
1 parent 6b9090e commit db186e6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
17 changes: 11 additions & 6 deletions circuitmatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,18 @@ def process_packet(self, address, data):
message.decode(data)
message.source_ipaddress = address
if message.secure_session:
secure_session_context = None
if message.session_id < len(self.manager.secure_session_contexts):
secure_session_context = self.manager.secure_session_contexts[
message.session_id
]
if secure_session_context is None:
print("Failed to find session. Ignoring.")
return
# Decrypt the payload
secure_session_context = self.manager.secure_session_contexts[
message.session_id
]
ok = secure_session_context.decrypt_and_verify(message)
if not ok:
raise RuntimeError("Failed to decrypt message")
if not secure_session_context.decrypt_and_verify(message):
print("Failed to decrypt message. Ignoring.")
return
message.parse_protocol_header()
self.manager.mark_duplicate(message)

Expand Down
2 changes: 1 addition & 1 deletion circuitmatter/clusters/general/on_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class StartUpOnOffEnum(data_model.Enum8):
class OnOff(data_model.Cluster):
CLUSTER_ID = 0x0006

OnOff = data_model.BoolAttribute(0x0000, default=False)
OnOff = data_model.BoolAttribute(0x0000, default=False, N_nonvolatile=True)
GlobalSceneControl = data_model.BoolAttribute(0x4000, default=True)
OnTime = data_model.NumberAttribute(0x4001, signed=False, bits=16, default=0)
OffWaitTime = data_model.NumberAttribute(0x4002, signed=False, bits=16, default=0)
Expand Down
1 change: 0 additions & 1 deletion circuitmatter/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def restore(self, nonvolatile):
nonvolatile[ATTRIBUTES_KEY] = {}
for field_name, descriptor in self._attributes():
if descriptor.nonvolatile:
print(field_name, nonvolatile[ATTRIBUTES_KEY])
if hex(descriptor.id) in nonvolatile[ATTRIBUTES_KEY]:
# Update our live value
self._attribute_values[descriptor.id] = descriptor.from_json(
Expand Down
2 changes: 0 additions & 2 deletions circuitmatter/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ def receive(self, message) -> bool:
):
# Drop messages that have the wrong acknowledgement counter.
return True
print("acknowledged", message.acknowledged_message_counter)
self.pending_retransmission = None
self.next_retransmission_time = None

if message.protocol_id not in self.protocols:
print("protocol mismatch")
# Drop messages that don't match the protocols we're waiting for.
return True

Expand Down
12 changes: 2 additions & 10 deletions circuitmatter/nonvolatile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def __init__(self, filename=None, root=None, state=None):
self.persisted = {}
self._state: dict
if self.root is None and filename:
self.rollback()
with open(self.filename, "r") as state_file:
self._state = json.load(state_file)
elif state is not None:
self._state = state
else:
Expand Down Expand Up @@ -51,19 +52,10 @@ def __iter__(self):

def commit(self):
if not self.dirty:
print("not dirty")
return
if self.root:
print("root commit")
self.root.commit()
return
print("commit")
print(self._state)
with open(self.filename, "w") as state_file:
json.dump(self._state, state_file, indent=1)
self.dirty = False

def rollback(self):
print("rollback")
with open(self.filename, "r") as state_file:
self._state = json.load(state_file)

0 comments on commit db186e6

Please sign in to comment.