diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index 1d64cd28..2081def6 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -85,41 +85,47 @@ void MeshPlugin::callPlugins(const MeshPacket &mp) auto ch = channels.getByIndex(mp.channel); assert(ch.has_settings); - /// Is the channel this packet arrived on acceptable? (security check) - bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || (strcmp(ch.settings.name, pi.boundChannel) == 0); - /// We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious) - if (!rxChannelOk && toUs) { - // no one should have already replied! - assert(!currentReply); + bool wantsPacket = (pi.isPromiscuous || toUs) && pi.wantPacket(&mp); - if (mp.decoded.want_response) { - DEBUG_MSG("packet on wrong channel, returning error\n"); - currentReply = pi.allocErrorResponse(Routing_Error_NOT_AUTHORIZED, &mp); - } else - DEBUG_MSG("packet on wrong channel, but client didn't want response\n"); - } else if ((pi.isPromiscuous || toUs) && pi.wantPacket(&mp)) { + if (wantsPacket) { // DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket); pluginFound = true; - bool handled = pi.handleReceived(mp); + /// Is the channel this packet arrived on acceptable? (security check) + bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || (strcmp(ch.settings.name, pi.boundChannel) == 0); - // Possibly send replies (but only if the message was directed to us specifically, i.e. not for promiscious sniffing) - // also: we only let the one plugin send a reply, once that happens, remaining plugins are not considered + if (!rxChannelOk) { + // no one should have already replied! + assert(!currentReply); - // NOTE: we send a reply *even if the (non broadcast) request was from us* which is unfortunate but necessary because - // currently when the phone sends things, it sends things using the local node ID as the from address. A better - // solution (FIXME) would be to let phones have their own distinct addresses and we 'route' to them like any other - // node. - if (mp.decoded.want_response && toUs && (getFrom(&mp) != ourNodeNum || mp.to == ourNodeNum) && !currentReply) { - pi.sendResponse(mp); - DEBUG_MSG("Plugin %s sent a response\n", pi.name); + if (mp.decoded.want_response) { + DEBUG_MSG("packet on wrong channel, returning error\n"); + currentReply = pi.allocErrorResponse(Routing_Error_NOT_AUTHORIZED, &mp); + } else + DEBUG_MSG("packet on wrong channel, but client didn't want response\n"); } else { - DEBUG_MSG("Plugin %s considered\n", pi.name); - } - if (handled) { - DEBUG_MSG("Plugin %s handled and skipped other processing\n", pi.name); - break; + + bool handled = pi.handleReceived(mp); + + // Possibly send replies (but only if the message was directed to us specifically, i.e. not for promiscious + // sniffing) also: we only let the one plugin send a reply, once that happens, remaining plugins are not + // considered + + // NOTE: we send a reply *even if the (non broadcast) request was from us* which is unfortunate but necessary + // because currently when the phone sends things, it sends things using the local node ID as the from address. A + // better solution (FIXME) would be to let phones have their own distinct addresses and we 'route' to them like + // any other node. + if (mp.decoded.want_response && toUs && (getFrom(&mp) != ourNodeNum || mp.to == ourNodeNum) && !currentReply) { + pi.sendResponse(mp); + DEBUG_MSG("Plugin %s sent a response\n", pi.name); + } else { + DEBUG_MSG("Plugin %s considered\n", pi.name); + } + if (handled) { + DEBUG_MSG("Plugin %s handled and skipped other processing\n", pi.name); + break; + } } }