Adapt member sync and protocol tests to dataset cursors
This commit is contained in:
1 parent
539bfd6db9
commit
5e146f20bc
2 files changed
+29
-24
No files matched your search
+14
-9
@@ -204,12 +204,17 @@ static int _member_update_bucket_hash(void* ctx, const char* ns, uint8_t level,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int after_valid, uint64_t after,
|
||||
uint8_t* buf, size_t* len, uint64_t* next, int* more) {
|
||||
static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int after_valid, const merkle_key_t* after,
|
||||
uint8_t* buf, size_t* len, merkle_key_t* next, int* more) {
|
||||
struct UTUN_INSTANCE* inst = (struct UTUN_INSTANCE*)ctx;
|
||||
sqlite3* db = _db(inst); if (!db || !buf || !len) { DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: get_items — invalid args db=%p buf=%p len=%p", MS_ID, (void*)db, (void*)buf, (void*)len); return -1; }
|
||||
const uint8_t level = MT_MAX_LEVEL;
|
||||
*next = 0; *more = 0;
|
||||
memset(next, 0, sizeof(*next)); *more = 0;
|
||||
uint64_t after_id = member_read64(after->bytes);
|
||||
static const uint8_t zero_tail[MT_KEY_SIZE - 8];
|
||||
if (after_valid && memcmp(after->bytes + 8, zero_tail, sizeof(zero_tail))) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: invalid member cursor ns=%s", MS_ID, ns); return -1;
|
||||
}
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_MEMBER_SYNC, "%s: get_items ns=%s L%d/P%016llx", MS_ID, ns, level, (unsigned long long)prefix);
|
||||
char peers_tbl[128]; _peers_table(ns, peers_tbl, sizeof(peers_tbl));
|
||||
|
||||
@@ -227,7 +232,7 @@ static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int afte
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) { DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: get_items prepare failed ns=%s", MS_ID, ns); return -1; }
|
||||
sqlite3_bind_int(stmt, 1, after_valid);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)after);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)after_id);
|
||||
|
||||
size_t off = 0;
|
||||
if (off + 2 > *len) { sqlite3_finalize(stmt); return -2; }
|
||||
@@ -290,7 +295,7 @@ static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int afte
|
||||
if (sgn && sqlite3_column_bytes(stmt, 11) >= 64) { memcpy(buf + off, sgn, 64); off += 64; }
|
||||
else { memset(buf + off, 0, 64); off += 64; }
|
||||
cnt++;
|
||||
*next = nid;
|
||||
member_write64(next->bytes, nid);
|
||||
}
|
||||
if (step != SQLITE_DONE && !*more) { DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: page read failed ns=%s: %s", MS_ID, ns, sqlite3_errmsg(db)); sqlite3_finalize(stmt); return -1; }
|
||||
sqlite3_finalize(stmt);
|
||||
@@ -694,7 +699,7 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
|
||||
|
||||
/* ── recompute и подтвердить реальное изменение по хешу ── */
|
||||
if (changed) {
|
||||
int rc = merkle_sync_recompute_path(inst, ch_id, m->node_id);
|
||||
int rc = merkle_sync_recompute_path(inst, MT_DATA_MEMBERS, MT_DATA_MEMBERS, MT_DATA_MEMBERS, ch_id, m->node_id);
|
||||
if (rc < 0) return -1;
|
||||
if (rc == 0) changed = 0; /* запись была no-op (данные идентичны) */
|
||||
}
|
||||
@@ -705,7 +710,7 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
|
||||
}
|
||||
|
||||
static void member_committed(struct UTUN_INSTANCE* inst, const char* ns, uint64_t node_id) {
|
||||
merkle_sync_changed(inst, ns);
|
||||
merkle_sync_changed(inst, MT_DATA_MEMBERS, ns);
|
||||
struct TOPO_GROUP* g = inst->topo_groups ? topo_groups_find(inst->topo_groups, strtoull(ns, NULL, 10)) : NULL;
|
||||
struct ETCP_CONN* conn = instance_find_conn(inst, node_id);
|
||||
if (g && g->group_type == TOPO_GROUP_TYPE_CHAT) {
|
||||
@@ -1131,11 +1136,11 @@ void member_sync_destroy(struct UTUN_INSTANCE* inst) {
|
||||
int member_sync_start(struct UTUN_INSTANCE* inst, uint64_t peer,
|
||||
const char* ch_id, merkle_sync_done_cb done_cb, void* arg) {
|
||||
member_sync_verify_and_purge(inst, ch_id);
|
||||
return merkle_sync_start(inst, peer, ch_id, done_cb, arg);
|
||||
return merkle_sync_start(inst, MT_DATA_MEMBERS, peer, ch_id, done_cb, arg);
|
||||
}
|
||||
|
||||
void member_sync_cancel(struct UTUN_INSTANCE* inst, uint64_t peer, const char* ch_id) {
|
||||
merkle_sync_cancel(inst, peer, ch_id);
|
||||
merkle_sync_cancel(inst, MT_DATA_MEMBERS, peer, ch_id);
|
||||
}
|
||||
|
||||
void member_sync_cancel_channel(struct UTUN_INSTANCE* inst, const char* ch_id) {
|
||||
|
||||
Reference in new issue
Block a user