* Add ESP32 Power Management lessons learned document Documents our experimentation with ESP-IDF DFS and why it doesn't work well for Meshtastic (RTOS locks, BLE locks, USB issues). Proposes simpler alternative: manual setCpuFrequencyMhz() control with explicit triggers for when to go fast vs slow. * Addition of traffic management module * Fixing compile issues, but may still need to update protobufs. * Fixing log2Floor in cuckoo hash function * Adding support for traffic management in PhoneAPI. * Making router_preserve_hops work without checking if the previous hop was a router. Also works for CLIENT_BASE. * Adding station-g2 and portduino varients to be able to use this module. * Spoofing from address for nodeinfo cache * Changing name and behavior for zero_hop_telemetry / zero_hop_position * Name change for exhausting telemetry packets and setting hop_limit to 1 so it will be 0 when sent. * Updated hop logic, including exhaustRequested flag to bypass some checks later in the code. * Reducing memory on nrf52 nodes further to 12 bytes per entry, 12KB total using 8 bit hashes with 0.4% collision. Probably ok. Adding portduino to the platforms that don't need to worry about memory as much. * Fixing hopsAway for nodeinfo responses. * traffic_management.nodeinfo_direct_response_min_hops -> traffic_management.nodeinfo_direct_response_max_hops * Removing dry run mode * Updates to UnifiedCacheEntry to use a common cache, created defaults for some values, reduced a couple bytes per entry by using a resolution-scale time selection based on configuration value. * Enhance traffic management logging and configuration. Updated log messages in NextHopRouter and Router to include more context. Adjusted traffic management configuration checks in AdminModule and improved cache handling in TrafficManagementModule. Ensured consistent enabling of traffic management across various variants. * Implement destructor for TrafficManagementModule and improve cache allocation handling. The destructor ensures proper deallocation of cache memory based on its allocation source (PSRAM or heap). Additionally, updated cache allocation logic to log warnings only when PSRAM allocation fails. * Update TrafficManagementModule with enhanced comments for clarity and improve cache handling logic. Update protobuf submodule to latest commit. * Creating consistent log messages * Remove docs/ESP32_Power_Management.md from traffic_module * Add unit tests for Traffic Management Module functionality * Fixing compile issues, but may still need to update protobufs. * Adding support for traffic management in PhoneAPI. * Making router_preserve_hops work without checking if the previous hop was a router. Also works for CLIENT_BASE. * Enhance traffic management logging and configuration. Updated log messages in NextHopRouter and Router to include more context. Adjusted traffic management configuration checks in AdminModule and improved cache handling in TrafficManagementModule. Ensured consistent enabling of traffic management across various variants. * Implement destructor for TrafficManagementModule and improve cache allocation handling. The destructor ensures proper deallocation of cache memory based on its allocation source (PSRAM or heap). Additionally, updated cache allocation logic to log warnings only when PSRAM allocation fails. * Update TrafficManagementModule with enhanced comments for clarity and improve cache handling logic. Update protobuf submodule to latest commit. * Add mock classes and unit tests for Traffic Management Module functionality. * Refactor setup and loop functions in test_main.cpp to include extern "C" linkage * Update comment to include reduced memory requirements Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Re-arranging comments for programmers with the attention span of less than 5 lines of code. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update comments in TrafficManagementModule to reflect changes in timestamp epoch handling and memory optimization details. * bug: Use node-wide config_ok_to_mqtt setting for cached NodeInfo replies. * Better way to handle clearing the ok_to_mqtt bit * Add bucketing to cuckoo hashing, allowing for 95% occupied rate before major eviction problems. * Extend nodeinfo cache for psram devices. * Refactor traffic management to make hop exhaustion packet-scoped. Nice catch. * Implement better position precision sanitization in TrafficManagementModule. * Added logic in TrafficManagementModule to invalidate stale traffic state. Also, added some tests to avoid future me from creating a regression here. * Fixing tests for native * Enhance TrafficManagementModule to improve NodeInfo response handling and position deduplication logic. Added tests to ensure local packets bypass transit filters and that NodeInfo requests correctly update the requester information in the cache. Updated deduplication checks to prevent dropping valid position packets under certain conditions. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
110 lines
4.0 KiB
C++
110 lines
4.0 KiB
C++
#pragma once
|
|
#include <vector>
|
|
|
|
#include "mesh/generated/meshtastic/admin.pb.h"
|
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
|
#include "mesh/generated/meshtastic/localonly.pb.h"
|
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
|
|
|
// this file defines constants which come from mesh.options
|
|
|
|
// Tricky macro to let you find the sizeof a type member
|
|
#define member_size(type, member) sizeof(((type *)0)->member)
|
|
|
|
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
|
// FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in
|
|
// RAM #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
|
#ifndef MAX_RX_TOPHONE
|
|
#if defined(ARCH_ESP32) && !(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3))
|
|
#define MAX_RX_TOPHONE 8
|
|
#else
|
|
#define MAX_RX_TOPHONE 32
|
|
#endif
|
|
#endif
|
|
|
|
/// max number of QueueStatus packets which can be waiting for delivery to phone
|
|
#ifndef MAX_RX_QUEUESTATUS_TOPHONE
|
|
#define MAX_RX_QUEUESTATUS_TOPHONE 2
|
|
#endif
|
|
|
|
/// max number of MqttClientProxyMessage packets which can be waiting for delivery to phone
|
|
#ifndef MAX_RX_MQTTPROXY_TOPHONE
|
|
#define MAX_RX_MQTTPROXY_TOPHONE 8
|
|
#endif
|
|
|
|
/// max number of ClientNotification packets which can be waiting for delivery to phone
|
|
#ifndef MAX_RX_NOTIFICATION_TOPHONE
|
|
#define MAX_RX_NOTIFICATION_TOPHONE 2
|
|
#endif
|
|
|
|
/// Verify baseline assumption of node size. If it increases, we need to reevaluate
|
|
/// the impact of its memory footprint, notably on MAX_NUM_NODES.
|
|
static_assert(sizeof(meshtastic_NodeInfoLite) <= 200, "NodeInfoLite size increased. Reconsider impact on MAX_NUM_NODES.");
|
|
|
|
/// max number of nodes allowed in the nodeDB
|
|
#ifndef MAX_NUM_NODES
|
|
#if defined(ARCH_STM32WL)
|
|
#define MAX_NUM_NODES 10
|
|
#elif defined(ARCH_NRF52)
|
|
#define MAX_NUM_NODES 80
|
|
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
|
#include "Esp.h"
|
|
static inline int get_max_num_nodes()
|
|
{
|
|
uint32_t flash_size = ESP.getFlashChipSize() / (1024 * 1024); // Convert Bytes to MB
|
|
if (flash_size >= 15) {
|
|
return 250;
|
|
} else if (flash_size >= 7) {
|
|
return 200;
|
|
} else {
|
|
return 100;
|
|
}
|
|
}
|
|
#define MAX_NUM_NODES get_max_num_nodes()
|
|
#else
|
|
#define MAX_NUM_NODES 100
|
|
#endif
|
|
#endif
|
|
|
|
/// Max number of channels allowed
|
|
#define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0]))
|
|
|
|
// Traffic Management module configuration
|
|
// Enable per-variant by defining HAS_TRAFFIC_MANAGEMENT=1 in variant.h
|
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
|
#define HAS_TRAFFIC_MANAGEMENT 0
|
|
#endif
|
|
|
|
// Cache size for traffic management (number of nodes to track)
|
|
// Can be overridden per-variant based on available memory
|
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
|
#if HAS_TRAFFIC_MANAGEMENT
|
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 1000
|
|
#else
|
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 0
|
|
#endif
|
|
#endif
|
|
|
|
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
|
/// returns the encoded packet size
|
|
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct);
|
|
|
|
/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
|
|
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct);
|
|
|
|
/// Read from an Arduino File
|
|
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count);
|
|
|
|
/// Write to an arduino file
|
|
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count);
|
|
|
|
/** is_in_repeated is a macro/function that returns true if a specified word appears in a repeated protobuf array.
|
|
* It relies on the following naming conventions from nanopb:
|
|
*
|
|
* pb_size_t ignore_incoming_count;
|
|
* uint32_t ignore_incoming[3];
|
|
*/
|
|
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count);
|
|
|
|
#define is_in_repeated(name, n) is_in_helper(n, name, name##_count)
|