You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.0 KiB
86 lines
3.0 KiB
/* |
|
* 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 <stdint.h> |
|
#include <stddef.h> |
|
|
|
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); |
|
|
|
struct sqlite3* chat_core_get_db(void); |
|
struct UTUN_INSTANCE* chat_core_get_inst(void); |
|
int chat_core_is_initialized(void); |
|
|
|
/* ── Отправка сообщения (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); |
|
|
|
/* ── DB-операции (оставлены для интроспекции) ── */ |
|
|
|
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_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); |
|
|
|
/* ── Создание канала (GUI → uasync) ── */ |
|
|
|
struct chat_channel_create { |
|
char channel_id[64]; |
|
char name[128]; |
|
uint64_t owner_node_id; |
|
uint8_t x25519_pubkey[32]; |
|
uint8_t x25519_privkey[32]; |
|
uint8_t ed25519_pubkey[32]; |
|
uint8_t ed25519_privkey[32]; |
|
uint8_t signature[64]; |
|
}; |
|
|
|
void chat_core_ensure_channel_ready(const char* ch_id); |
|
void chat_core_create_channel(struct chat_channel_create* req); |
|
void chat_core_create_channel_trampoline(void* arg); |
|
void chat_core_create_channel_auto(const char* name); |
|
void chat_core_create_channel_auto_trampoline(void* arg); |
|
|
|
/* ── Утилиты ── */ |
|
|
|
void chat_core_set_my_node_id(uint64_t node_id); |
|
void chat_core_update_my_name(const char* name); |
|
void chat_core_update_my_name_trampoline(void* arg); |
|
void chat_core_sync_my_addresses(void); |
|
|
|
/* Сохранение key-value в ui_state (вызывается из uasync-потока) */ |
|
void chat_core_save_ui_state(const char* key, const char* value); |
|
void chat_core_save_ui_state_trampoline(void* arg); |
|
|
|
/* Запуск подключения к узлам выбранного канала (GUI → uasync) */ |
|
void chat_core_connect_channel(const char* ch_id); |
|
void chat_core_connect_channel_trampoline(void* arg); |
|
|
|
/* Трамплин для gui_bridge_post_uasync (GUI → uasync) */ |
|
void chat_core_submit_trampoline(void* arg); |
|
|
|
/* Сбор статуса (NTP + connections) и отправка в GUI */ |
|
void chat_core_collect_status_trampoline(void* arg); |
|
|
|
#endif /* CHAT_CORE_H */
|
|
|