Restore effective membership on startup and group creation

This commit is contained in:
evgeny committed 2026-11-03 15:49:10 +01:00
1 parent b5d008ee87
commit 6aa24b6471
2 files changed
+25

No files matched your search

+5
View File
@@ -7,6 +7,7 @@
#include "chat_core_priv.h"
#include "chat_attachment.h"
#include "group_avatar.h"
#include "group_policy.h"
#include "chat_event.h"
#include "chat_feedback.h"
#include "chat_setting.h"
@@ -168,6 +169,10 @@ int chat_core_create_channel(struct UTUN_INSTANCE* inst, const struct chat_chann
stage = "commit"; rc = sqlite3_exec(cc->db, "COMMIT /* channel creation */", NULL, NULL, NULL);
if (rc != SQLITE_OK) goto error;
if (group_policy_refresh(inst, req->channel_id)) {
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "channel created but admission refresh failed ch=%s", req->channel_id); return -1;
}
int ready = !chat_core_ensure_channel_ready(inst, req->channel_id);
if (!ready) DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "channel create: committed ch=%s, runtime activation deferred; retry preparation", req->channel_id);
member_sync_record_committed(inst, req->channel_id, inst->node_id, (unsigned)changes);
+20
View File
@@ -1380,6 +1380,26 @@ int member_sync_init(struct UTUN_INSTANCE* inst) {
merkle_sync_destroy(inst); return -1;
}
if (_rebuild_all_trees(inst) < 0) { merkle_sync_destroy(inst); return -1; }
char last[128] = "";
for (;;) {
sqlite3_stmt* st = NULL;
int sr = sqlite3_prepare_v2(db, "SELECT name FROM sqlite_master WHERE type='table' AND name GLOB 'peers_*'"
" AND name>? ORDER BY name LIMIT 1", -1, &st, NULL);
if (sr == SQLITE_OK) sr = sqlite3_bind_text(st, 1, last, -1, SQLITE_STATIC);
if (sr == SQLITE_OK) sr = sqlite3_step(st);
if (sr == SQLITE_ROW) {
const char* name = (const char*)sqlite3_column_text(st, 0);
if (!name || strlen(name) >= sizeof(last)) sr = SQLITE_CORRUPT;
else strcpy(last, name);
}
int final = sqlite3_finalize(st);
if ((sr != SQLITE_ROW && sr != SQLITE_DONE) || final != SQLITE_OK ||
(sr == SQLITE_ROW && group_policy_refresh(inst, last + 6))) {
DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "admission initialization failed rc=%d table=%s", sr, last);
merkle_sync_destroy(inst); return -1;
}
if (sr == SQLITE_DONE) break;
}
/* подписка на BGP-события существующих chat-групп */
if (inst->topo_groups && inst->topo_groups->group_list) {
struct ll_entry* ge = inst->topo_groups->group_list->head;