|
|
|
@ -460,12 +460,16 @@ static struct ETCP_CONN* cs_find_conn_for_node(struct UTUN_INSTANCE* inst, uint6 |
|
|
|
/* ── 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) { |
|
|
|
if (!inst->connections) return 0; |
|
|
|
if (!inst->connections) { DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: is_online peer=0x%016llx CONNS=NULL", CS_ID, (unsigned long long)peer_id); return 0; } |
|
|
|
struct ll_entry* e = queue_find_data_by_index(inst->connections, (const uint8_t*)&peer_id); |
|
|
|
struct ll_entry* e = queue_find_data_by_index(inst->connections, (const uint8_t*)&peer_id); |
|
|
|
if (e) { |
|
|
|
if (e) { |
|
|
|
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data; |
|
|
|
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data; |
|
|
|
return ce->conn->initialized && ce->conn->links_up; |
|
|
|
int onl = ce->conn->initialized && ce->conn->links_up; |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: is_online peer=0x%016llx found=1 init=%d links=%d online=%d", |
|
|
|
|
|
|
|
CS_ID, (unsigned long long)peer_id, ce->conn->initialized, ce->conn->links_up, onl); |
|
|
|
|
|
|
|
return onl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: is_online peer=0x%016llx found=0", CS_ID, (unsigned long long)peer_id); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -552,9 +556,11 @@ static void cs_on_peer_status_changed(uint64_t peer, int online) { |
|
|
|
member_sync_set_online(g_cs->inst, peer, online); |
|
|
|
member_sync_set_online(g_cs->inst, peer, online); |
|
|
|
|
|
|
|
|
|
|
|
/* 2. GUI + online-бар */ |
|
|
|
/* 2. GUI + online-бар */ |
|
|
|
|
|
|
|
int found_in_channel = 0; |
|
|
|
for (int i = 0; i < g_cs->channel_count; i++) { |
|
|
|
for (int i = 0; i < g_cs->channel_count; i++) { |
|
|
|
for (int j = 0; j < g_cs->channels[i].peer_count; j++) { |
|
|
|
for (int j = 0; j < g_cs->channels[i].peer_count; j++) { |
|
|
|
if (g_cs->channels[i].peer_ids[j] == peer) { |
|
|
|
if (g_cs->channels[i].peer_ids[j] == peer) { |
|
|
|
|
|
|
|
found_in_channel = 1; |
|
|
|
size_t cl = strlen(g_cs->channels[i].channel_id); |
|
|
|
size_t cl = strlen(g_cs->channels[i].channel_id); |
|
|
|
if (cl > 63) cl = 63; |
|
|
|
if (cl > 63) cl = 63; |
|
|
|
uint8_t evt[65]; evt[0] = (uint8_t)cl; |
|
|
|
uint8_t evt[65]; evt[0] = (uint8_t)cl; |
|
|
|
@ -570,6 +576,9 @@ static void cs_on_peer_status_changed(uint64_t peer, int online) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: peer_status_changed peer=0x%016llx online=%d channels=%d found=%d", |
|
|
|
|
|
|
|
CS_ID, (unsigned long long)peer, online, g_cs->channel_count, found_in_channel); |
|
|
|
|
|
|
|
|
|
|
|
/* 4. Запланировать member_sync_start (throttled) */ |
|
|
|
/* 4. Запланировать member_sync_start (throttled) */ |
|
|
|
cs_schedule_sync(g_cs); |
|
|
|
cs_schedule_sync(g_cs); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1263,6 +1272,7 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer, |
|
|
|
{ uint8_t evt[65]; uint8_t cl=(uint8_t)strlen(ch_id); evt[0]=cl; memcpy(evt+1,ch_id,cl); |
|
|
|
{ uint8_t evt[65]; uint8_t cl=(uint8_t)strlen(ch_id); evt[0]=cl; memcpy(evt+1,ch_id,cl); |
|
|
|
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1+cl); } |
|
|
|
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1+cl); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: JOIN calling cs_post_channel_online ch=%s", CS_ID, ch_id); |
|
|
|
cs_post_channel_online(cs, ch_id); |
|
|
|
cs_post_channel_online(cs, ch_id); |
|
|
|
|
|
|
|
|
|
|
|
/* initiate member sync with the joiner (server side) */ |
|
|
|
/* initiate member sync with the joiner (server side) */ |
|
|
|
@ -1392,6 +1402,7 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer, |
|
|
|
|
|
|
|
|
|
|
|
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1 + ch_id_len); |
|
|
|
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1 + ch_id_len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: WELCOME calling cs_post_channel_online ch=%s", CS_ID, ch_id); |
|
|
|
cs_post_channel_online(cs, ch_id); |
|
|
|
cs_post_channel_online(cs, ch_id); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: WELCOME processed ch=%s peers=%d — message sync triggered via db_sync (active conn or peer_check timer every 5s)", |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: WELCOME processed ch=%s peers=%d — message sync triggered via db_sync (active conn or peer_check timer every 5s)", |
|
|
|
|