an optimization for #681 - make want_ack packets higher priority

pull/684/head
Kevin Hester 2021-02-12 09:40:20 +08:00
rodzic bc8453283f
commit f2b7ff2b79
3 zmienionych plików z 17 dodań i 6 usunięć

2
proto

@ -1 +1 @@
Subproject commit 0221e83d689f7930ed3e5c474eff4fbb8697efbb
Subproject commit b1aed06442025624841b2288fac273d9bc41c438

Wyświetl plik

@ -20,19 +20,29 @@ bool CompareMeshPacket::operator()(MeshPacket *p1, MeshPacket *p2)
: (p1->id >= p2->id); // prefer smaller packet ids
}
MeshPacketQueue::MeshPacketQueue(size_t _maxLen) : maxLen(_maxLen)
MeshPacketQueue::MeshPacketQueue(size_t _maxLen) : maxLen(_maxLen) {}
/** Some clients might not properly set priority, therefore we fix it here.
*/
void fixPriority(MeshPacket *p)
{
// We might receive acks from other nodes (and since generated remotely, they won't have priority assigned. Check for that
// and fix it
if (p->priority == MeshPacket_Priority_UNSET) {
// if acks give high priority
// if a reliable message give a bit higher default priority
p->priority = p->decoded.which_ackVariant ? MeshPacket_Priority_ACK :
(p->want_ack ? MeshPacket_Priority_RELIABLE : MeshPacket_Priority_DEFAULT);
}
}
/** enqueue a packet, return false if full */
bool MeshPacketQueue::enqueue(MeshPacket *p)
{
// We might receive acks from other nodes (and since generated remotely, they won't have priority assigned. Check for that
// and fix it
if (p->priority == MeshPacket_Priority_UNSET)
p->priority = p->decoded.which_ackVariant ? MeshPacket_Priority_ACK : MeshPacket_Priority_DEFAULT;
fixPriority(p);
// fixme if there is something lower priority in the queue that can be deleted to make space, delete that instead
if (size() >= maxLen)
return false;
else {

Wyświetl plik

@ -88,6 +88,7 @@ typedef enum _MeshPacket_Priority {
MeshPacket_Priority_MIN = 1,
MeshPacket_Priority_BACKGROUND = 10,
MeshPacket_Priority_DEFAULT = 64,
MeshPacket_Priority_RELIABLE = 70,
MeshPacket_Priority_ACK = 120,
MeshPacket_Priority_MAX = 127
} MeshPacket_Priority;