- db_sync_next_timestamp(): ntp_time_get_us() via si->db_sync->inst - topo_node_sqlite_node_put: +time_t now_sec param, replace unixepoch() - topo_node_sqlite_node_update_verified: +time_t created_at param - topo_node_sqlite_member_put: joined_at = join_ts (already NTP-corrected) - All INSERTs (nodes, local_identity, accounts, peers): replace DEFAULT(unixepoch()) with explicit ntp_time_get_seconds() - ON CONFLICT DO UPDATE: created_at = COALESCE(nodes.created_at, excluded.created_at) - Updated callers: topo_group.c, chat_sync.c, chat_conn_mgr.c, chat_core.c
60 lines
2.3 KiB
C
60 lines
2.3 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;
|
|
|
|
#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);
|
|
|
|
#endif
|