Skip to content

Refactor RX Log architecture: Unified handler eliminates Session Log duplicates#123

Merged
MrAlders0n merged 4 commits intodevfrom
copilot/add-passive-rx-log-listener
Dec 22, 2025
Merged

Refactor RX Log architecture: Unified handler eliminates Session Log duplicates#123
MrAlders0n merged 4 commits intodevfrom
copilot/add-passive-rx-log-listener

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

RX Log was tracking all incoming messages including echoes of the user's own pings from #wardriving channel, causing duplicate entries between Session Log and RX Log.

Architecture Refactoring

Refactored from a two-handler architecture to a unified single-handler architecture where Session Log taps into the unified RX handler via clean delegation pattern.

Previous Design

  • Two separate event handlers (handleRxLogEvent and handlePassiveRxLogEvent)
  • Coupling via shared state (isListening flag)
  • Redundant packet parsing (2× per event)

New Design

  • Single unified handler (handleUnifiedRxLogEvent) processes all RX events
  • Session Log delegates to handleSessionLogTracking() when tracking active
  • Passive RX delegates to handlePassiveRxLogging() for non-echoes
  • Packet parsed once per event

Changes

  • handleUnifiedRxLogEvent(): Single entry point for all RX events

    • Parses packet once
    • Delegates to Session Log when state.repeaterTracking.isListening = true
    • Delegates to Passive RX for all other messages
  • handleSessionLogTracking(): Session Log echo tracking (renamed from handleRxLogEvent)

    • Called by unified handler during 7-second tracking window
    • Decrypts and verifies echoes
    • Returns boolean indicating if echo was tracked
  • handlePassiveRxLogging(): Passive RX logging (extracted from handlePassiveRxLogEvent)

    • Called by unified handler for non-echo messages
    • Logs observations to RX Log
  • Registration changes:

    • startUnifiedRxListening(): Registers single handler at connect
    • startRepeaterTracking(): Now just sets flag (no separate handler registration)
  • Disconnect cleanup: Clear rxLogState.entries on disconnect

  • Settings panel: Add hidden class for correct initial state

Implementation

// Unified RX handler delegates based on tracking state
async function handleUnifiedRxLogEvent(data) {
  const packet = Packet.fromBytes(data.raw); // Parse once
  
  // Delegate to Session Log if tracking
  if (state.repeaterTracking.isListening) {
    const wasTracked = await handleSessionLogTracking(packet, data);
    if (wasTracked) return; // Echo handled
  }
  
  // Delegate to Passive RX for non-echoes
  await handlePassiveRxLogging(packet, data);
}

Result

Message Type Session Log RX Log Packet Parsing Decryption Count
User's ping echoes ✅ Tracked ⊘ Filtered 1× (unified) 1× (Session only)
Other users' pings ✅ Logged 1× (unified)
Other channels ✅ Logged 1× (unified)

Performance & Architecture Benefits

  • Single packet parse: Parse packet once instead of twice (50% reduction)
  • No double decryption: Session Log handles echoes, Passive RX never needs to decrypt
  • Clean delegation: Session Log taps into unified handler, no coupling via flags
  • Single handler registration: One handler for all RX events instead of two
  • Easier to maintain: Clear delegation pattern, simpler code flow

Edge cases handled: missing GPS fix, direct transmission without repeater path.

Original prompt

Problem

Currently, the RX Log and Session Log overlap. When a user sends a ping:

  1. The Session Log correctly records the ping sent and the repeaters that echoed it
  2. However, echoes of the user's own ping are also being tracked, causing duplicate entries

The user wants the RX Log to be a passive listener that tracks all incoming messages on the mesh, but specifically excludes echoes of pings that the user sent.

Expected Behavior

  1. Session Log: Records pings the user sends + the repeaters that echoed their ping (no changes needed)
  2. RX Log (Passive): Records ALL incoming messages EXCEPT echoes of the user's own pings

Example:

  • User sends a ping → Session Log records it with repeater 0C that echoed it
  • User hears RX from 1A (unrelated to their ping) → RX Log tracks it
  • User's ping echoed by 0C → Should NOT appear in RX Log (already in Session Log)

Implementation Requirements

  1. Add a passive RX Log listener in content/wardrive.js that:

    • Listens to ALL LogRxData events continuously while connected (not just during the 7-second ping window)
    • Runs independently from the existing handleRxLogEvent which handles Session Log repeater tracking
  2. Filter logic for the passive RX listener:

    • For messages on the #wardriving channel (channel hash match with WARDRIVING_CHANNEL_HASH):
      • Decrypt the message using WARDRIVING_CHANNEL_KEY
      • Check if the decrypted content matches any recently-sent ping payload (stored in state.repeaterTracking.sentPayload or a similar mechanism)
      • If it matches → skip (this is an echo of our own ping, already tracked in Session Log)
      • If it doesn't match → log it to the RX Log (this is someone else's message on the channel)
    • For messages on other channels or message types: log them to the RX Log
  3. Add RX Log UI section in index.html:

    • Add a new collapsible section similar to the Session Log
    • Display RX Log entries with timestamp, signal info (SNR/RSSI), and message details where available
  4. RX Log state management:

    • Track recent sent payloads to compare against (may need to keep a short history if pings can overlap)
    • Clear RX Log on disconnect
    • Manage RX Log entries array similar to sessionLogState

Files to Modify

  • content/wardrive.js: Add passive RX listener, filtering logic, and RX Log state management
  • index.html: Add RX Log UI section
  • content/style.css: Add any necessary styles for RX Log entries (may reuse existing log entry styles)

Technical Notes

  • The existing handleRxLogEvent function should remain unchanged for Session Log functionality
  • The passive listener should be registered on connect and unregistered on disconnect
  • Use the pre-computed WARDRIVING_CHANNEL_HASH and WARDRIVING_CHANNEL_KEY for filtering
  • The passive listener should NOT be affected by the 7-second ping window - it runs continuously

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Add passive RX Log listener to exclude user's echoed pings Filter own ping echoes from RX Log to eliminate Session Log duplicates Dec 22, 2025
Copilot AI requested a review from MrAlders0n December 22, 2025 04:39
@MrAlders0n
Copy link
Collaborator

@copilot Can you confirm if you're now decrypting the events twice? Is there a better way to fo it if thats the case

… double decryption

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 22, 2025

@copilot Can you confirm if you're now decrypting the events twice? Is there a better way to fo it if thats the case

You're correct - there was double decryption happening. Both handlers (Session Log and Passive RX) were decrypting the same packets during the 7-second echo window.

Fixed in commit 3709f82 by having Passive RX skip entirely when state.repeaterTracking.isListening = true. This eliminates the double decryption and simplifies the logic - no need to decrypt and compare payloads anymore since all messages during the tracking window are echoes anyway.

Result: 50% reduction in crypto operations (2 decryptions instead of 4 for a typical ping with 2 repeaters).

@MrAlders0n
Copy link
Collaborator

@copilot Wait revert this and lets think about this more. If the RX is received at the exact same time, both will be decrpyting at the same time so it woul never skip. Unless I am wrong wouldnt it make more sense to have Session log handler just tap into the passive RX handler?

Copy link
Contributor Author

Copilot AI commented Dec 22, 2025

@copilot Wait revert this and lets think about this more. If the RX is received at the exact same time, both will be decrpyting at the same time so it woul never skip. Unless I am wrong wouldnt it mak...

Good catch on the architectural concern. However, JavaScript's single-threaded event loop means handlers run sequentially, not simultaneously. When an echo arrives:

  1. isListening is already true (set before ping is sent at line 2663)
  2. Both handlers are called sequentially (not parallel)
  3. Passive RX checks isListening and skips

So there's no race condition. But I agree the architecture could be cleaner - having Session Log tap into Passive RX would avoid having two separate handlers.

Would you like me to refactor to have a single RX handler with conditional logic for Session Log tracking? That would be a bigger change but architecturally cleaner.

@MrAlders0n
Copy link
Collaborator

@copilot Lets do the bigger change to keep the architecture cleaner

…gle handler

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 22, 2025

@copilot Lets do the bigger change to keep the architecture cleaner

Refactored in commit 8235c4a to use a single unified RX handler architecture.

Architecture changes:

  • Single handleUnifiedRxLogEvent() processes all RX events (registered once at connect)
  • When tracking active: delegates to handleSessionLogTracking()
  • For non-echoes: delegates to handlePassiveRxLogging()
  • Session Log now taps into unified handler via delegation pattern

Benefits:

  • ✅ No coupling via shared state flags
  • ✅ Parse packet once (was 2×)
  • ✅ Cleaner code organization
  • ✅ Same functionality as before

Copilot AI changed the title Filter own ping echoes from RX Log to eliminate Session Log duplicates Refactor RX Log architecture: Unified handler eliminates Session Log duplicates Dec 22, 2025
@MrAlders0n MrAlders0n marked this pull request as ready for review December 22, 2025 05:00
@MrAlders0n MrAlders0n merged commit 103bf10 into dev Dec 22, 2025
@MrAlders0n MrAlders0n deleted the copilot/add-passive-rx-log-listener branch December 22, 2025 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants