Mask out random bits when doing queue ordering (#4561)

* Mask out random bits when doing queue ordering

* Parenthesis
pull/4562/head^2
Jonathan Bennett 2024-08-26 15:48:47 -05:00 zatwierdzone przez GitHub
rodzic 5824a8f4c1
commit b9a8683a4b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 8 dodań i 6 usunięć

Wyświetl plik

@ -20,8 +20,9 @@ bool CompareMeshPacketFunc(const meshtastic_MeshPacket *p1, const meshtastic_Mes
// If priorities differ, use that
// for equal priorities, order by id (older packets have higher priority - this will briefly be wrong when IDs roll over but
// no big deal)
return (p1p != p2p) ? (p1p < p2p) // prefer bigger priorities
: (p1->id >= p2->id); // prefer smaller packet ids
return (p1p != p2p)
? (p1p < p2p) // prefer bigger priorities
: ((p1->id & ID_COUNTER_MASK) >= (p2->id & ID_COUNTER_MASK)); // Mask to counter portion, prefer smaller packet ids
}
MeshPacketQueue::MeshPacketQueue(size_t _maxLen) : maxLen(_maxLen) {}

Wyświetl plik

@ -16,6 +16,7 @@ typedef uint32_t PacketId; // A packet sequence number
#define ERRNO_NO_INTERFACES 33
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
#define ERRNO_DISABLED 34 // the interface is disabled
#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID
/*
* Source of a received message

Wyświetl plik

@ -109,7 +109,7 @@ PacketId generatePacketId()
rollingPacketId++;
rollingPacketId &= UINT32_MAX >> 22; // Mask out the top 22 bits
rollingPacketId &= ID_COUNTER_MASK; // Mask out the top 22 bits
PacketId id = rollingPacketId | random(UINT32_MAX & 0x7fffffff) << 10; // top 22 bits
LOG_DEBUG("Partially randomized packet id %u\n", id);
return id;