/* * chat_core.h — центральный API чата в потоке uasync * * Все DB-операции и сетевые функции выполняются в uasync-потоке. * GUI вызывает chat_core_submit_message() через gui_bridge_post_uasync(). */ #ifndef CHAT_CORE_H #define CHAT_CORE_H #include #include struct sqlite3; struct UTUN_INSTANCE; /* ── Жизненный цикл ── */ int chat_core_init(struct UTUN_INSTANCE* inst, const char* db_path); void chat_core_destroy(struct UTUN_INSTANCE* inst); /* ── Отправка сообщения (GUI → uasync) ── */ struct chat_msg_submit { char channel_id[64]; char content_type[32]; uint8_t* data; uint32_t data_len; uint64_t timestamp; }; void chat_core_submit_message(struct chat_msg_submit* req); /* ── Push-only (без вставки в БД, только рассылка пирам) ── */ void chat_core_push_message(struct chat_msg_submit* req); /* ── DB-операции для chat_sync ── */ uint32_t chat_core_count(const char* ch_id); int chat_core_chain_hash_at(const char* ch_id, uint32_t pos, uint8_t* hash_out); int chat_core_insert_record(const char* ch_id, const uint8_t* rec, size_t len); uint32_t chat_core_cursor_open(const char* ch_id); int chat_core_cursor_next(uint32_t cursor_id, uint8_t* buf, size_t buf_size, size_t* out_len); void chat_core_cursor_close(uint32_t cursor_id); void chat_core_mark_sent(const char* ch_id, uint64_t ts, uint64_t dh, uint64_t node_id); void chat_core_ttl_delete(const char* ch_id, uint64_t node_id, uint64_t cutoff_us); int chat_core_list_channels(uint8_t* buf, size_t buf_size, size_t* out_len); int chat_core_list_peers(const char* ch_id, uint8_t* buf, size_t buf_size, size_t* out_len); int chat_core_load_nodeinfo(uint64_t node_id, uint8_t* buf, size_t buf_size, size_t* out_len); /* ── Подключение к пиру (из invite-ссылки) ── */ struct chat_invite { uint64_t node_id; uint8_t pubkey[32]; uint8_t* addrs_data; int addr_count; uint8_t* ch_id; int ch_id_len; }; void chat_core_connect_from_invite(struct chat_invite* inv); /* ── Утилиты ── */ void chat_core_set_my_node_id(uint64_t node_id); /* Трамплин для gui_bridge_post_uasync (GUI → uasync) */ void chat_core_submit_trampoline(void* arg); void chat_core_push_trampoline(void* arg); #endif /* CHAT_CORE_H */