- dedup double ETCP_CONN_STATUS_UP (UDP+TCP links) in topo_group_new_conn - close conn_mgr handle on TIMEOUT in Phase2/3 (fix stuck 'already connecting') - infinite Phase1→2→3 cycle with pause (1s active / 30s standby) - CHAT_EVT_CONNECTING_NODES: yellow circle in member list while connecting - Android: client_activity wiring via onStart/onStop + nativeSetActive - function-level comments in topo_group_connect.c
149 lines
5.3 KiB
C
149 lines
5.3 KiB
C
/*
|
|
* android_jni_bridge.h — JNI bridge API (C side)
|
|
*
|
|
* Provides lifecycle management and callbacks between C core and Kotlin.
|
|
* For Android, compiled via NDK into libutun_lite.so.
|
|
*/
|
|
#ifndef ANDROID_JNI_BRIDGE_H
|
|
#define ANDROID_JNI_BRIDGE_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* ── Callback types (C → Kotlin) ── */
|
|
|
|
typedef void (*utun_log_fn)(int level, const char* category, const char* message);
|
|
|
|
typedef void (*utun_event_fn)(int event_type, const char* json_data);
|
|
|
|
typedef const char* (*utun_config_string_fn)(const char* key);
|
|
typedef int64_t (*utun_config_int64_fn)(const char* key);
|
|
typedef int (*utun_config_int_fn)(const char* key);
|
|
|
|
struct utun_bridge_config {
|
|
utun_config_string_fn get_string;
|
|
utun_config_int64_fn get_int64;
|
|
utun_config_int_fn get_int;
|
|
};
|
|
|
|
/* ── Initialize uTun core (legacy stub — use start for real init) ── */
|
|
|
|
bool utun_bridge_init(const char* db_path, int control_port,
|
|
utun_log_fn on_log,
|
|
utun_event_fn on_event,
|
|
const struct utun_bridge_config* config);
|
|
|
|
/* ── Start full uTun stack from INI config text ── */
|
|
int utun_bridge_start(const char* config_text);
|
|
|
|
/* ── Shutdown uTun core ── */
|
|
void utun_bridge_destroy(void);
|
|
|
|
/* ── Actions (Kotlin → C) ── */
|
|
|
|
void utun_bridge_send_message(const char* channel_id, const char* text);
|
|
void utun_bridge_create_channel(const char* name, const char* channel_id);
|
|
void utun_bridge_connect_node(const char* address, int port, const char* pubkey_hex);
|
|
|
|
/* Join channel via invite link.
|
|
addr_data format: family(1) + socketId(1) + address(4|16) + port(2 BE) per addr */
|
|
void utun_bridge_join_channel(uint64_t channel_id, uint64_t node_id,
|
|
const uint8_t* pubkey_bin,
|
|
const uint8_t* addrs_data, int addr_count,
|
|
int addrs_data_len);
|
|
|
|
/* Connect to all peers of a channel (auto-connect on select) */
|
|
void utun_bridge_connect_channel(const char* channel_id);
|
|
|
|
/* ── Queries ── */
|
|
|
|
char* utun_bridge_get_channels_json(void);
|
|
char* utun_bridge_get_messages_json(const char* channel_id, int limit);
|
|
uint64_t utun_bridge_get_my_node_id(void);
|
|
|
|
/* ── Restart (config update, key regen, DB clear) ── */
|
|
|
|
void utun_bridge_restart(const char* config_text);
|
|
|
|
/* ── Health check ── */
|
|
|
|
void utun_bridge_ping(void);
|
|
int utun_bridge_is_responsive(void);
|
|
|
|
/* ── Voice recording ── */
|
|
|
|
int utun_bridge_voice_start(const char* channel_id);
|
|
int utun_bridge_voice_feed(const int16_t* samples, int count);
|
|
int utun_bridge_voice_stop(int* out_duration_ms);
|
|
void utun_bridge_voice_cancel(void);
|
|
int utun_bridge_voice_is_active(void);
|
|
void utun_bridge_voice_set_preset(int preset);
|
|
int utun_bridge_voice_get_preset(void);
|
|
void utun_bridge_voice_set_compressor(int enabled);
|
|
int utun_bridge_voice_get_compressor(void);
|
|
void utun_bridge_voice_set_compressor_config(int max_gain_db, int lookback_ms, int lookahead_ms,
|
|
float rise_rate_per_sec, float target_level_db);
|
|
float utun_bridge_voice_get_peak_level(void);
|
|
|
|
/* ── Attachment ── */
|
|
|
|
int utun_bridge_attachment_send(const char* channel_id, const char* file_path, const char* db_path);
|
|
int utun_bridge_attachment_download(const char* channel_id, int64_t msg_id);
|
|
|
|
/* ── Voice playback (Opus decode) ── */
|
|
|
|
void* utun_bridge_voice_decode_open(const char* file_path,
|
|
int* out_sample_rate, int* out_channels,
|
|
int* out_total_samples);
|
|
int utun_bridge_voice_decode_read(void* handle, int16_t* buf, int max_samples);
|
|
void utun_bridge_voice_decode_close(void* handle);
|
|
|
|
/* ── Invite link encode (for sharing) ── */
|
|
char* utun_bridge_encode_invite_link(uint64_t channel_id, const char* password);
|
|
|
|
/* ── Debug ── */
|
|
|
|
void utun_bridge_set_debug_level(const char* category, const char* level);
|
|
|
|
/* ── Chat settings ── */
|
|
|
|
void utun_bridge_chat_setting_set(const char* name, const char* value);
|
|
int utun_bridge_chat_setting_get_int(const char* name, int def);
|
|
|
|
/* ── Channel members ── */
|
|
|
|
char* utun_bridge_get_channel_members_json(const char* channel_id);
|
|
char* utun_bridge_get_member_detail_json(const char* channel_id, uint64_t node_id);
|
|
void utun_bridge_set_member_nick(const char* channel_id, uint64_t node_id, const char* nick);
|
|
void utun_bridge_set_member_flags(const char* channel_id, uint64_t node_id,
|
|
int admin, int supernode, int moder, int storage);
|
|
|
|
char* utun_bridge_get_member_links_json(uint64_t node_id);
|
|
|
|
/* ── Local sockets state (for auto-mode display) ── */
|
|
|
|
char* utun_bridge_get_local_sockets_json(void);
|
|
|
|
/* ── Network change notification (ConnectivityManager → auto_socket) ── */
|
|
|
|
void utun_bridge_on_network_change(void);
|
|
|
|
/* ── App foreground/background (Android lifecycle) → client_activity ── */
|
|
|
|
void utun_bridge_set_active(int active);
|
|
|
|
/* ── Connection monitor (post collect functions to uasync thread) ── */
|
|
|
|
void utun_bridge_collect_conn_list(void);
|
|
void utun_bridge_collect_conn_metrics(uint64_t peer_node_id);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* ANDROID_JNI_BRIDGE_H */
|