Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/mesh/NextHopRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,16 @@ int32_t NextHopRouter::doRetransmissions()
void NextHopRouter::setNextTx(PendingPacket *pending)
{
assert(iface);
auto d = iface->getRetransmissionMsec(pending->packet);
// Two nodes that NAK each other will otherwise re-collide on near-identical
// schedules; spread successive attempts with exponential backoff plus jitter.
uint32_t base = iface->getRetransmissionMsec(pending->packet);
uint8_t attempt = (NUM_RELIABLE_RETX - 1) - pending->numRetransmissions;
uint8_t shift = attempt < 3 ? attempt : 3; // cap multiplier at 8x
uint32_t backoff = base << shift;
Comment on lines +354 to +357
uint32_t jitter = base ? random(base / 2 + 1) : 0;
uint32_t d = backoff + jitter;
pending->nextTxMsec = millis() + d;
LOG_DEBUG("Setting next retransmission in %u msecs: ", d);
LOG_DEBUG("Setting next retransmission in %u msecs (attempt %u): ", d, attempt);
printPacket("", pending->packet);
setReceivedMessage(); // Run ASAP, so we can figure out our correct sleep time
}
Loading