- conn_mgr_init(TOPO_GROUP* group) — работает внутри заданной группы - conn_mgr_connect_node: загрузка узла из SQLite если нет в BGP-таблице - topo_node_sqlite_node_load(): загрузка TOPO_NODE (ref=0) из БД - cm_start_phase_direct: db_loaded-ветка — перебор всех адресов без NAT-фильтра - cm_cleanup_db_node: удаление TOPO_NODEQ из группы при неудаче, только если нет путей - cm_start_phase_indirect: исправлено зависание при best_candidates==0 (cm_deliver_result) - conn_mgr_set_direct_timeout_ms(): конфигурируемый таймаут фазы DIRECT - conn_mgr_destroy до etcp_router_destroy (исправлен порядок) - test_conn_mgr: +2 сценария (DB-успех, DB-недоступен), проверка topo_group
71 lines
2.9 KiB
C
71 lines
2.9 KiB
C
#ifndef TOPO_NODE_SQLITE_H
|
|
#define TOPO_NODE_SQLITE_H
|
|
|
|
#include <sqlite3.h>
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <time.h>
|
|
|
|
struct TOPO_NODEQ;
|
|
struct TOPO_GROUPS;
|
|
|
|
#define PEERS_JOIN_SIG_SIZE 64
|
|
#define PEERS_JOIN_TS_SIZE 8
|
|
#define PEERS_UPDATE_SIG_SIZE 64
|
|
|
|
/* flags byte in wire format */
|
|
#define PEERS_FLAG_HAS_JOIN 0x01
|
|
|
|
int topo_node_sqlite_init(sqlite3* db);
|
|
|
|
int topo_node_sqlite_node_put(sqlite3* db, struct TOPO_NODEQ* nq, time_t now_sec);
|
|
|
|
int topo_node_sqlite_channel_put(sqlite3* db, const char* channel_id,
|
|
const char* name, uint64_t owner_node_id,
|
|
const uint8_t* x25519_pub, const uint8_t* x25519_priv,
|
|
const uint8_t* ed25519_pub, const uint8_t* ed25519_priv,
|
|
const uint8_t* signature);
|
|
|
|
int topo_node_sqlite_member_put(sqlite3* db, const char* channel_id, uint64_t node_id,
|
|
const uint8_t* join_sig, uint64_t join_ts,
|
|
const uint8_t* update_sig, uint64_t update_ts,
|
|
const uint8_t* x25519_pubkey, const uint8_t* ed25519_pubkey, const char* userinfo,
|
|
const uint8_t* creator_sig);
|
|
|
|
int topo_node_sqlite_member_get_join(sqlite3* db, const char* channel_id, uint64_t node_id,
|
|
uint8_t* join_sig_out, uint64_t* join_ts_out);
|
|
|
|
int topo_node_sqlite_member_del(sqlite3* db, const char* channel_id, uint64_t node_id);
|
|
|
|
int topo_node_sqlite_node_update_verified(sqlite3* db, uint64_t node_id,
|
|
const char* name, const uint8_t* x25519, const uint8_t* ed25519, uint64_t update_ts, time_t created_at);
|
|
|
|
int topo_node_sqlite_channel_get(sqlite3* db, const char* channel_id,
|
|
char* name_out, int name_sz, uint64_t* owner_node_id,
|
|
uint8_t* x25519_pub, uint8_t* ed25519_pub, uint8_t* signature);
|
|
|
|
int topo_node_sqlite_channel_peers_all(sqlite3* db, const char* channel_id,
|
|
uint8_t* buf, size_t buf_sz, size_t* out_len);
|
|
|
|
int topo_node_sqlite_node_set_online(sqlite3* db, uint64_t node_id, int online);
|
|
int topo_node_sqlite_node_get_online(sqlite3* db, uint64_t node_id);
|
|
int topo_node_sqlite_get_ed25519_pubkey(sqlite3* db, uint64_t node_id, uint8_t pubkey_out[32]);
|
|
|
|
/** Пересчитывает node_type во всех peers_* таблицах на основе addr_type из node_addresses */
|
|
int topo_node_sqlite_nodeinfo_updated(sqlite3* db, uint64_t node_id);
|
|
|
|
/** Обновляет RTT узла: node_addresses.rtt и все peers_*.node_RTT */
|
|
void topo_node_sqlite_update_rtt(sqlite3* db, uint64_t node_id, uint16_t rtt);
|
|
|
|
/**
|
|
* @brief Загружает TOPO_NODE из SQLite (ref_count=0).
|
|
* @param groups нужен для выделения адресов из memory_pool
|
|
* @return TOPO_NODE* или NULL если узел не найден/нет адресов
|
|
*
|
|
* Загружает pubkey, name из nodes, IPv4/UDP-адреса из node_addresses.
|
|
* Вызывающий должен передать владение через topo_node_registry_acquire().
|
|
*/
|
|
struct TOPO_NODE* topo_node_sqlite_node_load(sqlite3* db, struct TOPO_GROUPS* groups, uint64_t node_id);
|
|
|
|
#endif
|