diff --git a/src/etcp.c b/src/etcp.c index 4e1357bf..faa60732 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -581,6 +581,8 @@ void etcp_conn_queue_set_ready(struct ETCP_CONN* conn) { if (!conn || conn->state != 0) return; // Reindex: remove old entry (key=0), add new entry with real peer_node_id + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "[%s] queue_set_ready: removing old entry=%p key=0 -> new key=0x%llx", + conn->log_name, (void*)conn->conn_queue_entry, (unsigned long long)conn->peer_node_id); if (conn->conn_queue && conn->conn_queue_entry) { queue_remove_data(conn->conn_queue, conn->conn_queue_entry); queue_entry_free(conn->conn_queue_entry); @@ -595,6 +597,8 @@ void etcp_conn_queue_set_ready(struct ETCP_CONN* conn) { conn->conn_queue = conn->instance->connections; conn->state = 1; queue_data_put_with_index(conn->instance->connections, qe); + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "[%s] queue_set_ready: new entry=%p put in queue, count=%d", + conn->log_name, (void*)qe, queue_entry_count(conn->instance->connections)); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] moved to ready queue, state=%d peer_node_id=0x%llx", conn->log_name, conn->state, (unsigned long long)conn->peer_node_id); @@ -634,7 +638,8 @@ void etcp_conn_set_peer_node_id(struct ETCP_CONN* conn, uint64_t peer_node_id) { conn->peer_node_id = peer_node_id; etcp_update_log_name(conn); - DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] peer_node_id set to 0x%llx", conn->log_name, (unsigned long long)peer_node_id); + DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] peer_node_id set to 0x%llx (state=%d reindexed=%d)", + conn->log_name, (unsigned long long)peer_node_id, conn->state, conn->state == 1); } diff --git a/tools/chatgui/transport/chat_sync.c b/tools/chatgui/transport/chat_sync.c index d91f6124..02d0f794 100644 --- a/tools/chatgui/transport/chat_sync.c +++ b/tools/chatgui/transport/chat_sync.c @@ -434,9 +434,17 @@ static void cs_join_timeout_cb(void* arg) { /* ── helper: find active ETCP_CONN for node ── */ static struct ETCP_CONN* cs_find_conn_for_node(struct UTUN_INSTANCE* inst, uint64_t node_id) { - if (!inst->connections) return NULL; + if (!inst->connections) { DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: find_conn connections=NULL", CS_ID); return NULL; } struct ll_entry* e = queue_find_data_by_index(inst->connections, (const uint8_t*)&node_id); - if (e) { struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data; if (ce->conn->initialized && ce->conn->links_up) return ce->conn; } + if (e) { + struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data; + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: find_conn node=%016llx found=%p initialized=%d links_up=%d state=%d", + CS_ID, (unsigned long long)node_id, (void*)ce->conn, ce->conn->initialized, ce->conn->links_up, ce->conn->state); + if (ce->conn->initialized && ce->conn->links_up) return ce->conn; + return NULL; + } + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: find_conn node=%016llx NOT FOUND in queue (head=%p count=%d)", + CS_ID, (unsigned long long)node_id, (void*)inst->connections->head, queue_entry_count(inst->connections)); return NULL; } @@ -484,7 +492,7 @@ static void cs_on_conn_up(struct ETCP_CONN* conn, void* arg) { if (!conn || !g_cs) return; uint64_t peer = conn->peer_node_id; if (peer == 0 || peer == g_cs->inst->node_id) return; - if (!conn->initialized) return; + if (!conn->initialized) { DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: conn_up SKIP — not initialized peer=%016llx", CS_ID, (unsigned long long)peer); return; } if (g_cs->pending_invite_ch_id != 0 && !g_cs->info_req_timer) { DEBUG_INFO(DEBUG_CATEGORY_CONNECTIVITY, "%s: conn_up invite path peer=%016llx ch=%llu",