From 989f52494db5e3d532d7b52076a881f030630582 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 26 Feb 2021 20:36:22 +0800 Subject: [PATCH] clean up ack packets --- proto | 2 +- src/mesh/DSRRouter.cpp | 2 +- src/mesh/MeshPlugin.cpp | 2 ++ src/mesh/ReliableRouter.cpp | 4 ++-- src/mesh/SinglePortPlugin.h | 1 + src/mesh/generated/deviceonly.pb.h | 2 +- src/mesh/generated/mesh.pb.h | 32 ++++++++++++------------------ src/plugins/RoutingPlugin.cpp | 10 ++-------- 8 files changed, 23 insertions(+), 32 deletions(-) diff --git a/proto b/proto index 6bb139c0a..fa40a9389 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 6bb139c0a43825d868a5e78c07c443f8e9e80b55 +Subproject commit fa40a9389bc910b6291fabe148260070e393600f diff --git a/src/mesh/DSRRouter.cpp b/src/mesh/DSRRouter.cpp index 0b28257f6..5fa6b1609 100644 --- a/src/mesh/DSRRouter.cpp +++ b/src/mesh/DSRRouter.cpp @@ -142,7 +142,7 @@ void DSRRouter::sniffReceived(const MeshPacket *p, const Routing *c) if (c) { // handle naks - convert them to route error packets // All naks are generated locally, because we failed resending the packet too many times - PacketId nakId = c->fail_id; + PacketId nakId = c->error_reason ? p->decoded.request_id : 0; if (nakId) { auto pending = findPendingPacket(p->to, nakId); if (pending && diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index c9cc89e12..6fd3c72b8 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -93,8 +93,10 @@ void MeshPlugin::sendResponse(const MeshPacket &req) { * This ensures that if the request packet was sent reliably, the reply is sent that way as well. */ void setReplyTo(MeshPacket *p, const MeshPacket &to) { + assert(p->which_payloadVariant == MeshPacket_decoded_tag); // Should already be set by now p->to = to.from; p->want_ack = to.want_ack; + p->decoded.request_id = to.id; } std::vector MeshPlugin::GetMeshPluginsWithUIFrames() { diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 65e1ff9f8..da743c389 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -65,8 +65,8 @@ void ReliableRouter::sniffReceived(const MeshPacket *p, const Routing *c) // If the payload is valid, look for ack/nak if (c) { - PacketId ackId = c->success_id; - PacketId nakId = c->fail_id; + PacketId ackId = c->error_reason == Routing_Error_NONE ? p->decoded.request_id : 0; + PacketId nakId = c->error_reason != Routing_Error_NONE ? p->decoded.request_id : 0; // We intentionally don't check wasSeenRecently, because it is harmless to delete non existent retransmission records if (ackId || nakId) { diff --git a/src/mesh/SinglePortPlugin.h b/src/mesh/SinglePortPlugin.h index 305532dc5..20836246d 100644 --- a/src/mesh/SinglePortPlugin.h +++ b/src/mesh/SinglePortPlugin.h @@ -33,6 +33,7 @@ class SinglePortPlugin : public MeshPlugin // Update our local node info with our position (even if we don't decide to update anyone else) MeshPacket *p = router->allocForSending(); p->decoded.portnum = ourPortNum; + p->which_payloadVariant = MeshPacket_decoded_tag; return p; } diff --git a/src/mesh/generated/deviceonly.pb.h b/src/mesh/generated/deviceonly.pb.h index 3b81f2240..1e4443af5 100644 --- a/src/mesh/generated/deviceonly.pb.h +++ b/src/mesh/generated/deviceonly.pb.h @@ -80,7 +80,7 @@ extern const pb_msgdesc_t DeviceState_msg; #define DeviceState_fields &DeviceState_msg /* Maximum encoded size of messages (where known) */ -#define DeviceState_size 6146 +#define DeviceState_size 6156 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index eed90661c..79e14f26a 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -141,6 +141,7 @@ typedef struct _Data { bool want_response; uint32_t dest; uint32_t source; + uint32_t request_id; } Data; typedef struct _LogRecord { @@ -282,10 +283,7 @@ typedef struct _Routing { RouteDiscovery route_request; RouteDiscovery route_reply; Routing_Error error_reason; - uint32_t success_id; - uint32_t fail_id; }; - uint32_t original_id; } Routing; typedef struct _FromRadio { @@ -366,8 +364,8 @@ extern "C" { #define Position_init_default {0, 0, 0, 0, 0} #define User_init_default {"", "", "", {0}} #define RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}} -#define Routing_init_default {0, {RouteDiscovery_init_default}, 0} -#define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0} +#define Routing_init_default {0, {RouteDiscovery_init_default}} +#define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} #define MeshPacket_init_default {0, 0, 0, 0, {Data_init_default}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define Channel_init_default {0, false, ChannelSettings_init_default, _Channel_Role_MIN} @@ -381,8 +379,8 @@ extern "C" { #define Position_init_zero {0, 0, 0, 0, 0} #define User_init_zero {"", "", "", {0}} #define RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} -#define Routing_init_zero {0, {RouteDiscovery_init_zero}, 0} -#define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0} +#define Routing_init_zero {0, {RouteDiscovery_init_zero}} +#define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} #define MeshPacket_init_zero {0, 0, 0, 0, {Data_init_zero}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define Channel_init_zero {0, false, ChannelSettings_init_zero, _Channel_Role_MIN} @@ -411,6 +409,7 @@ extern "C" { #define Data_want_response_tag 3 #define Data_dest_tag 4 #define Data_source_tag 5 +#define Data_request_id_tag 6 #define LogRecord_message_tag 1 #define LogRecord_time_tag 2 #define LogRecord_source_tag 3 @@ -507,9 +506,6 @@ extern "C" { #define Routing_route_request_tag 1 #define Routing_route_reply_tag 2 #define Routing_error_reason_tag 3 -#define Routing_success_id_tag 4 -#define Routing_fail_id_tag 5 -#define Routing_original_id_tag 6 #define FromRadio_num_tag 1 #define FromRadio_my_info_tag 3 #define FromRadio_node_info_tag 4 @@ -548,10 +544,7 @@ X(a, STATIC, REPEATED, FIXED32, route, 2) #define Routing_FIELDLIST(X, a) \ X(a, STATIC, ONEOF, MESSAGE, (variant,route_request,route_request), 1) \ X(a, STATIC, ONEOF, MESSAGE, (variant,route_reply,route_reply), 2) \ -X(a, STATIC, ONEOF, UENUM, (variant,error_reason,error_reason), 3) \ -X(a, STATIC, ONEOF, FIXED32, (variant,success_id,success_id), 4) \ -X(a, STATIC, ONEOF, FIXED32, (variant,fail_id,fail_id), 5) \ -X(a, STATIC, SINGULAR, FIXED32, original_id, 6) +X(a, STATIC, ONEOF, UENUM, (variant,error_reason,error_reason), 3) #define Routing_CALLBACK NULL #define Routing_DEFAULT NULL #define Routing_variant_route_request_MSGTYPE RouteDiscovery @@ -562,7 +555,8 @@ X(a, STATIC, SINGULAR, UENUM, portnum, 1) \ X(a, STATIC, SINGULAR, BYTES, payload, 2) \ X(a, STATIC, SINGULAR, BOOL, want_response, 3) \ X(a, STATIC, SINGULAR, FIXED32, dest, 4) \ -X(a, STATIC, SINGULAR, FIXED32, source, 5) +X(a, STATIC, SINGULAR, FIXED32, source, 5) \ +X(a, STATIC, SINGULAR, FIXED32, request_id, 6) #define Data_CALLBACK NULL #define Data_DEFAULT NULL @@ -760,9 +754,9 @@ extern const pb_msgdesc_t ToRadio_msg; #define Position_size 37 #define User_size 72 #define RouteDiscovery_size 40 -#define Routing_size 47 -#define Data_size 255 -#define MeshPacket_size 294 +#define Routing_size 42 +#define Data_size 260 +#define MeshPacket_size 298 #define ChannelSettings_size 87 #define Channel_size 94 #define RadioConfig_size 335 @@ -771,7 +765,7 @@ extern const pb_msgdesc_t ToRadio_msg; #define MyNodeInfo_size 89 #define LogRecord_size 81 #define FromRadio_size 344 -#define ToRadio_size 297 +#define ToRadio_size 301 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/plugins/RoutingPlugin.cpp b/src/plugins/RoutingPlugin.cpp index 9af7d31ff..18427bdca 100644 --- a/src/plugins/RoutingPlugin.cpp +++ b/src/plugins/RoutingPlugin.cpp @@ -38,20 +38,14 @@ void RoutingPlugin::sendAckNak(Routing_Error err, NodeNum to, PacketId idFrom) { Routing c = Routing_init_default; - if (!err) { - c.success_id = idFrom; - } else { - c.fail_id = idFrom; - - // Also send back the error reason - c.error_reason = err; - } + c.error_reason = err; auto p = allocDataProtobuf(c); p->priority = MeshPacket_Priority_ACK; p->hop_limit = 0; // Assume just immediate neighbors for now p->to = to; + p->decoded.request_id = idFrom; DEBUG_MSG("Sending an err=%d,to=0x%x,idFrom=0x%x,id=0x%x\n", err, to, idFrom, p->id); router->sendLocal(p); // we sometimes send directly to the local node