Skip to content

Commit 4594ae4

Browse files
authored
Upon receiving ACK/reply directly, only update next-hop if we’re the *sole* relayer (#7859)
1 parent f26e657 commit 4594ae4

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

src/mesh/NextHopRouter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
7474
if (p->from != 0) {
7575
meshtastic_NodeInfoLite *origTx = nodeDB->getMeshNode(p->from);
7676
if (origTx) {
77-
// Either relayer of ACK was also a relayer of the packet, or we were the relayer and the ACK came directly from
78-
// the destination
77+
// Either relayer of ACK was also a relayer of the packet, or we were the *only* relayer and the ACK came directly
78+
// from the destination
7979
if (wasRelayer(p->relay_node, p->decoded.request_id, p->to) ||
80-
(wasRelayer(ourRelayID, p->decoded.request_id, p->to) && p->hop_start != 0 && p->hop_start == p->hop_limit)) {
80+
(p->hop_start != 0 && p->hop_start == p->hop_limit &&
81+
wasSoleRelayer(ourRelayID, p->decoded.request_id, p->to))) {
8182
if (origTx->next_hop != p->relay_node) { // Not already set
8283
LOG_INFO("Update next hop of 0x%x to 0x%x based on ACK/reply", p->from, p->relay_node);
8384
origTx->next_hop = p->relay_node;

src/mesh/PacketHistory.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void PacketHistory::insert(const PacketRecord &r)
294294

295295
/* Check if a certain node was a relayer of a packet in the history given an ID and sender
296296
* @return true if node was indeed a relayer, false if not */
297-
bool PacketHistory::wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender)
297+
bool PacketHistory::wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender, bool *wasSole)
298298
{
299299
if (!initOk()) {
300300
LOG_ERROR("PacketHistory - wasRelayer: NOT INITIALIZED!");
@@ -322,27 +322,42 @@ bool PacketHistory::wasRelayer(const uint8_t relayer, const uint32_t id, const N
322322
found->sender, found->id, found->next_hop, millis() - found->rxTimeMsec, found->relayed_by[0], found->relayed_by[1],
323323
found->relayed_by[2], relayer);
324324
#endif
325-
return wasRelayer(relayer, *found);
325+
return wasRelayer(relayer, *found, wasSole);
326326
}
327327

328328
/* Check if a certain node was a relayer of a packet in the history given iterator
329329
* @return true if node was indeed a relayer, false if not */
330-
bool PacketHistory::wasRelayer(const uint8_t relayer, const PacketRecord &r)
330+
bool PacketHistory::wasRelayer(const uint8_t relayer, const PacketRecord &r, bool *wasSole)
331331
{
332-
for (uint8_t i = 0; i < NUM_RELAYERS; i++) {
332+
bool found = false;
333+
bool other_present = false;
334+
335+
for (uint8_t i = 0; i < NUM_RELAYERS; ++i) {
333336
if (r.relayed_by[i] == relayer) {
334-
#if VERBOSE_PACKET_HISTORY
335-
LOG_DEBUG("Packet History - was rel.PR.: s=%08x id=%08x rls=%02x %02x %02x / rl=%02x? YES", r.sender, r.id,
336-
r.relayed_by[0], r.relayed_by[1], r.relayed_by[2], relayer);
337-
#endif
338-
return true;
337+
found = true;
338+
} else if (r.relayed_by[i] != 0) {
339+
other_present = true;
339340
}
340341
}
342+
343+
if (wasSole) {
344+
*wasSole = (found && !other_present);
345+
}
346+
341347
#if VERBOSE_PACKET_HISTORY
342348
LOG_DEBUG("Packet History - was rel.PR.: s=%08x id=%08x rls=%02x %02x %02x / rl=%02x? NO", r.sender, r.id, r.relayed_by[0],
343349
r.relayed_by[1], r.relayed_by[2], relayer);
344350
#endif
345-
return false;
351+
352+
return found;
353+
}
354+
355+
// Check if a certain node was the *only* relayer of a packet in the history given an ID and sender
356+
bool PacketHistory::wasSoleRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender)
357+
{
358+
bool wasSole = false;
359+
wasRelayer(relayer, id, sender, &wasSole);
360+
return wasSole;
346361
}
347362

348363
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender

src/mesh/PacketHistory.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class PacketHistory
3434
void insert(const PacketRecord &r); // Insert or replace a packet record in the history
3535

3636
/* Check if a certain node was a relayer of a packet in the history given iterator
37+
* If wasSole is not nullptr, it will be set to true if the relayer was the only relayer of that packet
3738
* @return true if node was indeed a relayer, false if not */
38-
bool wasRelayer(const uint8_t relayer, const PacketRecord &r);
39+
bool wasRelayer(const uint8_t relayer, const PacketRecord &r, bool *wasSole = nullptr);
3940

4041
PacketHistory(const PacketHistory &); // non construction-copyable
4142
PacketHistory &operator=(const PacketHistory &); // non copyable
@@ -54,8 +55,12 @@ class PacketHistory
5455
bool *weWereNextHop = nullptr);
5556

5657
/* Check if a certain node was a relayer of a packet in the history given an ID and sender
58+
* If wasSole is not nullptr, it will be set to true if the relayer was the only relayer of that packet
5759
* @return true if node was indeed a relayer, false if not */
58-
bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);
60+
bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender, bool *wasSole = nullptr);
61+
62+
// Check if a certain node was the *only* relayer of a packet in the history given an ID and sender
63+
bool wasSoleRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);
5964

6065
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender
6166
void removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);

0 commit comments

Comments
 (0)