mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 22:52:07 +00:00
feat: implement StoreAndForward lastRequest
map handling (2) (#3246)
* feat: implement StoreAndForward `lastRequest` map handling * Correct type, check if NodeNum is in map --------- Co-authored-by: andrekir <andrekir@pm.me> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
parent
143ee9cdf6
commit
5672e6825d
@ -96,11 +96,11 @@ void StoreForwardModule::populatePSRAM()
|
|||||||
*
|
*
|
||||||
* @param msAgo The number of milliseconds ago from which to start sending messages.
|
* @param msAgo The number of milliseconds ago from which to start sending messages.
|
||||||
* @param to The recipient ID to send the messages to.
|
* @param to The recipient ID to send the messages to.
|
||||||
* @param last_request_index The index in the packet history of the last request from this node.
|
|
||||||
*/
|
*/
|
||||||
void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to, uint32_t last_request_index)
|
void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to)
|
||||||
{
|
{
|
||||||
uint32_t queueSize = storeForwardModule->historyQueueCreate(msAgo, to, &last_request_index);
|
uint32_t lastIndex = lastRequest.find(to) != lastRequest.end() ? lastRequest[to] : 0;
|
||||||
|
uint32_t queueSize = storeForwardModule->historyQueueCreate(msAgo, to, &lastIndex);
|
||||||
|
|
||||||
if (queueSize) {
|
if (queueSize) {
|
||||||
LOG_INFO("*** S&F - Sending %u message(s)\n", queueSize);
|
LOG_INFO("*** S&F - Sending %u message(s)\n", queueSize);
|
||||||
@ -114,7 +114,8 @@ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to, uint32_t last_
|
|||||||
sf.which_variant = meshtastic_StoreAndForward_history_tag;
|
sf.which_variant = meshtastic_StoreAndForward_history_tag;
|
||||||
sf.variant.history.history_messages = queueSize;
|
sf.variant.history.history_messages = queueSize;
|
||||||
sf.variant.history.window = msAgo;
|
sf.variant.history.window = msAgo;
|
||||||
sf.variant.history.last_request = last_request_index;
|
sf.variant.history.last_request = lastIndex;
|
||||||
|
lastRequest[to] = lastIndex;
|
||||||
storeForwardModule->sendMessage(to, sf);
|
storeForwardModule->sendMessage(to, sf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,10 +131,10 @@ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to, uin
|
|||||||
{
|
{
|
||||||
|
|
||||||
this->packetHistoryTXQueue_size = 0;
|
this->packetHistoryTXQueue_size = 0;
|
||||||
// If our history was cleared, ignore what the client is telling us
|
// If our history was cleared, ignore the last request index
|
||||||
uint32_t last_index = *last_request_index >= this->packetHistoryCurrent ? 0 : *last_request_index;
|
uint32_t last_index = *last_request_index > this->packetHistoryCurrent ? 0 : *last_request_index;
|
||||||
|
|
||||||
for (int i = last_index; i < this->packetHistoryCurrent; i++) {
|
for (uint32_t i = last_index; i < this->packetHistoryCurrent; i++) {
|
||||||
/*
|
/*
|
||||||
LOG_DEBUG("SF historyQueueCreate\n");
|
LOG_DEBUG("SF historyQueueCreate\n");
|
||||||
LOG_DEBUG("SF historyQueueCreate - time %d\n", this->packetHistory[i].time);
|
LOG_DEBUG("SF historyQueueCreate - time %d\n", this->packetHistory[i].time);
|
||||||
@ -398,8 +399,7 @@ bool StoreForwardModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp,
|
|||||||
} else {
|
} else {
|
||||||
if ((p->which_variant == meshtastic_StoreAndForward_history_tag) && (p->variant.history.window > 0)) {
|
if ((p->which_variant == meshtastic_StoreAndForward_history_tag) && (p->variant.history.window > 0)) {
|
||||||
// window is in minutes
|
// window is in minutes
|
||||||
storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp),
|
storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp));
|
||||||
p->variant.history.last_request);
|
|
||||||
} else {
|
} else {
|
||||||
storeForwardModule->historySend(historyReturnWindow * 60000, getFrom(&mp)); // defaults to 4 hours
|
storeForwardModule->historySend(historyReturnWindow * 60000, getFrom(&mp)); // defaults to 4 hours
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
struct PacketHistoryStruct {
|
struct PacketHistoryStruct {
|
||||||
uint32_t time;
|
uint32_t time;
|
||||||
@ -36,6 +37,9 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
|
|||||||
bool is_client = false;
|
bool is_client = false;
|
||||||
bool is_server = false;
|
bool is_server = false;
|
||||||
|
|
||||||
|
// Unordered_map stores the last request for each nodeNum (`to` field)
|
||||||
|
std::unordered_map<NodeNum, uint32_t> lastRequest;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StoreForwardModule();
|
StoreForwardModule();
|
||||||
|
|
||||||
@ -48,7 +52,7 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
|
|||||||
*/
|
*/
|
||||||
void historyAdd(const meshtastic_MeshPacket &mp);
|
void historyAdd(const meshtastic_MeshPacket &mp);
|
||||||
void statsSend(uint32_t to);
|
void statsSend(uint32_t to);
|
||||||
void historySend(uint32_t msAgo, uint32_t to, uint32_t last_request_index = 0);
|
void historySend(uint32_t msAgo, uint32_t to);
|
||||||
|
|
||||||
uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to, uint32_t *last_request_index);
|
uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to, uint32_t *last_request_index);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user