refactor: move sqlite3 db from topo_group to UTUN_INSTANCE, remove conn_mgr/topo_group deps from chatgui
- topo_sqlite_db moved from TOPO_GROUPS to UTUN_INSTANCE (direct access) - topo_groups_set_sqlite_db() removed - chatgui: chat_sync_connect_node → chat_core_connect_auto (direct ETCP, no conn_mgr) - chatgui: chat_core_connect_from_invite saves to SQLite → auto connect (no BGP) - chatgui: removed _on_node_updated BGP callback from member_sync - chatgui: removed conn_mgr_get_status from status dump - chatgui: removed all conn_mgr.h and topo_group.h includes - chatgui: CONN_MGR_ERR_* constants → CC_* in chat_core.h - removed unused cc_parallel_* code, conn_state_str/conn_type_str helpers
This commit is contained in:
1 parent
52587c4f2b
commit
6f4025e420
10 files changed
+94
-334
No files matched your search
+2
-2
@@ -369,8 +369,8 @@ static int db_chain_hash8_at(struct DB_SYNC_INSTANCE* si, uint32_t pos, uint64_t
|
||||
static int db_get_ed25519_pubkey(struct DB_SYNC* db, uint64_t node_id, uint8_t out[32])
|
||||
{
|
||||
if (node_id == db->inst->node_id) { memcpy(out, db->inst->my_ed25519_pubkey, 32); return 0; }
|
||||
if (db->inst->topo_groups && db->inst->topo_groups->topo_sqlite_db) {
|
||||
if (topo_node_sqlite_get_ed25519_pubkey(db->inst->topo_groups->topo_sqlite_db, node_id, out) == 0) return 0;
|
||||
if (db->inst->topo_sqlite_db) {
|
||||
if (topo_node_sqlite_get_ed25519_pubkey(db->inst->topo_sqlite_db, node_id, out) == 0) return 0;
|
||||
}
|
||||
struct ll_entry* e = queue_find_data_by_index(db->inst->connections, (const uint8_t*)&node_id);
|
||||
if (e) {
|
||||
|
||||
+11
-17
@@ -254,16 +254,16 @@ 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, &g->topo_sqlite_db);
|
||||
if (rc == SQLITE_OK && g->topo_sqlite_db) {
|
||||
sqlite3_exec(g->topo_sqlite_db, "PRAGMA journal_mode=WAL", NULL, NULL, NULL);
|
||||
sqlite3_exec(g->topo_sqlite_db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
|
||||
topo_node_sqlite_init(g->topo_sqlite_db);
|
||||
int rc = sqlite3_open(instance->config->global.db_path, &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);
|
||||
} else {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "sqlite3_open(%s) failed: %s",
|
||||
instance->config->global.db_path, g->topo_sqlite_db ? sqlite3_errmsg(g->topo_sqlite_db) : "null db");
|
||||
if (g->topo_sqlite_db) { sqlite3_close(g->topo_sqlite_db); g->topo_sqlite_db = NULL; }
|
||||
instance->config->global.db_path, 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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ void topo_groups_destroy(struct UTUN_INSTANCE* instance) {
|
||||
memory_pool_destroy(g->v4_subnet_pool);
|
||||
memory_pool_destroy(g->v6_subnet_pool);
|
||||
|
||||
if (g->topo_sqlite_db) { sqlite3_close(g->topo_sqlite_db); g->topo_sqlite_db = NULL; }
|
||||
if (instance->topo_sqlite_db) { sqlite3_close(instance->topo_sqlite_db); instance->topo_sqlite_db = NULL; }
|
||||
|
||||
u_free(g); instance->topo_groups = NULL;
|
||||
}
|
||||
@@ -340,12 +340,6 @@ struct TOPO_GROUP* topo_groups_create_group(struct TOPO_GROUPS* g, uint64_t grou
|
||||
return group;
|
||||
}
|
||||
|
||||
void topo_groups_set_sqlite_db(struct TOPO_GROUPS* g, sqlite3* db) {
|
||||
if (!g) return;
|
||||
g->topo_sqlite_db = db;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "topo_sqlite_db set");
|
||||
}
|
||||
|
||||
void topo_group_set_nat_check_local(struct TOPO_GROUP* group, int allow) {
|
||||
if (!group || !group->instance || !group->instance->nat_det) return;
|
||||
nat_detection_set_allow_local(group->instance->nat_det, allow);
|
||||
@@ -587,7 +581,7 @@ int topo_group_process_nodeinfo(struct TOPO_GROUP* group, struct ETCP_CONN* from
|
||||
|
||||
if (group->group_type != TOPO_GROUP_TYPE_CHAT && group->instance->rt) route_insert(group->instance->rt, nodeinfo1);
|
||||
if (node_id != group->instance->node_id) {
|
||||
sqlite3* sdb = group->instance->topo_groups->topo_sqlite_db;
|
||||
sqlite3* sdb = group->instance->topo_sqlite_db;
|
||||
if (sdb) {
|
||||
topo_node_sqlite_node_put(sdb, nodeinfo1);
|
||||
if (group->group_type == TOPO_GROUP_TYPE_CHAT && group->channel_id[0]) {
|
||||
@@ -646,8 +640,8 @@ int topo_group_process_withdraw(struct TOPO_GROUP* group, struct ETCP_CONN* send
|
||||
struct ll_entry* entry = queue_find_data_by_index(group->nodes, &node_id);
|
||||
if (entry) { queue_remove_data(group->nodes, entry); queue_entry_free(entry); }
|
||||
topo_group_broadcast_withdraw(group, node_id, wd_source, sender);
|
||||
if (group->group_type == TOPO_GROUP_TYPE_CHAT && group->instance->topo_groups->topo_sqlite_db)
|
||||
topo_node_sqlite_member_del(group->instance->topo_groups->topo_sqlite_db, group->channel_id, node_id);
|
||||
if (group->group_type == TOPO_GROUP_TYPE_CHAT && group->instance->topo_sqlite_db)
|
||||
topo_node_sqlite_member_del(group->instance->topo_sqlite_db, group->channel_id, node_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,6 @@ struct TOPO_GROUPS {
|
||||
struct memory_pool* v6_addr_pool;
|
||||
struct memory_pool* v4_subnet_pool;
|
||||
struct memory_pool* v6_subnet_pool;
|
||||
sqlite3* topo_sqlite_db;
|
||||
topo_node_updated_fn node_updated_cb; /* optional — set by chatgui's member_sync */
|
||||
};
|
||||
|
||||
@@ -242,8 +241,6 @@ int topo_group_remove_path(struct TOPO_NODEQ* nq, struct ETCP_CONN* conn);
|
||||
|
||||
void topo_groups_set_node_updated_cb(struct TOPO_GROUPS* groups, topo_node_updated_fn fn);
|
||||
|
||||
void topo_groups_set_sqlite_db(struct TOPO_GROUPS* g, sqlite3* db);
|
||||
|
||||
/** Разрешить/запретить NAT check для локальных подсетей (тестовый хелпер, делегат в nat_detection) */
|
||||
void topo_group_set_nat_check_local(struct TOPO_GROUP* group, int allow);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "../lib/memory_pool.h"
|
||||
#include "../lib/sqlite3.h"
|
||||
#include "secure_channel.h"
|
||||
#include "etcp_api.h"
|
||||
#include "config_parser.h"
|
||||
@@ -75,6 +76,7 @@ struct UTUN_INSTANCE {
|
||||
|
||||
struct ROUTE_TABLE* rt;
|
||||
struct TOPO_GROUPS* topo_groups; // Groups module for topology exchange
|
||||
sqlite3* topo_sqlite_db; // Shared SQLite DB (nodes/channels/peers)
|
||||
struct NAT_DETECTION* nat_det; // NAT detection module
|
||||
|
||||
// Identification
|
||||
|
||||
Reference in new issue
Block a user