Skip to content

Commit

Permalink
Let StoreForward server send history to phoneAPI (#4282)
Browse files Browse the repository at this point in the history
* Send StoreForward history of the server to a connected client
To extend the ToPhoneQueue

* Add delay after sending history info

* Don't allow history request over LoRa on default channel

---------

Co-authored-by: Ben Meadors <[email protected]>
  • Loading branch information
GUVWAF and thebentern authored Jul 13, 2024
1 parent 141ae29 commit 9e4ce86
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 180 deletions.
22 changes: 14 additions & 8 deletions src/mesh/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ const char *Channels::getName(size_t chIndex)
return channelName;
}

bool Channels::isDefaultChannel(const meshtastic_Channel &ch)
{
if (ch.settings.psk.size == 1 && ch.settings.psk.bytes[0] == 1) {
const char *presetName = DisplayFormatters::getModemPresetDisplayName(config.lora.modem_preset, false);
// Check if the name is the default derived from the modem preset
if (strcmp(ch.settings.name, presetName) == 0)
return true;
}
return false;
}

bool Channels::hasDefaultChannel()
{
// If we don't use a preset or the default frequency slot, or we override the frequency, we don't have a default channel
Expand All @@ -285,13 +296,8 @@ bool Channels::hasDefaultChannel()
// Check if any of the channels are using the default name and PSK
for (size_t i = 0; i < getNumChannels(); i++) {
const auto &ch = getByIndex(i);
if (ch.settings.psk.size == 1 && ch.settings.psk.bytes[0] == 1) {
const char *name = getName(i);
const char *presetName = DisplayFormatters::getModemPresetDisplayName(config.lora.modem_preset, false);
// Check if the name is the default derived from the modem preset
if (strcmp(name, presetName) == 0)
return true;
}
if (isDefaultChannel(ch))
return true;
}
return false;
}
Expand Down Expand Up @@ -324,4 +330,4 @@ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
int16_t Channels::setActiveByIndex(ChannelIndex channelIndex)
{
return setCrypto(channelIndex);
}
}
5 changes: 4 additions & 1 deletion src/mesh/Channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Channels
*/
int16_t setActiveByIndex(ChannelIndex channelIndex);

// Returns true if the channel has the default name and PSK
bool isDefaultChannel(const meshtastic_Channel &ch);

// Returns true if we can be reached via a channel with the default settings given a region and modem preset
bool hasDefaultChannel();

Expand Down Expand Up @@ -126,4 +129,4 @@ class Channels
};

/// Singleton channel table
extern Channels channels;
extern Channels channels;
11 changes: 11 additions & 0 deletions src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ void MeshService::sendToPhone(meshtastic_MeshPacket *p)
{
perhapsDecode(p);

#ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
if (moduleConfig.store_forward.enabled && storeForwardModule->isServer() &&
p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
releaseToPool(p); // Copy is already stored in StoreForward history
fromNum++; // Notify observers for packet from radio
return;
}
#endif
#endif

if (toPhoneQueue.numFree() == 0) {
if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP ||
p->decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP) {
Expand Down
5 changes: 5 additions & 0 deletions src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#if defined(ARCH_PORTDUINO) && !HAS_RADIO
#include "../platform/portduino/SimRadio.h"
#endif
#ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/esp32/StoreForwardModule.h"
#endif
#endif

extern Allocator<meshtastic_QueueStatus> &queueStatusPool;
extern Allocator<meshtastic_MqttClientProxyMessage> &mqttClientProxyMessagePool;
Expand Down
8 changes: 8 additions & 0 deletions src/mesh/PhoneAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@ bool PhoneAPI::available()
return true;
}

#ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
// Check if StoreForward has packets stored for us.
if (!packetForPhone && storeForwardModule)
packetForPhone = storeForwardModule->getForPhone();
#endif
#endif

if (!packetForPhone)
packetForPhone = service.getForPhone();
hasPacket = !!packetForPhone;
Expand Down
5 changes: 5 additions & 0 deletions src/modules/AdminModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
// Router Client is deprecated; Set it to client
if (c.payload_variant.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT) {
config.device.role = meshtastic_Config_DeviceConfig_Role_CLIENT;
if (moduleConfig.store_forward.enabled && !moduleConfig.store_forward.is_server) {
moduleConfig.store_forward.is_server = true;
changes |= SEGMENT_MODULECONFIG;
requiresReboot = true;
}
}
break;
case meshtastic_Config_position_tag:
Expand Down
Loading

0 comments on commit 9e4ce86

Please sign in to comment.