mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-09-02 02:39:30 +00:00
sync to vanilla 1.16
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user