From a7346c25e3a03fa8ce022ce033da57cd210085d7 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 22 Jul 2026 12:03:57 +0300 Subject: [PATCH] fix chatgui: members not showing (schema mismatch) and username showing JSON instead of name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - topo_node_sqlite_member_put: remove joined_at column from INSERT (not in server schema, duplicates join_ts) - chat_core: rename peers table column name→userinfo to match server schema + add ALTER TABLE migration - chat_sync: remove 3 redundant INSERT INTO nodes that wrote raw JSON userinfo into nodes.name, overwriting correct plain name from topo_node_sqlite_node_update_verified --- src/routing_layer/topo_node_sqlite.c | 17 +++++----- tools/chatgui/transport/chat_core.c | 6 +++- tools/chatgui/transport/chat_sync.c | 47 ---------------------------- 3 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/routing_layer/topo_node_sqlite.c b/src/routing_layer/topo_node_sqlite.c index 0941fdc6..32766311 100644 --- a/src/routing_layer/topo_node_sqlite.c +++ b/src/routing_layer/topo_node_sqlite.c @@ -319,8 +319,8 @@ int topo_node_sqlite_member_put(sqlite3* db, const char* channel_id, uint64_t no char sql[256]; snprintf(sql, sizeof(sql), "INSERT OR REPLACE INTO \"%s\"(node_id, x25519_pubkey, ed25519_pubkey," - " join_sig, join_ts, joined_at, update_sig, update_ts, userinfo, creator_sig)" - " VALUES(?,?,?,?,?,?,?,?,?,?)", peers_tbl); + " join_sig, join_ts, update_sig, update_ts, userinfo, creator_sig)" + " VALUES(?,?,?,?,?,?,?,?,?)", peers_tbl); sqlite3_stmt* stmt = NULL; if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) return -1; sqlite3_bind_int64(stmt, 1, (sqlite3_int64)node_id); @@ -329,13 +329,12 @@ int topo_node_sqlite_member_put(sqlite3* db, const char* channel_id, uint64_t no if (join_sig) sqlite3_bind_blob(stmt, 4, join_sig, PEERS_JOIN_SIG_SIZE, SQLITE_STATIC); else { static const unsigned char zsig[PEERS_JOIN_SIG_SIZE] = {0}; sqlite3_bind_blob(stmt, 4, zsig, PEERS_JOIN_SIG_SIZE, SQLITE_STATIC); } sqlite3_bind_int64(stmt, 5, (sqlite3_int64)join_ts); - sqlite3_bind_int64(stmt, 6, (sqlite3_int64)join_ts); - if (update_sig) sqlite3_bind_blob(stmt, 7, update_sig, PEERS_UPDATE_SIG_SIZE, SQLITE_STATIC); - else sqlite3_bind_null(stmt, 7); - sqlite3_bind_int64(stmt, 8, (sqlite3_int64)update_ts); - sqlite3_bind_text(stmt, 9, userinfo ? userinfo : "", -1, SQLITE_STATIC); - if (creator_sig) sqlite3_bind_blob(stmt, 10, creator_sig, PEERS_JOIN_SIG_SIZE, SQLITE_STATIC); - else sqlite3_bind_null(stmt, 10); + if (update_sig) sqlite3_bind_blob(stmt, 6, update_sig, PEERS_UPDATE_SIG_SIZE, SQLITE_STATIC); + else sqlite3_bind_null(stmt, 6); + sqlite3_bind_int64(stmt, 7, (sqlite3_int64)update_ts); + sqlite3_bind_text(stmt, 8, userinfo ? userinfo : "", -1, SQLITE_STATIC); + if (creator_sig) sqlite3_bind_blob(stmt, 9, creator_sig, PEERS_JOIN_SIG_SIZE, SQLITE_STATIC); + else sqlite3_bind_null(stmt, 9); int rc = sqlite3_step(stmt); sqlite3_finalize(stmt); return rc == SQLITE_DONE ? 0 : -1; } diff --git a/tools/chatgui/transport/chat_core.c b/tools/chatgui/transport/chat_core.c index 9ace5fc5..efd52a5d 100644 --- a/tools/chatgui/transport/chat_core.c +++ b/tools/chatgui/transport/chat_core.c @@ -667,13 +667,17 @@ void chat_core_ensure_channel_ready(const char* ch_id) { " join_ts INTEGER DEFAULT 0," " update_sig BLOB," " update_ts INTEGER DEFAULT 0," - " name TEXT NOT NULL DEFAULT ''," + " userinfo TEXT NOT NULL DEFAULT ''," " creator_sig BLOB," " comment TEXT," " joined_at INTEGER DEFAULT (unixepoch())" ")", tbl_peers); db_exec(sql); + // Migration: rename old 'name' column to 'userinfo' (match server schema) + snprintf(sql, sizeof(sql), "ALTER TABLE \"%s\" RENAME COLUMN name TO userinfo", tbl_peers); + sqlite3_exec(g_cc.db, sql, NULL, NULL, NULL); + uint64_t ch_hash = 0; { const uint8_t* chd = (const uint8_t*)ch_id; size_t chl = strlen(ch_id); uint8_t sh[32]; SHA256(chd, chl, sh); memcpy(&ch_hash, sh, 8); } struct DB_SYNC_INSTANCE* si = db_sync_instance_add(g_cc.inst, tbl_msg, ch_hash); diff --git a/tools/chatgui/transport/chat_sync.c b/tools/chatgui/transport/chat_sync.c index 0839529d..fb59d7a3 100644 --- a/tools/chatgui/transport/chat_sync.c +++ b/tools/chatgui/transport/chat_sync.c @@ -1047,23 +1047,7 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer, DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: CHANNEL_INFO_RESP invalid inviter_update_sig peer=%016llx ts=%llu", CS_ID, (unsigned long long)peer, (unsigned long long)inviter_update_ts); } - /* save inviter node_info to local DB */ sqlite3* vdb = cs->inst->topo_sqlite_db; - if (vdb && inv_userinfo[0]) { - sqlite3_stmt* ns = NULL; - sqlite3_prepare_v2(vdb, - "INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" - " ON CONFLICT(node_id) DO UPDATE SET" - " name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," - " created_at=COALESCE(nodes.created_at, excluded.created_at)", - -1, &ns, NULL); - if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)peer); - sqlite3_bind_text(ns, 2, inv_userinfo, -1, SQLITE_STATIC); - sqlite3_bind_blob(ns, 3, inv_x25519, 32, SQLITE_STATIC); - sqlite3_bind_blob(ns, 4, inv_ed, 32, SQLITE_STATIC); - sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); - sqlite3_step(ns); sqlite3_finalize(ns); } - } /* save inviter's address from ETCP connection */ { DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: [ADDR_SYNC] INFO_RESP save inviter peer=%016llx", CS_ID, (unsigned long long)peer); struct ETCP_LINK* lk = inv_conn->links; @@ -1210,22 +1194,6 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer, { char j_name[128]; json_flat_get(joiner_userinfo, "name", j_name, sizeof(j_name)); topo_node_sqlite_node_update_verified(db, node_id, j_name, x25519, ed_pub, join_ts, ntp_time_get_seconds(cs->inst)); } chat_conn_mgr_add_node(chat_conn_mgr_get(), node_id); - /* save joiner node_info to local DB */ - if (db && joiner_userinfo[0]) { - sqlite3_stmt* ns = NULL; - sqlite3_prepare_v2(db, - "INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" - " ON CONFLICT(node_id) DO UPDATE SET" - " name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," - " created_at=COALESCE(nodes.created_at, excluded.created_at)", - -1, &ns, NULL); - if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)node_id); - sqlite3_bind_text(ns, 2, joiner_userinfo, -1, SQLITE_STATIC); - sqlite3_bind_blob(ns, 3, x25519, 32, SQLITE_STATIC); - sqlite3_bind_blob(ns, 4, ed_pub, 32, SQLITE_STATIC); - sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); - sqlite3_step(ns); sqlite3_finalize(ns); } - } /* save/update node addresses */ DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: [ADDR_SYNC] JOIN save addrs node=0x%016llx addr_cnt=%d", CS_ID, (unsigned long long)node_id, addr_cnt); @@ -1488,21 +1456,6 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer, { char pn2[128]; json_flat_get(peer_userinfo, "name", pn2, sizeof(pn2)); topo_node_sqlite_node_update_verified(db, node_id, pn2, x25519, ed_pub, join_ts, ntp_time_get_seconds(cs->inst)); } chat_conn_mgr_add_node(chat_conn_mgr_get(), node_id); - if (db && peer_userinfo[0]) { - sqlite3_stmt* ns = NULL; - sqlite3_prepare_v2(db, - "INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" - " ON CONFLICT(node_id) DO UPDATE SET" - " name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," - " created_at=COALESCE(nodes.created_at, excluded.created_at)", - -1, &ns, NULL); - if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)node_id); - sqlite3_bind_text(ns, 2, peer_userinfo, -1, SQLITE_STATIC); - sqlite3_bind_blob(ns, 3, x25519, 32, SQLITE_STATIC); - sqlite3_bind_blob(ns, 4, ed_pub, 32, SQLITE_STATIC); - sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); - sqlite3_step(ns); sqlite3_finalize(ns); } - } DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: [ADDR_SYNC] PEER_UPSERT save addrs node=0x%016llx ac=%d", CS_ID, (unsigned long long)node_id, ac); for (uint8_t i = 0; i < ac; i++) {