Skip to content

Commit

Permalink
app/dynamic_node_id: avoid spurious reallocation
Browse files Browse the repository at this point in the history
Only set a None unique ID in the DNA database if there's no existing
unique ID for the node ID and the node's unique ID is not available.
This prevents erasing an existing allocation and causing the node to be
allocated another ID, while still allowing the node ID to be reserved if
a unique ID never becomes available.
  • Loading branch information
tpwrules authored and tridge committed Nov 13, 2024
1 parent 6805cf0 commit 19ac176
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dronecan/app/dynamic_node_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,16 @@ def get_allocation_table(self):
return self._allocation_table.get_entries()

def _handle_monitor_event(self, event):
if event.event_id not in (event.EVENT_ID_NEW, event.EVENT_ID_INFO_UPDATE):
return # don't care about nodes going offline or other such things
# unique ID might not be available if we see a node not participating in
# DNA and haven't got it or it didn't share that
unique_id = event.entry.info.hardware_version.unique_id.to_bytes() if event.entry.info else None
self._allocation_table.set(unique_id, event.entry.node_id)
# set unique ID for this node ID (possibly to None in case we never get
# one) if we don't have one yet (though maybe we should raise a
# conflict if we do)
if self._allocation_table.get_unique_id(event.entry.node_id) is None:
self._allocation_table.set(unique_id, event.entry.node_id)

def close(self):
"""Stops the instance and closes the allocation table storage.
Expand Down

0 comments on commit 19ac176

Please sign in to comment.