auto_connect: add DB dump diagnostics (node_addresses state, node existence, db path+status)
- chat_core.c: dump node_addresses total, per-node counts, nodes lookup before addr query - topo_group.c: log db path, rc, and db pointer after sqlite3_open
This commit is contained in:
1 parent
3aadaa3396
commit
a510cb0018
2 files changed
+26
-1
No files matched your search
+1
-1
@@ -261,7 +261,7 @@ struct TOPO_GROUPS* topo_groups_init(struct UTUN_INSTANCE* instance) {
|
||||
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", db_file);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SQLite opened: %s rc=%d db=%p", db_file, rc, (void*)instance->topo_sqlite_db);
|
||||
} else {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "sqlite3_open(%s) failed: %s",
|
||||
db_file, instance->topo_sqlite_db ? sqlite3_errmsg(instance->topo_sqlite_db) : "null db");
|
||||
|
||||
@@ -762,6 +762,31 @@ void chat_core_connect_auto(uint64_t node_id,
|
||||
return;
|
||||
}
|
||||
|
||||
/* ── DB state diagnostics ── */
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: auto_connect DIAG: looking for node=0x%016llx", CC_ID, (unsigned long long)node_id);
|
||||
{
|
||||
sqlite3_stmt* diag = NULL;
|
||||
if (sqlite3_prepare_v2(g_cc.db, "SELECT COUNT(*) FROM node_addresses", -1, &diag, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(diag) == SQLITE_ROW)
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: auto_connect DIAG: node_addresses total=%d", CC_ID, sqlite3_column_int(diag, 0));
|
||||
sqlite3_finalize(diag);
|
||||
}
|
||||
if (sqlite3_prepare_v2(g_cc.db, "SELECT node_id, COUNT(*) FROM node_addresses GROUP BY node_id", -1, &diag, NULL) == SQLITE_OK) {
|
||||
while (sqlite3_step(diag) == SQLITE_ROW)
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: auto_connect DIAG: node_addresses node=0x%016llx cnt=%d",
|
||||
CC_ID, (unsigned long long)sqlite3_column_int64(diag, 0), sqlite3_column_int(diag, 1));
|
||||
sqlite3_finalize(diag);
|
||||
}
|
||||
if (sqlite3_prepare_v2(g_cc.db, "SELECT node_id, name FROM nodes WHERE node_id=?", -1, &diag, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_int64(diag, 1, (sqlite3_int64)node_id);
|
||||
if (sqlite3_step(diag) == SQLITE_ROW)
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: auto_connect DIAG: node found in nodes table name=%s",
|
||||
CC_ID, sqlite3_column_text(diag, 1));
|
||||
else
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "%s: auto_connect DIAG: node NOT found in nodes table", CC_ID);
|
||||
sqlite3_finalize(diag);
|
||||
}
|
||||
}
|
||||
/* collect IPv4 addresses */
|
||||
struct { uint8_t addr[4]; uint16_t port; } addrs[16];
|
||||
int addr_count = 0;
|
||||
|
||||
Reference in new issue
Block a user