mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-23 22:32:29 +00:00
refactor(message_handler): DMs read SNR and RSSI through _message_signal
handle_contact_message's copy of the payload/metadata/signal-cache lookup becomes a _message_signal call with its own SNR keys (it also accepts signal_to_noise and signal_noise_ratio), so DMs and channel messages share one implementation. The helper loses a comment that only made sense inline. A DM replay (1,500 corpus packets as RF rows, 1,500 DMs with varied SNR/RSSI key layouts, metadata, cached signal values keyed by pubkey prefix, with and without radio contacts) gives byte-identical processed messages and logger calls; passing the channel keys instead changes them. The channel replay is unchanged.
This commit is contained in:
1 parent
80d80c52dd
commit
ef255cd689
2 files changed
+3
-23
No files matched your search
@@ -78,7 +78,6 @@ class ChannelMessageMixin:
|
||||
self, payload: dict[str, Any], metadata: dict[str, Any] | None, snr_payload_keys: tuple[str, ...]
|
||||
) -> tuple[float | None, int | None]:
|
||||
"""A message's SNR and RSSI from its payload or metadata, else the signal cache by pubkey prefix."""
|
||||
# Get SNR and RSSI using the same logic as contact messages
|
||||
snr: float | None = None
|
||||
rssi: int | None = None
|
||||
|
||||
|
||||
@@ -283,28 +283,9 @@ class MessageHandler(MeshGraphRecorderMixin, ContactEventsMixin, RfCorrelationMi
|
||||
self._log_dm_routing_from_rf(message_pubkey)
|
||||
|
||||
# Get additional metadata - try multiple sources for SNR and RSSI
|
||||
snr: float | None = None
|
||||
rssi: int | None = None
|
||||
|
||||
# Try to get SNR from payload first - check multiple possible field names
|
||||
snr = _signal_value(payload, metadata, ("SNR", "snr", "signal_to_noise", "signal_noise_ratio"), ("snr", "SNR"), float)
|
||||
|
||||
# If still no SNR, try to get it from the cache using pubkey prefix from payload
|
||||
if snr is None:
|
||||
pubkey_prefix = payload.get("pubkey_prefix", "")
|
||||
if pubkey_prefix and pubkey_prefix in self.snr_cache:
|
||||
snr = self.snr_cache[pubkey_prefix]
|
||||
self.logger.debug(f"Retrieved cached SNR {snr} for pubkey {pubkey_prefix}")
|
||||
|
||||
# Try to get RSSI from payload first
|
||||
rssi = _signal_value(payload, metadata, ("RSSI", "rssi", "signal_strength"), ("rssi", "RSSI"), int)
|
||||
|
||||
# If still no RSSI, try to get it from the cache using pubkey prefix from payload
|
||||
if rssi is None:
|
||||
pubkey_prefix = payload.get("pubkey_prefix", "")
|
||||
if pubkey_prefix and pubkey_prefix in self.rssi_cache:
|
||||
rssi = int(self.rssi_cache[pubkey_prefix])
|
||||
self.logger.debug(f"Retrieved cached RSSI {rssi} for pubkey {pubkey_prefix}")
|
||||
snr, rssi = self._message_signal(
|
||||
payload, metadata, ("SNR", "snr", "signal_to_noise", "signal_noise_ratio")
|
||||
)
|
||||
|
||||
# For DMs, we can't decode the encrypted packet, but we can get SNR/RSSI from the payload
|
||||
# For channel messages, we can decode the packet since they use shared keys
|
||||
|
||||
Reference in new issue
Block a user