Skip to content

Drop echoes of own datagrams to a peer that shares our hash - #3867

Open
marcelverdult wants to merge 1 commit into
meshcore-dev:devfrom
marcelverdult:fix/dm-own-echo
Open

marcelverdult wants to merge 1 commit into
meshcore-dev:devfrom
marcelverdult:fix/dm-own-echo

Conversation

@marcelverdult

Copy link
Copy Markdown
Contributor

Peer datagrams (TXT_MSG, REQ, RESPONSE, PATH) carry a 1-byte dest_hash and
src_hash. When a contact's public key starts with the same byte as ours, a
repeater echo of our own DM to that contact looks like a DM from that
contact: dest_hash matches self_id, searchPeersByHash(src_hash) finds the
contact, and the ECDH secret is the same in both directions, so the MAC is
valid. onPeerDataRecv() then shows our own text as a message from the
contact and sends an ACK plus a path return.

The seen table normally catches the echo, since sendFlood()/sendDirect()
mark the packet as seen. That table is a ring of MAX_PACKET_HASHES (160)
entries that every received packet also writes to, so on a busy mesh a late
echo can arrive after our entry was evicted. A user reported exactly this
symptom: a DM to a contact out of range came back as a "reply" from that
contact, and both keys start with the same byte.

This change adds a second ring of 8 packet hashes to Mesh. send*() writes
to it only for peer datagrams whose dest_hash equals our own hash, which
only happens when we share a prefix with the destination. On receive, a
datagram with dest_hash == src_hash == our hash whose hash is in that ring
is dropped like a seen packet: no decrypt, no ACK, no forward. A real DM
from that contact has different content and a different hash, so it is
delivered as before. The wire format is unchanged. RAM cost is 65 bytes,
and MAX_SELF_ADDRESSED_SENT can be overridden at build time.

Tested: builds for RAK_4631_companion_radio_ble and
Heltec_v3_companion_radio_ble. A local host test (not part of this PR) with
two BaseChatMesh nodes sharing a key prefix fails without the change (own
DM delivered as from the contact, one TX) and passes with it; a genuine DM
from the same-prefix contact is still delivered once.

Open PRs #3523, #3839, #3521 and #3473 also edit the datagram branch of
Mesh::onRecvPacket(), so a rebase may be needed depending on merge order.

@fdlamotte

Peer datagrams (TXT_MSG, REQ, RESPONSE, PATH) carry a 1-byte dest_hash and
src_hash. If a contact's public key starts with the same byte as ours, a
repeater echo of our own datagram to that contact matches self_id as
destination, searchPeersByHash(src_hash) finds the contact, and the shared
secret is symmetric, so the MAC checks out. onPeerDataRecv() then reports our
own message as received from the contact and sends an ACK and a path return.

The only guard today is the seen table, which is a ring of MAX_PACKET_HASHES
entries shared with all received traffic. On a busy mesh the entry for our
packet can be evicted before a late echo arrives.

Keep a small separate ring of hashes of sent datagrams whose dest_hash equals
our own hash. Normal traffic does not write to it, so these entries are not
evicted by it. An incoming datagram with dest_hash == src_hash == our hash
whose hash is in that ring is handled like a seen packet: not processed and
not forwarded. Genuine datagrams from that contact differ in content and hash
and are delivered as before. No wire format change.

This branch has not been deployed

No deployments
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.

1 participant