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
// and fix it
if (p->priority == meshtastic_MeshPacket_Priority_UNSET) {
// if acks give high priority
// if a reliable message give a bit higher default priority
p->priority = (p->decoded.portnum == meshtastic_PortNum_ROUTING_APP)
? meshtastic_MeshPacket_Priority_ACK
: (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT);
p->priority = (p->want_ack ? meshtastic_MeshPacket_Priority_RELIABLE : meshtastic_MeshPacket_Priority_DEFAULT);
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
// 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 */
bool MeshPacketQueue::enqueue(meshtastic_MeshPacket *p)
{
fixPriority(p);
// no space - try to replace a lower priority packet in the queue
if (queue.size() >= maxLen) {
return replaceLowerPriorityPacket(p);

View File

@ -49,3 +49,6 @@ extern Allocator<meshtastic_MeshPacket> &packetPool;
* the local node. If from is zero this function returns our node number instead
*/
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;
}
fixPriority(p); // Before encryption, fix the priority if it's unset
// If the packet is not yet encrypted, do so now
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it