sync to vanilla 1.16

This commit is contained in:
liquidraver committed 2026-06-06 16:42:39 +02:00
1 parent 4353936328
commit ffe9ea652d
15 files changed
+105 -24

No files matched your search

+16 -7
View File
@@ -82,18 +82,27 @@ void BaseChatMesh::bootstrapRTCfromContacts()
}
}
ContactInfo *BaseChatMesh::allocateContactSlot()
ContactInfo *BaseChatMesh::allocateContactSlot(bool transient_only)
{
if (num_contacts < MAX_CONTACTS) {
return &contacts[num_contacts++];
} else if (shouldOverwriteWhenFull()) {
} else if (transient_only || shouldOverwriteWhenFull()) {
int oldest_idx = -1;
uint32_t oldest_lastmod = 0xFFFFFFFF;
for (int i = 0; i < num_contacts; i++) {
bool is_favourite = (contacts[i].flags & 0x01) != 0;
if (!is_favourite && contacts[i].lastmod < oldest_lastmod) {
oldest_lastmod = contacts[i].lastmod;
oldest_idx = i;
if (transient_only) {
// transient/anon requests only ever recycle an existing anon slot
if (contacts[i].type == ADV_TYPE_NONE && contacts[i].lastmod < oldest_lastmod) {
oldest_lastmod = contacts[i].lastmod;
oldest_idx = i;
}
} else {
// never evict favourites or transient/anon contacts
bool is_favourite = (contacts[i].flags & 0x01) != 0;
if (!is_favourite && contacts[i].lastmod < oldest_lastmod && contacts[i].type != ADV_TYPE_NONE) {
oldest_lastmod = contacts[i].lastmod;
oldest_idx = i;
}
}
}
if (oldest_idx >= 0) {
@@ -740,7 +749,7 @@ ContactInfo *BaseChatMesh::lookupContactByPubKey(const uint8_t *pub_key, int pre
bool BaseChatMesh::addContact(const ContactInfo &contact)
{
ContactInfo *dest = allocateContactSlot();
ContactInfo *dest = allocateContactSlot(contact.type == ADV_TYPE_NONE);
if (dest) {
*dest = contact;
dest->shared_secret_valid = false;
+8 -3
View File
@@ -19,6 +19,11 @@
#define MAX_CONTACTS 32
#endif
/* Headroom for transient "anon" contacts (type ADV_TYPE_NONE) created to service
* non-contact requests (CMD_SEND_ANON_REQ to a pubkey not in the contact list).
* These are never persisted or synced to the app. Mirrors upstream. */
#define MAX_ANON_CONTACTS 8
#ifdef CONFIG_ZEPHCORE_MAX_CHANNELS
#define MAX_GROUP_CHANNELS CONFIG_ZEPHCORE_MAX_CHANNELS
#else
@@ -78,9 +83,9 @@ public:
class BaseChatMesh : public mesh::Mesh {
friend class ContactsIterator;
ContactInfo contacts[MAX_CONTACTS];
ContactInfo contacts[MAX_CONTACTS + MAX_ANON_CONTACTS];
int num_contacts;
int sort_array[MAX_CONTACTS];
int sort_array[MAX_CONTACTS + MAX_ANON_CONTACTS];
int matching_peer_indexes[MAX_SEARCH_RESULTS];
unsigned long txt_send_timeout;
@@ -117,7 +122,7 @@ protected:
void bootstrapRTCfromContacts();
void resetContacts() { num_contacts = 0; }
void populateContactFromAdvert(ContactInfo &ci, const mesh::Identity &id, const AdvertDataParser &parser, uint32_t timestamp);
ContactInfo *allocateContactSlot();
ContactInfo *allocateContactSlot(bool transient_only = false);
// UI concepts for subclasses to implement
virtual bool isAutoAddEnabled() const { return true; }
+14
View File
@@ -116,6 +116,7 @@ void CommonCLI::loadPrefs(const char* path) {
ok = ok && prefs_read(&file, &_prefs->apc_enabled, sizeof(_prefs->apc_enabled)); // 292
ok = ok && prefs_read(&file, &_prefs->apc_margin, sizeof(_prefs->apc_margin)); // 293
ok = ok && prefs_read(&file, &_prefs->flood_max_unscoped, sizeof(_prefs->flood_max_unscoped)); // 294
ok = ok && prefs_read(&file, &_prefs->flood_max_advert, sizeof(_prefs->flood_max_advert)); // 295
if (!ok) {
LOG_WRN("Prefs file %s truncated, some fields use defaults", path);
@@ -160,6 +161,7 @@ void CommonCLI::loadPrefs(const char* path) {
_prefs->apc_enabled = constrain(_prefs->apc_enabled, (uint8_t)0, (uint8_t)1);
_prefs->apc_margin = constrain(_prefs->apc_margin, (uint8_t)6, (uint8_t)30);
_prefs->flood_max_unscoped = constrain(_prefs->flood_max_unscoped, (uint8_t)0, (uint8_t)64);
_prefs->flood_max_advert = constrain(_prefs->flood_max_advert, (uint8_t)0, (uint8_t)64);
LOG_INF("Loaded prefs from %s", path);
}
@@ -226,6 +228,7 @@ void CommonCLI::savePrefs(const char* path) {
fs_write(&file, &_prefs->apc_enabled, sizeof(_prefs->apc_enabled));
fs_write(&file, &_prefs->apc_margin, sizeof(_prefs->apc_margin));
fs_write(&file, &_prefs->flood_max_unscoped, sizeof(_prefs->flood_max_unscoped));
fs_write(&file, &_prefs->flood_max_advert, sizeof(_prefs->flood_max_advert));
fs_close(&file);
LOG_INF("Saved prefs to %s", path);
@@ -451,6 +454,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
(double)est, (double)ff);
} else if (memcmp(config, "apc.margin", 10) == 0) {
snprintf(reply, CLI_REPLY_SIZE, "> %d dB", (int)_callbacks->getAPCTargetMargin());
} else if (memcmp(config, "flood.max.advert", 16) == 0) {
snprintf(reply, CLI_REPLY_SIZE, "> %u", (uint32_t)_prefs->flood_max_advert);
} else if (memcmp(config, "flood.max.unscoped", 18) == 0) {
snprintf(reply, CLI_REPLY_SIZE, "> %u", (uint32_t)_prefs->flood_max_unscoped);
} else if (memcmp(config, "flood.max", 9) == 0) {
@@ -679,6 +684,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
_prefs->tx_delay_factor = atof(&config[8]);
savePrefs();
strcpy(reply, "OK (ignored: txdelay is now adaptive)");
} else if (memcmp(config, "flood.max.advert ", 17) == 0) {
int m = atoi(&config[17]);
if (m >= 0 && m <= 64) {
_prefs->flood_max_advert = (uint8_t)m;
savePrefs();
strcpy(reply, "OK");
} else {
strcpy(reply, "Error: range 0-64");
}
} else if (memcmp(config, "flood.max.unscoped ", 19) == 0) {
int m = atoi(&config[19]);
if (m >= 0 && m <= 64) {
+2
View File
@@ -48,6 +48,7 @@ struct NodePrefs {
float bw;
uint8_t flood_max;
uint8_t flood_max_unscoped; // hop limit for un-scoped (ROUTE_TYPE_FLOOD) floods
uint8_t flood_max_advert; // hop limit for ADVERT floods (curbs advert churn)
uint8_t interference_threshold;
uint8_t agc_reset_interval; // stored as secs / 4
// Power saving
@@ -120,6 +121,7 @@ static inline void initNodePrefs(NodePrefs* prefs) {
prefs->multi_acks = 0;
prefs->flood_max = 64; // max hops for flood packets (0 = blocking all!)
prefs->flood_max_unscoped = 64; // un-scoped flood hop limit (defaults to flood_max)
prefs->flood_max_advert = 8; // ADVERT flood hop limit (upstream default)
prefs->interference_threshold = 0;
prefs->agc_reset_interval = 0;
prefs->powersaving_enabled = 0;