Browse Source

fix: peers table schema mismatch causing silent member write failures

chat_core_ensure_channel_ready() created peers_<ch_id> with 7 columns
while topo_node_sqlite_member_put() INSERT expected 9 (name, creator_sig).
Fixed schema alignment + reordered calls in create_channel() so
topo_node_sqlite_channel_put() (full 11-column schema) runs first.
Added error logging to all 6 member_put/member_sync_put call sites.
topo_upd
Evgeny 3 months ago
parent
commit
8180676120
  1. 27
      tools/chatgui/transport/chat_core.c
  2. 12
      tools/chatgui/transport/chat_sync.c
  3. 7
      tools/chatgui/transport/member_sync.c

27
tools/chatgui/transport/chat_core.c

@ -283,10 +283,12 @@ void chat_core_update_my_name(const char* name) {
}
EVP_PKEY_free(pkey);
}
topo_node_sqlite_member_put(g_cc.db, ch, myid, new_sig, join_ts, NULL, 0,
int r1 = topo_node_sqlite_member_put(g_cc.db, ch, myid, new_sig, join_ts, NULL, 0,
g_cc.inst->my_keys.public_key, g_cc.inst->my_ed25519_pubkey, name, NULL);
member_sync_put(g_cc.inst, ch, myid, g_cc.inst->my_keys.public_key,
g_cc.inst->my_ed25519_pubkey, new_sig, join_ts, NULL, 0, name, NULL, 0);
if (r1 != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put(my_name) FAILED ch=%s rc=%d", CC_ID, ch, r1);
int r2 = member_sync_put(g_cc.inst, ch, myid, g_cc.inst->my_keys.public_key,
g_cc.inst->my_ed25519_pubkey, new_sig, join_ts, NULL, 0, name, NULL, 0);
if (r2 != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_sync_put(my_name) FAILED ch=%s rc=%d", CC_ID, ch, r2);
uint8_t evt[65]; uint8_t cl = (uint8_t)strlen(ch);
evt[0] = cl; memcpy(evt + 1, ch, cl);
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1 + cl);
@ -1034,7 +1036,11 @@ void chat_core_ensure_channel_ready(const char* ch_id) {
" join_sig BLOB,"
" join_ts INTEGER DEFAULT 0,"
" update_sig BLOB,"
" update_ts INTEGER DEFAULT 0"
" update_ts INTEGER DEFAULT 0,"
" name TEXT NOT NULL DEFAULT '',"
" creator_sig BLOB,"
" comment TEXT,"
" joined_at INTEGER DEFAULT (unixepoch())"
")", tbl_peers);
db_exec(sql);
@ -1065,9 +1071,7 @@ void chat_core_create_channel(struct chat_channel_create* req) {
DEBUG_INFO(DEBUG_CATEGORY_CONNECTIVITY, "%s: create_channel BEGIN ch=%s name=%s",
CC_ID, req->channel_id, req->name);
chat_core_ensure_channel_ready(req->channel_id);
/* записываем канал в БД */
/* записываем канал в БД ПЕРВЫМ — создаст полную схему peers_<ch_id> (11 колонок) */
int rc = topo_node_sqlite_channel_put(g_cc.db,
req->channel_id, req->name, req->is_dm, req->owner_node_id,
req->x25519_pubkey, req->x25519_privkey,
@ -1081,6 +1085,9 @@ void chat_core_create_channel(struct chat_channel_create* req) {
DEBUG_INFO(DEBUG_CATEGORY_CONNECTIVITY, "%s: channel_put OK ch=%s name=%s owner=0x%016llx",
CC_ID, req->channel_id, req->name, (unsigned long long)req->owner_node_id);
/* после полной схемы — готовим таблицы и db_sync */
chat_core_ensure_channel_ready(req->channel_id);
uint8_t ch_id_len = (uint8_t)strlen(req->channel_id);
uint8_t data[65];
data[0] = ch_id_len;
@ -1113,9 +1120,13 @@ void chat_core_create_channel(struct chat_channel_create* req) {
} else {
memset(join_sig, 0, 64);
}
member_sync_put(g_cc.inst, req->channel_id, myid,
int mrc = member_sync_put(g_cc.inst, req->channel_id, myid,
g_cc.inst->my_keys.public_key, g_cc.inst->my_ed25519_pubkey,
join_sig, join_ts, NULL, 0, g_cc.inst->name, NULL, 0);
if (mrc != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_sync_put(self) FAILED ch=%s rc=%d",
CC_ID, req->channel_id, mrc);
}
}
/* notify GUI — members already in DB, channel will show with self as participant */

12
tools/chatgui/transport/chat_sync.c

@ -945,7 +945,8 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
lk = lk->next;
}
}
topo_node_sqlite_member_put(vdb, ch_id, peer, inviter_join_sig, inviter_join_ts, inviter_update_sig, inviter_update_ts, inv_x25519, inv_ed, inv_name, inviter_join_sig);
int rc = topo_node_sqlite_member_put(vdb, ch_id, peer, inviter_join_sig, inviter_join_ts, inviter_update_sig, inviter_update_ts, inv_x25519, inv_ed, inv_name, inviter_join_sig);
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put(inviter) FAILED ch=%s peer=%016llx rc=%d", CS_ID, ch_id, (unsigned long long)peer, rc);
topo_node_sqlite_node_update_verified(vdb, peer, inv_name, inv_x25519, inv_ed, inviter_join_ts);
}
@ -1047,7 +1048,8 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
}
sqlite3* db = cs->inst->topo_groups->topo_sqlite_db;
topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, joiner_name, NULL);
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, joiner_name, NULL);
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put(joiner) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc);
topo_node_sqlite_node_update_verified(db, node_id, joiner_name, x25519, ed_pub, join_ts);
/* save joiner node_info to local DB */
if (db && joiner_name[0]) {
@ -1178,7 +1180,8 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer,
}
}
topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_name, NULL);
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_name, NULL);
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put(welcome) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc);
topo_node_sqlite_node_update_verified(db, node_id, peer_name, x25519, ed_pub, join_ts);
for (uint8_t j = 0; j < ac; j++) {
@ -1250,7 +1253,8 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer,
sqlite3* db = cs->inst->topo_groups->topo_sqlite_db;
topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_name, NULL);
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_name, NULL);
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put(peer_upsert) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc);
topo_node_sqlite_node_update_verified(db, node_id, peer_name, x25519, ed_pub, join_ts);
if (db && peer_name[0]) {
sqlite3_stmt* ns = NULL;

7
tools/chatgui/transport/member_sync.c

@ -345,9 +345,14 @@ int member_sync_put(struct UTUN_INSTANCE* inst, const char* ch_id,
if (!inst || !ch_id) return -1;
sqlite3* db = _db(inst); if (!db) return -1;
topo_node_sqlite_member_put(db, ch_id, member_id,
int rc = topo_node_sqlite_member_put(db, ch_id, member_id,
join_sig, join_ts, update_sig, update_ts,
x25519, ed25519, name, NULL);
if (rc != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: member_put FAILED ch=%s id=0x%016llx name=%s rc=%d",
MS_ID, ch_id, (unsigned long long)member_id, name ? name : "", rc);
return -1;
}
if (addrs_data && addr_count > 0) {
sqlite3_exec(db, "BEGIN", NULL, NULL, NULL);

Loading…
Cancel
Save