Skip to content

Commit

Permalink
Check Position Request for Primary Channel
Browse files Browse the repository at this point in the history
Prevents leaking location data to secondary channels.
  • Loading branch information
jp-bennett committed Jul 23, 2023
1 parent 470363d commit 41ff2a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/mesh/MeshModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ class MeshModule
return AdminMessageHandleResult::NOT_HANDLED;
};

private:
/**
* If any of the current chain of modules has already sent a reply, it will be here. This is useful to allow
* the RoutingModule to avoid sending redundant acks
*/
static meshtastic_MeshPacket *currentReply;

private:
friend class ReliableRouter;

/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
* so that subclasses can (optionally) send a response back to the original sender. This method calls allocReply()
* to generate the reply message, and if !NULL that message will be delivered to whoever sent req
*/
void sendResponse(const meshtastic_MeshPacket &req);
virtual void sendResponse(const meshtastic_MeshPacket &req);
};

/** set the destination and packet parameters of packet p intended as a reply to a particular "to" packet
Expand Down
16 changes: 15 additions & 1 deletion src/modules/PositionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ meshtastic_MeshPacket *PositionModule::allocReply()
return allocDataProtobuf(p);
}

void PositionModule::sendResponse(const meshtastic_MeshPacket &req)
{
if (channels.getByIndex(req.channel).role != meshtastic_Channel_Role_PRIMARY)
return;
auto r = allocReply();
if (r) {
setReplyTo(r, req);
currentReply = r;
} else {
// Ignore - this is now expected behavior for routing module (because it ignores some replies)
// LOG_WARN("Client requested response but this module did not provide\n");
}
}

void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
{
// cancel any not yet sent (now stale) position packets
Expand Down Expand Up @@ -214,4 +228,4 @@ int32_t PositionModule::runOnce()
}

return 5000; // to save power only wake for our callback occasionally
}
}
7 changes: 7 additions & 0 deletions src/modules/PositionModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu

/** Does our periodic broadcast */
virtual int32_t runOnce() override;

private:
/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
* so that subclasses can (optionally) send a response back to the original sender. This method calls allocReply()
* to generate the reply message, and if !NULL that message will be delivered to whoever sent req
*/
virtual void sendResponse(const meshtastic_MeshPacket &req) override;
};

extern PositionModule *positionModule;

0 comments on commit 41ff2a2

Please sign in to comment.