mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
G7: M03+M05+M07 — cleanup: TypeError guard, dead code removal, None normalization
Why: Three minor cleanup fixes. M03 adds an else branch in set_flood_scope so unsupported scope types raise TypeError instead of UnboundLocalError. M05 removes the dead `out_path_len >> 6` shift in update_contact (high bits always zero due to reader masking) and initializes path_hash_mode=0 explicitly. M07 normalizes three `return None` paths in get_contacts to return Event(EventType.ERROR, ...) so callers can rely on the return type always being Event. Refs: Forensics report findings M03, M05, M07
This commit is contained in:
parent
4204bf090c
commit
aed7db21b3
2 changed files with 14 additions and 6 deletions
|
|
@ -43,13 +43,17 @@ class ContactCommands(CommandHandlerBase):
|
|||
logger.debug("Timeout while getting contacts")
|
||||
for future in pending: # cancel all futures
|
||||
future.cancel()
|
||||
return None
|
||||
return Event(EventType.ERROR, {"reason": "timeout waiting for contacts"})
|
||||
|
||||
for future in done:
|
||||
event = await future
|
||||
if event is None or event.type != EventType.NEXT_CONTACT:
|
||||
for future in pending:
|
||||
future.cancel()
|
||||
if event is None:
|
||||
for f in pending:
|
||||
f.cancel()
|
||||
return Event(EventType.ERROR, {"reason": "no event received during contacts retrieval"})
|
||||
if event.type != EventType.NEXT_CONTACT:
|
||||
for f in pending:
|
||||
f.cancel()
|
||||
return event
|
||||
|
||||
futures = []
|
||||
|
|
@ -64,7 +68,7 @@ class ContactCommands(CommandHandlerBase):
|
|||
|
||||
except asyncio.TimeoutError:
|
||||
logger.debug(f"Timeout receiving contacts")
|
||||
return None
|
||||
return Event(EventType.ERROR, {"reason": "asyncio timeout receiving contacts"})
|
||||
except Exception as e:
|
||||
logger.debug(f"Command error: {e}")
|
||||
return Event(EventType.ERROR, {"error": str(e)})
|
||||
|
|
@ -116,7 +120,9 @@ class ContactCommands(CommandHandlerBase):
|
|||
path_hash_mode = int(path.split(":")[1])
|
||||
path = path.split(":")[0].replace(":","")
|
||||
else: # use device one by default
|
||||
path_hash_mode = contact["out_path_len"] >> 6 # would fallback to previous val
|
||||
# out_path_len is pre-masked (& 0x3F) in reader.py, so high bits are always 0;
|
||||
# the actual path_hash_mode is fetched from the device query below.
|
||||
path_hash_mode = 0
|
||||
res = await self.send_device_query()
|
||||
if not res is None and res.type != EventType.ERROR:
|
||||
if "path_hash_mode" in res.payload:
|
||||
|
|
|
|||
|
|
@ -313,6 +313,8 @@ class MessagingCommands(CommandHandlerBase):
|
|||
elif isinstance (scope, bytes): # scope has been sent directly as byte
|
||||
logger.debug(f"Directly setting scope to {scope}")
|
||||
scope_key = scope
|
||||
else:
|
||||
raise TypeError(f"set_flood_scope: unsupported scope type {type(scope).__name__}")
|
||||
|
||||
logger.debug(f"Setting scope to {scope_key.hex()}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue