Browse Source
- src/db_sync: LMDB replaced with SQLite (separate tables per instance: db_sync_name_id) TTL index (author, timestamp), WAL mode, per-instance peers/timers opaque DB_SYNC_INSTANCE* handle, insert callback, select API new fields: author_signature, delivered_peers, delivery_chain transport: etcp_api direct P2P (was etcp_router) - src/db_sync.h: user-oriented API docs, multi-instance lifecycle - lib/Makefile.am: liblmdb sources removed - lib/sqlite3.c+h: SQLite amalgamation added - topo_node: LMDB→SQLite (src/topo_node_sqlite.c moved from chatgui) - chatgui: real db_sync.c replaces db_sync_stub.c chat_core: db_sync_insert_signed + dual-write insert callback utun_node: db_sync_init/destroy replaces chat_sync_init/destroy CMakeLists: stubs removed, real db_sync.c addedtopo_upd
21 changed files with 284332 additions and 1178 deletions
@ -1,66 +0,0 @@
|
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <stdint.h> |
||||
#include <sys/stat.h> |
||||
#include "topo_node_lmdb.h" |
||||
#include "topo_group.h" |
||||
#include "../lib/debug_config.h" |
||||
#include "../lib/mem.h" |
||||
|
||||
#define NODEINFO_DB_MAPSIZE (10UL * 1024 * 1024) |
||||
|
||||
int topo_node_lmdb_init(struct TOPO_GROUP* bgp, const char* db_path) { |
||||
if (!bgp || !db_path || !db_path[0]) return -1; |
||||
int rc = mdb_env_create(&bgp->nodeinfo_env); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_env_create failed: %s", mdb_strerror(rc)); return -1; } |
||||
rc = mdb_env_set_mapsize(bgp->nodeinfo_env, NODEINFO_DB_MAPSIZE); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_env_set_mapsize failed: %s", mdb_strerror(rc)); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
rc = mdb_env_set_maxdbs(bgp->nodeinfo_env, 2); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_env_set_maxdbs failed: %s", mdb_strerror(rc)); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
rc = mdb_env_open(bgp->nodeinfo_env, db_path, 0, 0644); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_env_open(%s) failed: %s", db_path, mdb_strerror(rc)); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
MDB_txn* txn = NULL; rc = mdb_txn_begin(bgp->nodeinfo_env, NULL, 0, &txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_txn_begin failed: %s", mdb_strerror(rc)); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
rc = mdb_dbi_open(txn, "nodeinfo", MDB_CREATE, &bgp->nodeinfo_dbi); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_dbi_open(nodeinfo) failed: %s", mdb_strerror(rc)); mdb_txn_abort(txn); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
rc = mdb_txn_commit(txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_txn_commit failed: %s", mdb_strerror(rc)); mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; return -1; } |
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "LMDB nodeinfo database opened: %s", db_path); |
||||
return 0; |
||||
} |
||||
|
||||
void topo_node_lmdb_destroy(struct TOPO_GROUP* bgp) { |
||||
if (!bgp) return; |
||||
if (bgp->nodeinfo_env) { mdb_env_close(bgp->nodeinfo_env); bgp->nodeinfo_env = NULL; DEBUG_INFO(DEBUG_CATEGORY_BGP, "LMDB nodeinfo database closed"); } |
||||
} |
||||
|
||||
int topo_node_lmdb_put(struct TOPO_GROUP* bgp, struct TOPO_NODEQ* nq) { |
||||
if (!bgp || !bgp->nodeinfo_env || !nq || !nq->node) return -1; |
||||
uint8_t buf[8192]; |
||||
int ser_len = topo_node_serialize(bgp, nq, buf, sizeof(buf)); |
||||
if (ser_len < 0) return -1; |
||||
|
||||
MDB_val key, data; |
||||
key.mv_size = 8; key.mv_data = &nq->node->node_id; |
||||
data.mv_size = (size_t)ser_len; data.mv_data = buf; |
||||
|
||||
MDB_txn* txn = NULL; int rc = mdb_txn_begin(bgp->nodeinfo_env, NULL, 0, &txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB put mdb_txn_begin failed: %s", mdb_strerror(rc)); return -1; } |
||||
rc = mdb_put(txn, bgp->nodeinfo_dbi, &key, &data, 0); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_put node %016llx failed: %s", (unsigned long long)nq->node->node_id, mdb_strerror(rc)); mdb_txn_abort(txn); return -1; } |
||||
rc = mdb_txn_commit(txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB put mdb_txn_commit failed: %s", mdb_strerror(rc)); return -1; } |
||||
return 0; |
||||
} |
||||
|
||||
int topo_node_lmdb_del(struct TOPO_GROUP* bgp, uint64_t node_id) { |
||||
if (!bgp || !bgp->nodeinfo_env) return -1; |
||||
MDB_val key; key.mv_size = 8; key.mv_data = &node_id; |
||||
MDB_txn* txn = NULL; int rc = mdb_txn_begin(bgp->nodeinfo_env, NULL, 0, &txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB del mdb_txn_begin failed: %s", mdb_strerror(rc)); return -1; } |
||||
rc = mdb_del(txn, bgp->nodeinfo_dbi, &key, NULL); |
||||
if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB mdb_del node %016llx failed: %s", (unsigned long long)node_id, mdb_strerror(rc)); mdb_txn_abort(txn); return -1; } |
||||
rc = mdb_txn_commit(txn); |
||||
if (rc != MDB_SUCCESS) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "LMDB del mdb_txn_commit failed: %s", mdb_strerror(rc)); return -1; } |
||||
return 0; |
||||
} |
||||
@ -1,23 +0,0 @@
|
||||
#ifndef TOPO_NODE_LMDB_H |
||||
#define TOPO_NODE_LMDB_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
#include <stdint.h> |
||||
#include "topo_node.h" |
||||
|
||||
struct TOPO_GROUP; |
||||
|
||||
int topo_node_lmdb_init(struct TOPO_GROUP* group, const char* db_path); |
||||
void topo_node_lmdb_destroy(struct TOPO_GROUP* group); |
||||
int topo_node_lmdb_put(struct TOPO_GROUP* group, struct TOPO_NODEQ* nq); |
||||
int topo_node_lmdb_del(struct TOPO_GROUP* group, uint64_t node_id); |
||||
|
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif |
||||
@ -1,6 +1,6 @@
|
||||
#include "topo_node_sqlite.h" |
||||
#include "../../../src/topo_node.h" |
||||
#include "../../../lib/debug_config.h" |
||||
#include "topo_node.h" |
||||
#include "../lib/debug_config.h" |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
|
||||
Loading…
Reference in new issue