etcp: instance-level conn status callbacks (NEW/UP/DOWN/DELETE), fix member online in chatgui

- Add etcp_add_conn_status_cbk/remove/set — unified callback for all connections
- 4 statuses: NEW, UP, DOWN, DELETE — one subscription covers all connections
- Fire points in etcp.c: create→NEW, on_up→UP, on_down→DOWN, close→DELETE
- chat_sync.c: replace cs_on_new_conn+per-conn subs with cs_on_conn_status
- db_sync.c: same migration to instance-level callback
- cs_is_peer_online: use conn->links_up instead of link->link_status (was 0 during INIT handshake)
This commit is contained in:
Evgeny committed 2026-07-18 14:51:01 +03:00
1 parent ef27633a88
commit aa1ed006d5
6 files changed
+84 -48

No files matched your search

+13 -23
View File
@@ -458,8 +458,7 @@ static int cs_is_peer_online(struct UTUN_INSTANCE* inst, uint64_t peer_id) {
struct ll_entry* e = queue_find_data_by_index(inst->connections, (const uint8_t*)&peer_id);
if (e) {
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data;
struct ETCP_LINK* l = ce->conn->links;
while (l) { if (l->initialized && l->link_status) return 1; l = l->next; }
return ce->conn->initialized && ce->conn->links_up;
}
return 0;
}
@@ -557,6 +556,15 @@ static void cs_on_conn_down(struct ETCP_CONN* conn, void* arg) {
}
}
static void cs_on_conn_status(struct ETCP_CONN* conn, int status, void* arg) {
switch (status) {
case ETCP_CONN_STATUS_UP: cs_on_conn_up(conn, arg); break;
case ETCP_CONN_STATUS_DOWN: cs_on_conn_down(conn, arg); break;
default: break;
}
}
#if 0 /* replaced by cs_on_conn_status */
static void cs_on_new_conn(struct ETCP_CONN* conn, void* arg) {
(void)arg;
if (!conn) return;
@@ -564,6 +572,7 @@ static void cs_on_new_conn(struct ETCP_CONN* conn, void* arg) {
etcp_conn_add_up_cbk(conn, cs_on_conn_up, NULL);
etcp_conn_add_down_cbk(conn, cs_on_conn_down, NULL);
}
#endif
/* ── Periodic refresh from DB ── */
@@ -633,17 +642,7 @@ int chat_sync_init(struct UTUN_INSTANCE* inst,
g_cs = cs;
etcp_bind(inst, ETCP_RT_ID_CHAT_SYNC, chat_sync_recv_cb);
etcp_add_new_conn_cbk(inst, cs_on_new_conn, NULL);
{
struct ll_entry* entry = inst->connections->head;
while (entry) {
struct conn_queue_entry* ce = (struct conn_queue_entry*)entry->data;
etcp_conn_add_up_cbk(ce->conn, cs_on_conn_up, NULL);
etcp_conn_add_down_cbk(ce->conn, cs_on_conn_down, NULL);
entry = entry->next;
}
}
etcp_add_conn_status_cbk(inst, cs_on_conn_status, NULL);
cs_refresh_channels(cs);
@@ -667,19 +666,10 @@ void chat_sync_destroy(struct UTUN_INSTANCE* inst) {
cs->initialized = 0; g_cs = NULL;
etcp_unbind(inst, ETCP_RT_ID_CHAT_SYNC);
etcp_remove_conn_status_cbk(inst, cs_on_conn_status, NULL);
if (cs->refresh_timer) { uasync_cancel_timeout(inst->ua, cs->refresh_timer); cs->refresh_timer = NULL; }
cs_cancel_proto_timers(cs);
{
struct ll_entry* entry = inst->connections->head;
while (entry) {
struct conn_queue_entry* ce = (struct conn_queue_entry*)entry->data;
etcp_conn_remove_up_cbk(ce->conn, cs_on_conn_up, NULL);
etcp_conn_remove_down_cbk(ce->conn, cs_on_conn_down, NULL);
entry = entry->next;
}
}
for (int i = 0; i < cs->channel_count; i++)
if (cs->channels[i].peer_ids) u_free(cs->channels[i].peer_ids);
if (cs->channels) u_free(cs->channels);