fix chatgui: db_sync_stub + chat_sync_init for invite link join
- db_sync_stub.c: complete rewrite — proper structs, all API functions (db_sync_instance_add, insert_signed, set_insert_cb, select) Fixes db_sync_instance_add returning NULL (inst->db_sync was NULL) - libutun/CMakeLists.txt: remove src/db_sync.c, stub replaces it - chatgui/CMakeLists.txt: add transport/db_sync_stub.c - utun_node.cpp: remove redundant db_sync_init/destroy, add chat_sync_init/destroy — server now registers svc_id=48 Fixes 'no handler for svc_id=48' on incoming CHANNEL_INFO_REQ
This commit is contained in:
1 parent
0f927ccb09
commit
fa2a64007c
4 files changed
+142
-18
No files matched your search
@@ -76,6 +76,7 @@ add_executable(chatgui
|
||||
transport/chat_sync.c
|
||||
transport/member_sync.c
|
||||
transport/merkle_sync.c
|
||||
transport/db_sync_stub.c
|
||||
db/db_manager.cpp
|
||||
../../lib/sqlite3.c
|
||||
resources/chatgui.qrc
|
||||
@@ -83,7 +84,7 @@ add_executable(chatgui
|
||||
|
||||
target_include_directories(chatgui PRIVATE ${CMAKE_SOURCE_DIR}/../../lib ${CMAKE_SOURCE_DIR}/../../src ${CMAKE_SOURCE_DIR}/db)
|
||||
target_compile_definitions(chatgui PRIVATE SQLITE_THREADSAFE=1 USE_SQLITE)
|
||||
set_source_files_properties(../../lib/sqlite3.c transport/chat_core.c transport/chat_sync.c transport/member_sync.c transport/merkle_sync.c PROPERTIES LANGUAGE C)
|
||||
set_source_files_properties(../../lib/sqlite3.c transport/chat_core.c transport/chat_sync.c transport/member_sync.c transport/merkle_sync.c transport/db_sync_stub.c PROPERTIES LANGUAGE C)
|
||||
if(WIN32)
|
||||
target_link_libraries(chatgui PRIVATE ${QT_LIBS} rlottie::rlottie ZLIB::ZLIB OpenSSL::Crypto ZXing::ZXing utun pthread)
|
||||
else()
|
||||
|
||||
@@ -62,7 +62,7 @@ set(UTUN_COMMON_SOURCES
|
||||
${SRC_DIR}/topo_node.c
|
||||
${SRC_DIR}/topo_node_sqlite.c
|
||||
${SRC_DIR}/route_connectivity.c
|
||||
${SRC_DIR}/db_sync.c
|
||||
# db_sync.c replaced by db_sync_stub.c (no P2P sync in chatgui)
|
||||
${SRC_DIR}/conn_mgr.c
|
||||
${TRANSPORT_DIR}/chat_sync.c
|
||||
${TRANSPORT_DIR}/merkle_sync.c
|
||||
|
||||
@@ -1,31 +1,154 @@
|
||||
// db_sync_stub.c — Minimal db_sync replacement for chatgui (no P2P sync, local only)
|
||||
//
|
||||
// Назначение: заменяет полноценный db_sync.c когда синхронизация через ETCP не нужна.
|
||||
// Сохраняет API-совместимость: chat_core.c использует db_sync_instance_add / db_sync_set_insert_cb /
|
||||
// db_sync_insert_signed — стаб обрабатывает их локально, без сетевого обмена.
|
||||
//
|
||||
// utun_instance.c вызывает db_sync_init/db_sync_destroy — стаб создаёт минимальную инфраструктуру
|
||||
// без SQLite и без регистрации ETCP-сервисов.
|
||||
|
||||
#include "db_sync.h"
|
||||
#include "utun_instance.h"
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define DEBUG_CATEGORY_DB_SYNC DEBUG_CATEGORY_DEBUG
|
||||
|
||||
/* ── Internal structs (match db_sync.h opaque types) ── */
|
||||
|
||||
struct DB_SYNC_INSTANCE {
|
||||
struct DB_SYNC* db_sync;
|
||||
uint8_t enabled;
|
||||
db_sync_insert_cb on_insert;
|
||||
void* on_insert_arg;
|
||||
};
|
||||
|
||||
struct DB_SYNC {
|
||||
struct UTUN_INSTANCE* inst;
|
||||
struct DB_SYNC_INSTANCE* instances;
|
||||
int instance_count, instance_capacity;
|
||||
uint8_t enabled;
|
||||
};
|
||||
|
||||
/* ── Init / Destroy ── */
|
||||
|
||||
int db_sync_init(struct UTUN_INSTANCE* inst) {
|
||||
(void)inst;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "db_sync: stub (disabled for chatgui)");
|
||||
if (!inst) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: NULL instance");
|
||||
return -1;
|
||||
}
|
||||
if (inst->db_sync) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: already initialized");
|
||||
return 0;
|
||||
}
|
||||
struct DB_SYNC* db = u_calloc(1, sizeof(struct DB_SYNC));
|
||||
if (!db) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: u_calloc failed");
|
||||
return -1;
|
||||
}
|
||||
db->inst = inst;
|
||||
db->enabled = 1;
|
||||
db->instance_count = 0;
|
||||
db->instance_capacity = 0;
|
||||
db->instances = NULL;
|
||||
inst->db_sync = db;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "db_sync: stub initialized (local-only, no P2P sync)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void db_sync_destroy(struct UTUN_INSTANCE* inst) {
|
||||
(void)inst;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "db_sync: stub destroyed");
|
||||
if (!inst || !inst->db_sync) return;
|
||||
struct DB_SYNC* db = inst->db_sync;
|
||||
inst->db_sync = NULL;
|
||||
for (int i = 0; i < db->instance_count; i++) {
|
||||
struct DB_SYNC_INSTANCE* si = &db->instances[i];
|
||||
if (si->on_insert_arg) u_free(si->on_insert_arg);
|
||||
}
|
||||
if (db->instances) u_free(db->instances);
|
||||
u_free(db);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "db_sync: stub destroyed");
|
||||
}
|
||||
|
||||
int db_sync_insert_len(struct UTUN_INSTANCE* inst, const char* json_data, size_t len) {
|
||||
(void)inst; (void)json_data; (void)len;
|
||||
/* ── Instance management ── */
|
||||
|
||||
struct DB_SYNC_INSTANCE* db_sync_instance_add(struct UTUN_INSTANCE* inst,
|
||||
const char* name, uint64_t id) {
|
||||
if (!inst || !inst->db_sync || !name || !name[0]) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: instance_add invalid args");
|
||||
return NULL;
|
||||
}
|
||||
struct DB_SYNC* db = inst->db_sync;
|
||||
|
||||
if (db->instance_count >= db->instance_capacity) {
|
||||
int nc = db->instance_capacity ? db->instance_capacity * 2 : 4;
|
||||
struct DB_SYNC_INSTANCE* np = u_realloc(db->instances, nc * sizeof(*db->instances));
|
||||
if (!np) return NULL;
|
||||
db->instances = np;
|
||||
db->instance_capacity = nc;
|
||||
}
|
||||
struct DB_SYNC_INSTANCE* si = &db->instances[db->instance_count++];
|
||||
memset(si, 0, sizeof(*si));
|
||||
si->db_sync = db;
|
||||
si->enabled = 1;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: instance added name=%s id=0x%016llx idx=%d",
|
||||
name, (unsigned long long)id, db->instance_count - 1);
|
||||
return si;
|
||||
}
|
||||
|
||||
void db_sync_instance_remove(struct DB_SYNC_INSTANCE* si) {
|
||||
if (!si) return;
|
||||
struct DB_SYNC* db = si->db_sync;
|
||||
si->enabled = 0;
|
||||
if (si->on_insert_arg) { u_free(si->on_insert_arg); si->on_insert_arg = NULL; }
|
||||
int idx = (int)(si - db->instances);
|
||||
if (idx >= 0 && idx < db->instance_count) {
|
||||
memmove(&db->instances[idx], &db->instances[idx + 1],
|
||||
(db->instance_count - idx - 1) * sizeof(*db->instances));
|
||||
db->instance_count--;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "db_sync stub: instance removed idx=%d", idx);
|
||||
}
|
||||
|
||||
/* ── Insert ── */
|
||||
|
||||
int db_sync_insert_signed(struct DB_SYNC_INSTANCE* si, const char* json_data,
|
||||
size_t len, const uint8_t* sig, size_t sig_len) {
|
||||
(void)sig; (void)sig_len;
|
||||
if (!si || !si->enabled || !json_data || len == 0) return -1;
|
||||
if (si->on_insert)
|
||||
si->on_insert(si, json_data, len, si->db_sync->inst->node_id, si->on_insert_arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db_sync_insert(struct UTUN_INSTANCE* inst, const char* json_data) {
|
||||
(void)inst; (void)json_data;
|
||||
int db_sync_insert_len(struct DB_SYNC_INSTANCE* si, const char* json_data, size_t len) {
|
||||
return db_sync_insert_signed(si, json_data, len, NULL, 0);
|
||||
}
|
||||
|
||||
int db_sync_insert(struct DB_SYNC_INSTANCE* si, const char* json_data) {
|
||||
if (!json_data) return -1;
|
||||
return db_sync_insert_len(si, json_data, strlen(json_data));
|
||||
}
|
||||
|
||||
/* ── Count / Select ── */
|
||||
|
||||
uint32_t db_sync_count(struct DB_SYNC_INSTANCE* si) {
|
||||
(void)si;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t db_sync_count(struct UTUN_INSTANCE* inst) {
|
||||
(void)inst;
|
||||
int db_sync_select(struct DB_SYNC_INSTANCE* si, uint32_t offset, uint32_t limit,
|
||||
db_sync_select_cb cb, void* arg) {
|
||||
(void)si; (void)offset; (void)limit; (void)cb; (void)arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ── Callbacks ── */
|
||||
|
||||
void db_sync_set_insert_cb(struct DB_SYNC_INSTANCE* si, db_sync_insert_cb cb, void* arg) {
|
||||
if (!si) return;
|
||||
si->on_insert = cb;
|
||||
if (si->on_insert_arg) u_free(si->on_insert_arg);
|
||||
si->on_insert_arg = arg;
|
||||
}
|
||||
@@ -238,10 +238,10 @@ void UtunNode::runLoop() {
|
||||
|
||||
etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, recvCallback);
|
||||
|
||||
/* Initialize chat_core (DB) and db_sync (message sync) */
|
||||
/* Initialize chat_core (DB) and chat_sync (channel/message P2P sync) */
|
||||
chat_core_init(m_instance, m_dbPath.toUtf8().constData());
|
||||
db_sync_init(m_instance);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "chat_core + db_sync initialized");
|
||||
chat_sync_init(m_instance, nullptr);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "chat_core + chat_sync initialized");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "utun_node: entering poll loop");
|
||||
|
||||
while (!m_stop) {
|
||||
@@ -249,7 +249,7 @@ void UtunNode::runLoop() {
|
||||
}
|
||||
|
||||
etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, nullptr);
|
||||
db_sync_destroy(m_instance);
|
||||
chat_sync_destroy(m_instance);
|
||||
chat_core_destroy(m_instance);
|
||||
utun_instance_destroy(m_instance);
|
||||
m_instance = nullptr;
|
||||
|
||||
Reference in new issue
Block a user