From f8d8dc25c0aff49d0b99aa7819e46f1f0f38493a Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 23 Feb 2021 14:35:34 +0800 Subject: [PATCH] properly route messages to phone again --- docs/software/TODO.md | 9 ++++++--- src/mesh/Channels.cpp | 9 ++++----- src/mesh/MeshPlugin.cpp | 4 +++- src/mesh/RadioInterface.cpp | 4 ++-- src/mesh/Router.cpp | 6 +++++- src/plugins/RoutingPlugin.cpp | 10 ++++++++-- src/plugins/RoutingPlugin.h | 3 +++ 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index c61ce0953..9dcfa3781 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -15,11 +15,14 @@ You probably don't care about this section - skip to the next one. * DONE enable remote setttings access by moving settings operations into a regular plugin (move settings ops out of PhoneAPI) * DONE move portnum up? * DONE remove region specific builds from the firmware -* test single channel without python -* test single channel with python -* implement 'get channels' Admin operation +* DONE test single channel without python +* DONE Use "default" for name if name is empty +* DONE fix python data packet receiving (nothing showing in log?) +* implement 'get channels' Admin plugin operation * use get-channels from python * use set-channel from python +* make python tests more exhaustive +* document the relationship between want_response (indicating remote node received it) and want_ack (indicating that this message should be sent reliably - and also get acks from the first rx node and naks if it is never delivered) * test multi channel * pick default random admin key * restrict gpio & serial & settings operations to the admin channel (unless local to the current node) diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 3e1ea3185..76ea3fb92 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -28,9 +28,8 @@ int16_t Channels::generateHash(ChannelIndex channelNum) if (k.length < 0) return -1; // invalid else { - Channel &c = getByIndex(channelNum); - - uint8_t h = xorHash((const uint8_t *)c.settings.name, strlen(c.settings.name)); + const char *name = getName(channelNum); + uint8_t h = xorHash((const uint8_t *) name, strlen(name)); h ^= xorHash(k.bytes, k.length); @@ -253,7 +252,7 @@ const char *Channels::getPrimaryName() static char buf[32]; char suffix; - auto channelSettings = getPrimary(); + // auto channelSettings = getPrimary(); // if (channelSettings.psk.size != 1) { // We have a standard PSK, so generate a letter based hash. uint8_t code = getHash(primaryIndex); @@ -263,7 +262,7 @@ const char *Channels::getPrimaryName() suffix = '0' + channelSettings.psk.bytes[0]; } */ - snprintf(buf, sizeof(buf), "#%s-%c", channelSettings.name, suffix); + snprintf(buf, sizeof(buf), "#%s-%c", getName(primaryIndex), suffix); return buf; } diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index 76ac99b6f..a1fdfd2e2 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -41,6 +41,7 @@ void MeshPlugin::callPlugins(const MeshPacket &mp) // We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious) bool wantsPacket = (pi.isPromiscuous || toUs) && pi.wantPacket(&mp); + // DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket); if (wantsPacket) { pluginFound = true; @@ -79,7 +80,8 @@ void MeshPlugin::sendResponse(const MeshPacket &req) { service.sendToMesh(r); } else { - DEBUG_MSG("WARNING: Client requested response but this plugin did not provide\n"); + // Ignore - this is now expected behavior for routing plugin (because it ignores some replies) + // DEBUG_MSG("WARNING: Client requested response but this plugin did not provide\n"); } } diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 93dd55e80..7b8aec605 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -119,8 +119,8 @@ uint32_t RadioInterface::getTxDelayMsec() void printPacket(const char *prefix, const MeshPacket *p) { - DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d", prefix, p->id, p->from & 0xff, p->to & 0xff, p->want_ack, - p->hop_limit); + DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d Ch0x%x", prefix, p->id, p->from & 0xff, p->to & 0xff, p->want_ack, + p->hop_limit, p->channel); if (p->which_payloadVariant == MeshPacket_decoded_tag) { auto &s = p->decoded; diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 50e4215b2..a6afe952e 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -232,6 +232,7 @@ bool Router::perhapsDecode(MeshPacket *p) } else { // parsing was successful p->channel = chIndex; // change to store the index instead of the hash + // printPacket("decoded message", p); p->which_payloadVariant = MeshPacket_decoded_tag; return true; } @@ -257,7 +258,10 @@ void Router::handleReceived(MeshPacket *p) p->rx_time = getValidTime(RTCQualityFromNet); // store the arrival timestamp for the phone // Take those raw bytes and convert them back into a well structured protobuf we can understand - if (perhapsDecode(p)) { + bool decoded = perhapsDecode(p); + printPacket("handleReceived", p); + DEBUG_MSG("decoded=%d\n", decoded); + if (decoded) { // parsing was successful, queue for our recipient // call any promiscious plugins here, make a (non promisiocous) plugin for forwarding messages to phone api diff --git a/src/plugins/RoutingPlugin.cpp b/src/plugins/RoutingPlugin.cpp index 58b3f08ae..9af7d31ff 100644 --- a/src/plugins/RoutingPlugin.cpp +++ b/src/plugins/RoutingPlugin.cpp @@ -9,6 +9,7 @@ RoutingPlugin *routingPlugin; bool RoutingPlugin::handleReceivedProtobuf(const MeshPacket &mp, const Routing *r) { + DEBUG_MSG("Routing sniffing", &mp); router->sniffReceived(&mp, r); // FIXME - move this to a non promsicious PhoneAPI plugin? @@ -23,8 +24,13 @@ bool RoutingPlugin::handleReceivedProtobuf(const MeshPacket &mp, const Routing * MeshPacket *RoutingPlugin::allocReply() { - assert(0); // 1.2 refactoring fixme, Not sure if anything needs this yet? - // return allocDataProtobuf(u); + assert(currentRequest); + + // We only consider making replies if the request was a legit routing packet (not just something we were sniffing) + if(currentRequest->decoded.portnum == PortNum_ROUTING_APP) { + assert(0); // 1.2 refactoring fixme, Not sure if anything needs this yet? + // return allocDataProtobuf(u); + } return NULL; } diff --git a/src/plugins/RoutingPlugin.h b/src/plugins/RoutingPlugin.h index 0d987f39e..a848bc9c4 100644 --- a/src/plugins/RoutingPlugin.h +++ b/src/plugins/RoutingPlugin.h @@ -25,6 +25,9 @@ class RoutingPlugin : public ProtobufPlugin * so that subclasses can (optionally) send a response back to the original sender. */ virtual MeshPacket *allocReply(); + /// Override wantPacket to say we want to see all packets, not just those for our port number + virtual bool wantPacket(const MeshPacket *p) { return true; } + void sendAckNak(Routing_Error err, NodeNum to, PacketId idFrom); };