More StoreForward updates (#3274)

* More StoreForward updates

* Disable heartbeat again if not in config

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
GUVWAF 2024-02-25 14:29:34 +01:00 committed by GitHub
parent d47f55289f
commit 02192e1163
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 33 deletions

View File

@ -45,7 +45,8 @@ int32_t StoreForwardModule::runOnce()
this->busy = false; this->busy = false;
} }
} }
} else if ((millis() - lastHeartbeat > (heartbeatInterval * 1000)) && airTime->isTxAllowedChannelUtil(true)) { } else if (this->heartbeat && (millis() - lastHeartbeat > (heartbeatInterval * 1000)) &&
airTime->isTxAllowedChannelUtil(true)) {
lastHeartbeat = millis(); lastHeartbeat = millis();
LOG_INFO("*** Sending heartbeat\n"); LOG_INFO("*** Sending heartbeat\n");
meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero; meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero;
@ -141,25 +142,31 @@ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to, uin
LOG_DEBUG("SF historyQueueCreate - millis %d\n", millis()); LOG_DEBUG("SF historyQueueCreate - millis %d\n", millis());
LOG_DEBUG("SF historyQueueCreate - math %d\n", (millis() - msAgo)); LOG_DEBUG("SF historyQueueCreate - math %d\n", (millis() - msAgo));
*/ */
if (this->packetHistory[i].time && (this->packetHistory[i].time < (millis() - msAgo))) { if (this->packetHistoryTXQueue_size < this->historyReturnMax) {
/* Copy the messages that were received by the router in the last msAgo if (this->packetHistory[i].time && (this->packetHistory[i].time < (millis() - msAgo))) {
to the packetHistoryTXQueue structure. /* Copy the messages that were received by the router in the last msAgo
Client not interested in packets from itself and only in broadcast packets or packets towards it. */ to the packetHistoryTXQueue structure.
if (this->packetHistory[i].from != to && Client not interested in packets from itself and only in broadcast packets or packets towards it. */
(this->packetHistory[i].to == NODENUM_BROADCAST || this->packetHistory[i].to == to)) { if (this->packetHistory[i].from != to &&
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; (this->packetHistory[i].to == NODENUM_BROADCAST || this->packetHistory[i].to == to)) {
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time;
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to;
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].channel = this->packetHistory[i].channel; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from;
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload_size = this->packetHistory[i].payload_size; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].channel = this->packetHistory[i].channel;
memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload, this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload_size =
meshtastic_Constants_DATA_PAYLOAD_LEN); this->packetHistory[i].payload_size;
this->packetHistoryTXQueue_size++; memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload,
*last_request_index = i + 1; // Set to one higher such that we don't send the same message again meshtastic_Constants_DATA_PAYLOAD_LEN);
this->packetHistoryTXQueue_size++;
*last_request_index = i + 1; // Set to one higher such that we don't send the same message again
LOG_DEBUG("*** PacketHistoryStruct time=%d, msg=%s\n", this->packetHistory[i].time, LOG_DEBUG("*** PacketHistoryStruct time=%d, msg=%s\n", this->packetHistory[i].time,
this->packetHistory[i].payload); this->packetHistory[i].payload);
}
} }
} else {
LOG_WARN("*** S&F - Maximum history return reached.\n");
return this->packetHistoryTXQueue_size;
} }
} }
return this->packetHistoryTXQueue_size; return this->packetHistoryTXQueue_size;
@ -174,20 +181,24 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp)
{ {
const auto &p = mp.decoded; const auto &p = mp.decoded;
if (this->packetHistoryCurrent < this->records) { if (this->packetHistoryCurrent == this->records) {
this->packetHistory[this->packetHistoryCurrent].time = millis(); LOG_WARN("*** S&F - PSRAM Full. Starting overwrite now.\n");
this->packetHistory[this->packetHistoryCurrent].to = mp.to; this->packetHistoryCurrent = 0;
this->packetHistory[this->packetHistoryCurrent].channel = mp.channel; this->packetHistoryMax = 0;
this->packetHistory[this->packetHistoryCurrent].from = mp.from; for (auto &i : lastRequest) {
this->packetHistory[this->packetHistoryCurrent].payload_size = p.payload.size; i.second = 0; // Clear the last request index for each client device
memcpy(this->packetHistory[this->packetHistoryCurrent].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN); }
this->packetHistoryCurrent++;
this->packetHistoryMax++;
} else {
// TODO: Overwrite the oldest message in the history buffer when it is full.
LOG_WARN("*** S&F - PSRAM Full. Packet is not added to the history.\n");
} }
this->packetHistory[this->packetHistoryCurrent].time = millis();
this->packetHistory[this->packetHistoryCurrent].to = mp.to;
this->packetHistory[this->packetHistoryCurrent].channel = mp.channel;
this->packetHistory[this->packetHistoryCurrent].from = mp.from;
this->packetHistory[this->packetHistoryCurrent].payload_size = p.payload.size;
memcpy(this->packetHistory[this->packetHistoryCurrent].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN);
this->packetHistoryCurrent++;
this->packetHistoryMax++;
} }
meshtastic_MeshPacket *StoreForwardModule::allocReply() meshtastic_MeshPacket *StoreForwardModule::allocReply()
@ -313,7 +324,8 @@ ProcessMessage StoreForwardModule::handleReceived(const meshtastic_MeshPacket &m
if ((mp.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) && is_server) { if ((mp.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) && is_server) {
auto &p = mp.decoded; auto &p = mp.decoded;
if ((p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 0x00)) { if (mp.to == nodeDB.getNodeNum() && (p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') &&
(p.payload.bytes[2] == 0x00)) {
LOG_DEBUG("*** Legacy Request to send\n"); LOG_DEBUG("*** Legacy Request to send\n");
// Send the last 60 minutes of messages. // Send the last 60 minutes of messages.
@ -543,6 +555,8 @@ StoreForwardModule::StoreForwardModule()
// send heartbeat advertising? // send heartbeat advertising?
if (moduleConfig.store_forward.heartbeat) if (moduleConfig.store_forward.heartbeat)
this->heartbeat = moduleConfig.store_forward.heartbeat; this->heartbeat = moduleConfig.store_forward.heartbeat;
else
this->heartbeat = false;
// Popupate PSRAM with our data structures. // Popupate PSRAM with our data structures.
this->populatePSRAM(); this->populatePSRAM();

View File

@ -44,7 +44,7 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
StoreForwardModule(); StoreForwardModule();
unsigned long lastHeartbeat = 0; unsigned long lastHeartbeat = 0;
uint32_t heartbeatInterval = default_broadcast_interval_secs; uint32_t heartbeatInterval = 900;
/** /**
Update our local reference of when we last saw that node. Update our local reference of when we last saw that node.