@ -5,7 +5,6 @@
# include "member_sync.h"
# include "member_sync.h"
# include "../../../src/utun_instance.h"
# include "../../../src/utun_instance.h"
# include "../../../src/etcp_router.h"
# include "../../../src/etcp_api.h"
# include "../../../src/etcp_api.h"
# include "../../../src/etcp.h"
# include "../../../src/etcp.h"
# include "../../../src/conn_mgr.h"
# include "../../../src/conn_mgr.h"
@ -304,6 +303,9 @@ static void cs_cancel_proto_timers(struct chat_sync* cs) {
if ( cs - > join_timer ) { uasync_cancel_timeout ( cs - > inst - > ua , cs - > join_timer ) ; cs - > join_timer = NULL ; }
if ( cs - > join_timer ) { uasync_cancel_timeout ( cs - > inst - > ua , cs - > join_timer ) ; cs - > join_timer = NULL ; }
}
}
/* ── Forward decl ── */
static struct ETCP_CONN * cs_find_conn_for_node ( struct UTUN_INSTANCE * inst , uint64_t node_id ) ;
/* ── Send ── */
/* ── Send ── */
static int cs_send ( struct chat_sync * cs , const char * ch_id , uint64_t dst ,
static int cs_send ( struct chat_sync * cs , const char * ch_id , uint64_t dst ,
@ -324,7 +326,9 @@ static int cs_send(struct chat_sync* cs, const char* ch_id, uint64_t dst,
entry - > dgram = buf ; entry - > len = total ;
entry - > dgram = buf ; entry - > len = total ;
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTIVITY , " %s: SEND %s to=%016llx ch=%s len=%zu " ,
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTIVITY , " %s: SEND %s to=%016llx ch=%s len=%zu " ,
CS_ID , cs_msg_name ( payload [ 0 ] ) , ( unsigned long long ) dst , ch_id , len ) ;
CS_ID , cs_msg_name ( payload [ 0 ] ) , ( unsigned long long ) dst , ch_id , len ) ;
return etcp_route_send ( cs - > inst , dst , entry , 0 ) ;
struct ETCP_CONN * conn = cs_find_conn_for_node ( cs - > inst , dst ) ;
if ( ! conn ) { DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: no conn for node %016llx " , CS_ID , ( unsigned long long ) dst ) ; u_free ( buf ) ; queue_entry_free ( entry ) ; return - 1 ; }
return etcp_send ( conn , entry ) ;
}
}
/* ── Channel cache ── */
/* ── Channel cache ── */
@ -650,6 +654,17 @@ static void cs_join_timeout_cb(void* arg) {
cs - > pending_invite_ch_id = 0 ;
cs - > pending_invite_ch_id = 0 ;
}
}
/* ── helper: find active ETCP_CONN for node ── */
static struct ETCP_CONN * cs_find_conn_for_node ( struct UTUN_INSTANCE * inst , uint64_t node_id ) {
struct ETCP_CONN * c = inst - > connections ;
while ( c ) {
if ( c - > peer_node_id = = node_id & & c - > initialized & & c - > links_up ) return c ;
c = c - > next ;
}
return NULL ;
}
/* ── helper: check if peer has active ETCP link ── */
/* ── helper: check if peer has active ETCP link ── */
static int cs_is_peer_online ( struct UTUN_INSTANCE * inst , uint64_t peer_id ) {
static int cs_is_peer_online ( struct UTUN_INSTANCE * inst , uint64_t peer_id ) {
@ -851,7 +866,7 @@ int chat_sync_init(struct UTUN_INSTANCE* inst,
cs - > initialized = 1 ;
cs - > initialized = 1 ;
g_cs = cs ;
g_cs = cs ;
etcp_router_ bind ( inst , ETCP_RT_ID_CHAT_SYNC , chat_sync_recv_cb ) ;
etcp_bind ( inst , ETCP_RT_ID_CHAT_SYNC , chat_sync_recv_cb ) ;
etcp_add_new_conn_cbk ( inst , cs_on_new_conn , NULL ) ;
etcp_add_new_conn_cbk ( inst , cs_on_new_conn , NULL ) ;
struct ETCP_CONN * c = inst - > connections ;
struct ETCP_CONN * c = inst - > connections ;
@ -883,7 +898,7 @@ void chat_sync_destroy(struct UTUN_INSTANCE* inst) {
member_sync_destroy ( inst ) ;
member_sync_destroy ( inst ) ;
cs - > initialized = 0 ; g_cs = NULL ;
cs - > initialized = 0 ; g_cs = NULL ;
etcp_router_ unbind ( inst , ETCP_RT_ID_CHAT_SYNC ) ;
etcp_unbind ( inst , ETCP_RT_ID_CHAT_SYNC ) ;
if ( cs - > refresh_timer ) { uasync_cancel_timeout ( inst - > ua , cs - > refresh_timer ) ; cs - > refresh_timer = NULL ; }
if ( cs - > refresh_timer ) { uasync_cancel_timeout ( inst - > ua , cs - > refresh_timer ) ; cs - > refresh_timer = NULL ; }
if ( cs - > ttl_timer ) { uasync_cancel_timeout ( inst - > ua , cs - > ttl_timer ) ; cs - > ttl_timer = NULL ; }
if ( cs - > ttl_timer ) { uasync_cancel_timeout ( inst - > ua , cs - > ttl_timer ) ; cs - > ttl_timer = NULL ; }
cs_cancel_proto_timers ( cs ) ;
cs_cancel_proto_timers ( cs ) ;
@ -1027,7 +1042,7 @@ static void cs_propagate(struct chat_sync* cs, const char* ch_id, uint64_t exclu
for ( int i = 0 ; i < ch - > peer_count ; i + + ) {
for ( int i = 0 ; i < ch - > peer_count ; i + + ) {
uint64_t pid = ch - > peer_ids [ i ] ;
uint64_t pid = ch - > peer_ids [ i ] ;
if ( pid = = exclude_id | | pid = = myid ) continue ;
if ( pid = = exclude_id | | pid = = myid ) continue ;
if ( ! etcp_router_conn_get ( cs - > inst , pid , ETCP_RT_ID_CHAT_SYNC ) ) continue ;
if ( ! cs_find_conn_for_node ( cs - > inst , pid ) ) continue ;
cs_send ( cs , ch_id , pid , payload , len ) ;
cs_send ( cs , ch_id , pid , payload , len ) ;
}
}
}
}