mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-02 18:26:11 +00:00
* contacts sync fix
* fix for reusing transient/anon contacts only
This commit is contained in:
@@ -2186,7 +2186,15 @@ void MyMesh::checkSerialInterface() {
|
|||||||
&& !_serial->isWriteBusy() // don't spam the Serial Interface too quickly!
|
&& !_serial->isWriteBusy() // don't spam the Serial Interface too quickly!
|
||||||
) {
|
) {
|
||||||
ContactInfo contact;
|
ContactInfo contact;
|
||||||
if (_iter.hasNext(this, contact)) {
|
bool found = false;
|
||||||
|
while (_iter.hasNext(this, contact)) {
|
||||||
|
if (contact.type != ADV_TYPE_NONE) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
if (contact.lastmod > _iter_filter_since) { // apply the 'since' filter
|
if (contact.lastmod > _iter_filter_since) { // apply the 'since' filter
|
||||||
writeContactRespFrame(RESP_CODE_CONTACT, contact);
|
writeContactRespFrame(RESP_CODE_CONTACT, contact);
|
||||||
if (contact.lastmod > _most_recent_lastmod) {
|
if (contact.lastmod > _most_recent_lastmod) {
|
||||||
|
|||||||
@@ -67,18 +67,25 @@ void BaseChatMesh::bootstrapRTCfromContacts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactInfo* BaseChatMesh::allocateContactSlot() {
|
ContactInfo* BaseChatMesh::allocateContactSlot(bool transient_only) {
|
||||||
if (num_contacts < MAX_CONTACTS) {
|
if (num_contacts < MAX_CONTACTS) {
|
||||||
return &contacts[num_contacts++];
|
return &contacts[num_contacts++];
|
||||||
} else if (shouldOverwriteWhenFull()) {
|
} else if (transient_only || shouldOverwriteWhenFull()) {
|
||||||
// Find oldest non-favourite contact by oldest lastmod timestamp
|
// Find oldest non-favourite contact by oldest lastmod timestamp
|
||||||
int oldest_idx = -1;
|
int oldest_idx = -1;
|
||||||
uint32_t oldest_lastmod = 0xFFFFFFFF;
|
uint32_t oldest_lastmod = 0xFFFFFFFF;
|
||||||
for (int i = 0; i < num_contacts; i++) {
|
for (int i = 0; i < num_contacts; i++) {
|
||||||
bool is_favourite = (contacts[i].flags & 0x01) != 0;
|
if (transient_only) {
|
||||||
if (!is_favourite && contacts[i].lastmod < oldest_lastmod && contacts[i].type != ADV_TYPE_NONE) {
|
if (contacts[i].type == ADV_TYPE_NONE && contacts[i].lastmod < oldest_lastmod) {
|
||||||
oldest_lastmod = contacts[i].lastmod;
|
oldest_lastmod = contacts[i].lastmod;
|
||||||
oldest_idx = i;
|
oldest_idx = i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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) {
|
if (oldest_idx >= 0) {
|
||||||
@@ -830,7 +837,7 @@ ContactInfo* BaseChatMesh::lookupContactByPubKey(const uint8_t* pub_key, int pre
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool BaseChatMesh::addContact(const ContactInfo& contact) {
|
bool BaseChatMesh::addContact(const ContactInfo& contact) {
|
||||||
ContactInfo* dest = allocateContactSlot();
|
ContactInfo* dest = allocateContactSlot(contact.type == ADV_TYPE_NONE);
|
||||||
if (dest) {
|
if (dest) {
|
||||||
*dest = contact;
|
*dest = contact;
|
||||||
dest->shared_secret_valid = false; // mark shared_secret as needing calculation
|
dest->shared_secret_valid = false; // mark shared_secret as needing calculation
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ protected:
|
|||||||
void bootstrapRTCfromContacts();
|
void bootstrapRTCfromContacts();
|
||||||
void resetContacts() { num_contacts = 0; }
|
void resetContacts() { num_contacts = 0; }
|
||||||
void populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp);
|
void populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp);
|
||||||
ContactInfo* allocateContactSlot(); // helper to find slot for new contact
|
ContactInfo* allocateContactSlot(bool transient_only=false); // helper to find slot for new contact
|
||||||
|
|
||||||
// 'UI' concepts, for sub-classes to implement
|
// 'UI' concepts, for sub-classes to implement
|
||||||
virtual bool isAutoAddEnabled() const { return true; }
|
virtual bool isAutoAddEnabled() const { return true; }
|
||||||
|
|||||||
Reference in New Issue
Block a user