Set high priority for text messages (#4592)

This commit is contained in:
GUVWAF 2024-08-30 21:54:44 +02:00 committed by GitHub
parent 8144dcbc25
commit eb071ec80d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View File

@ -40,19 +40,22 @@ void fixPriority(meshtastic_MeshPacket *p)
// We might receive acks from other nodes (and since generated remotely, they won't have priority assigned. Check for that // We might receive acks from other nodes (and since generated remotely, they won't have priority assigned. Check for that
// and fix it // and fix it
if (p->priority == meshtastic_MeshPacket_Priority_UNSET) { if (p->priority == meshtastic_MeshPacket_Priority_UNSET) {
// if acks give high priority
// if a reliable message give a bit higher default priority // if a reliable message give a bit higher default priority
p->priority = (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP) p->priority = (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT);
? meshtastic_MeshPacket_Priority_ACK if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
: (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT); // if acks/naks give very high priority
if (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP)
p->priority = meshtastic_MeshPacket_Priority_ACK;
// if text give high priority
else if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP)
p->priority = meshtastic_MeshPacket_Priority_HIGH;
}
} }
} }
/** enqueue a packet, return false if full */ /** enqueue a packet, return false if full */
bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p) bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p)
{ {
fixPriority(p);
// no space - try to replace a lower priority packet in the queue // no space - try to replace a lower priority packet in the queue
if (queue.size() >= maxLen) { if (queue.size() >= maxLen) {
return replaceLowerPriorityPacket(p); return replaceLowerPriorityPacket(p);

View File

@ -48,4 +48,7 @@ extern Allocator<meshtastic_MeshPacket> &packetPool;
* Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on
* the local node. If from is zero this function returns our node number instead * the local node. If from is zero this function returns our node number instead
*/ */
NodeNum getFrom(const meshtastic_MeshPacket *p); NodeNum getFrom(const meshtastic_MeshPacket *p);
/* Some clients might not properly set priority, therefore we fix it here. */
void fixPriority(meshtastic_MeshPacket *p);

View File

@ -252,6 +252,8 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
return meshtastic_Routing_Error_BAD_REQUEST; return meshtastic_Routing_Error_BAD_REQUEST;
} }
fixPriority(p); // Before encryption, fix the priority if it's unset
// If the packet is not yet encrypted, do so now // If the packet is not yet encrypted, do so now
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it