Skip to content

bug: zero-hop detection reads the path byte at the wrong offset for transport-direct adverts #2225

Closed

Description

@efiten

Split off from #2190, where it was deferred to its own PR.

Problem

nodeZeroHopRegionCounts (cmd/server/store.go, at the head of #2190) decides that a direct ADVERT is zero-hop by reading the path byte at RawHex[2:4]. It does this for both ROUTE_TYPE_DIRECT and ROUTE_TYPE_TRANSPORT_DIRECT.

For the transport route types the packet carries 4 bytes of transport codes between the header and the path length. The format is [header][transport_codes(optional)][path_length][path][payload], with transport codes present only for ROUTE_TYPE_TRANSPORT_FLOOD and ROUTE_TYPE_TRANSPORT_DIRECT (firmware docs/packet_format.md). So for ROUTE_TYPE_TRANSPORT_DIRECT, RawHex[2:4] is the first byte of transport_code_1, not path_length.

The comment above that read says it matches the analytics decoder. It does not: the analytics code in the same file uses pbOffset = 5 for both transport route types.

Effect

A transport-direct zero-hop advert counts as zero-hop only when the low 6 bits of its first transport-code byte happen to be 0.

Fix

  • Use the same offset rule as the analytics decoder: path byte at offset 5 for route types 0 and 3, offset 1 otherwise. Ideally this becomes one shared helper used by both.
  • Add a test with a transport-direct zero-hop advert whose first transport-code byte is non-zero.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: nodesNodes directory pagepriority: minorNice to fix — polish and consistencytype: bugSomething is broken

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions