Skip to content

Commit

Permalink
app/dynamic_node_id: avoid spurious reallocation
Browse files Browse the repository at this point in the history
Don't set a None unique ID in the DNA database for a node ID if the node
goes offline or if its unique ID is not available yet. This prevents the
node being allocated another ID while still allowing the node ID to be
reserved if a unique ID will never be available.
  • Loading branch information
tpwrules committed Nov 12, 2024
1 parent 44c6cdf commit 4449bc1
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 @@ -117,8 +117,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 4449bc1

Please sign in to comment.