From 6da7e90e5d3d5db013d8958332561a415c9d837d Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Sat, 17 Jan 2026 15:29:05 -0500 Subject: [PATCH] docs: document collision risk for 16-char hex identity keys Expand _compute_identity_hash docstring to explain: - Uses truncated 64-bit keys for spawned_interfaces and identity_to_address - Birthday collision risk at ~2^32 (~4 billion) identities - Astronomically safe for BLE mesh networks with <100 peers - Note that fragmenter keys use full 32-char hex for packet reassembly Co-Authored-By: Claude Opus 4.5 --- src/ble_reticulum/BLEInterface.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ble_reticulum/BLEInterface.py b/src/ble_reticulum/BLEInterface.py index c361353..ca9e576 100644 --- a/src/ble_reticulum/BLEInterface.py +++ b/src/ble_reticulum/BLEInterface.py @@ -1779,11 +1779,18 @@ class BLEInterface(Interface): """ Convert 16-byte identity to 16-character hex string for interface tracking. + Uses truncated 64-bit hash for map keys (spawned_interfaces, identity_to_address). + Collision risk: birthday problem collision at ~2^32 (~4 billion) identities. + For BLE mesh networks with <100 simultaneous peers, this is astronomically safe. + + Note: Fragmenter keys use full 32-char hex via _get_fragmenter_key() for + maximum precision in packet reassembly. + Args: peer_identity: 16-byte peer identity (already a hash from BLE handshake) Returns: - str: First 16 hex chars of identity (8 bytes) + str: First 16 hex chars of identity (8 bytes = 64 bits) """ # peer_identity is already the identity hash from BLE handshake # Just convert to hex, don't re-hash (that would corrupt the identity!)