Skip to content

Commit

Permalink
Add airtime of current received/transmitted packet to nextTx time of …
Browse files Browse the repository at this point in the history
…all pending retransmissions (#2309)

To avoid unnecessary retransmissions when sending them too early

Co-authored-by: Ben Meadors <[email protected]>
  • Loading branch information
GUVWAF and thebentern authored Feb 26, 2023
1 parent c9ae90f commit 408c555
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ uint32_t RadioInterface::getPacketTime(uint32_t pl)
return msecs;
}

uint32_t RadioInterface::getPacketTime(meshtastic_MeshPacket *p)
uint32_t RadioInterface::getPacketTime(const meshtastic_MeshPacket *p)
{
uint32_t pl = 0;
if (p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag) {
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/RadioInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class RadioInterface
*
* @return num msecs for the packet
*/
uint32_t getPacketTime(meshtastic_MeshPacket *p);
uint32_t getPacketTime(const meshtastic_MeshPacket *p);
uint32_t getPacketTime(uint32_t totalPacketLen);

/**
Expand Down
18 changes: 18 additions & 0 deletions src/mesh/ReliableRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ ErrorCode ReliableRouter::send(meshtastic_MeshPacket *p)
startRetransmission(copy);
}

/* If we have pending retransmissions, add the airtime of this packet to it, because during that time we cannot receive an
(implicit) ACK. Otherwise, we might retransmit too early.
*/
for (auto i = pending.begin(); i != pending.end(); i++) {
if (i->first.id != p->id) {
i->second.nextTxMsec += iface->getPacketTime(p);
}
}

return FloodingRouter::send(p);
}

Expand Down Expand Up @@ -53,6 +62,15 @@ bool ReliableRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
}
}

/* At this point we have already deleted the pending retransmission if this packet was an (implicit) ACK to it.
Now for all other pending retransmissions, we have to add the airtime of this received packet to the retransmission timer,
because while receiving this packet, we could not have received an (implicit) ACK for it.
If we don't add this, we will likely retransmit too early.
*/
for (auto i = pending.begin(); i != pending.end(); i++) {
i->second.nextTxMsec += iface->getPacketTime(p);
}

/* Resend implicit ACKs for repeated packets (assuming the original packet was sent with HOP_RELIABLE)
* this way if an implicit ACK is dropped and a packet is resent we'll rebroadcast again.
* Resending real ACKs is omitted, as you might receive a packet multiple times due to flooding and
Expand Down

0 comments on commit 408c555

Please sign in to comment.