Browse Source

fix: sqlite3_open wrong path in topo_group.c (db_path vs db_path/chats.db), keep separate connections for perf

- topo_group.c: open {db_path}/chats.db instead of {db_path} — was opening a directory
- chat_core.c: remove inst->topo_sqlite_db = g_cc.db — keep topo_sqlite_db as separate
  uTun-only connection without FULLMUTEX, avoiding contention with GUI reads
topo_upd
Evgeny 3 months ago
parent
commit
3aadaa3396
  1. 8
      src/topo_group.c
  2. 1
      tools/chatgui/transport/chat_core.c

8
src/topo_group.c

@ -254,15 +254,17 @@ struct TOPO_GROUPS* topo_groups_init(struct UTUN_INSTANCE* instance) {
g->v6_subnet_pool = memory_pool_init(sizeof(struct TOPO_SUBNET6), "to_v6sub");
if (instance->config && instance->config->global.db_path[0]) {
int rc = sqlite3_open(instance->config->global.db_path, &instance->topo_sqlite_db);
char db_file[512];
snprintf(db_file, sizeof(db_file), "%s/chats.db", instance->config->global.db_path);
int rc = sqlite3_open(db_file, &instance->topo_sqlite_db);
if (rc == SQLITE_OK && instance->topo_sqlite_db) {
sqlite3_exec(instance->topo_sqlite_db, "PRAGMA journal_mode=WAL", NULL, NULL, NULL);
sqlite3_exec(instance->topo_sqlite_db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
topo_node_sqlite_init(instance->topo_sqlite_db);
DEBUG_INFO(DEBUG_CATEGORY_BGP, "SQLite opened: %s", instance->config->global.db_path);
DEBUG_INFO(DEBUG_CATEGORY_BGP, "SQLite opened: %s", db_file);
} else {
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "sqlite3_open(%s) failed: %s",
instance->config->global.db_path, instance->topo_sqlite_db ? sqlite3_errmsg(instance->topo_sqlite_db) : "null db");
db_file, instance->topo_sqlite_db ? sqlite3_errmsg(instance->topo_sqlite_db) : "null db");
if (instance->topo_sqlite_db) { sqlite3_close(instance->topo_sqlite_db); instance->topo_sqlite_db = NULL; }
}
}

1
tools/chatgui/transport/chat_core.c

@ -105,7 +105,6 @@ int chat_core_init(struct UTUN_INSTANCE* inst, const char* db_path) {
g_cc.my_node_id = inst->node_id;
topo_node_sqlite_init(g_cc.db);
inst->topo_sqlite_db = g_cc.db;
/* записать себя в nodes + local_identity с реальным node_id и именем */
{

Loading…
Cancel
Save