diff --git a/src/etcp_api.c b/src/etcp_api.c index 9a915e5c..8aa75ab0 100644 --- a/src/etcp_api.c +++ b/src/etcp_api.c @@ -102,10 +102,12 @@ void etcp_int_recv(struct ll_queue* queue, void* arg) { uint8_t id = e->dgram[0]; struct UTUN_INSTANCE* inst = conn->instance; if (!inst) { queue_dgram_free(e); queue_entry_free(e); queue_resume_callback(queue); return; } - if (inst->api_bindings.callbacks[id]) + if (inst->api_bindings.callbacks[id]) { + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "dispatch id=0x%02x conn=%s len=%zu", id, conn->log_name, e->len); inst->api_bindings.callbacks[id](conn, e); - else if (inst->api_bindings.callbacks[0]) + } else if (inst->api_bindings.callbacks[0]) { + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "dispatch id=0x%02x (fallback) conn=%s len=%zu", id, conn->log_name, e->len); inst->api_bindings.callbacks[0](conn, e); - else { queue_dgram_free(e); queue_entry_free(e); } + } else { DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "dispatch id=0x%02x NO CB conn=%s len=%zu — DROPPED", id, conn->log_name, e->len); queue_dgram_free(e); queue_entry_free(e); } queue_resume_callback(queue); } diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 7560ba50..6e4024bd 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -398,7 +398,14 @@ static int insert_link(struct ETCP_SOCKET* e_sock, struct ETCP_LINK* link) { } int idx = find_link_index(e_sock, link->ip_port_hash); - if (idx >= 0) return -1; + if (idx >= 0) { + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "insert_link DUP: hash=0x%08x idx=%d existing_conn=%s existing_etcp=%s num_channels=%zu sock=%s", + link->ip_port_hash, idx, + e_sock->links[idx]->etcp ? e_sock->links[idx]->etcp->log_name : "?", + e_sock->links[idx]->etcp ? "[...]" : "?", + e_sock->num_channels, e_sock->name); + return -1; + } idx = -(idx + 1); @@ -1525,6 +1532,8 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { return; } + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "raw_recv on %s from=%s len=%zd", e_sock->name, sockaddr_storage_to_str(&addr).str, recv_len); + // DUMP: Show received packet content if (debug_should_output(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_CRYPTO)) log_dump(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_CRYPTO, "RECV in:", data, recv_len); @@ -1705,6 +1714,8 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { if (memcmp(conn->crypto_ctx.peer_public_key, sc.peer_public_key, SC_PUBKEY_SIZE)) { errorcode=5; DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "peer key mismatch for node %016llx", (unsigned long long)peer_id); goto ec_fr; }// коллизия - peer id совпал а ключи разные. } + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "INIT conn=%s new_conn=%d peer=0x%016llx state=%d links_up=%d links=%p", conn->log_name, new_conn, (unsigned long long)peer_id, conn->state, conn->links_up, (void*)conn->links); + // Check if link already exists (for CHANNEL_INIT recovery) struct ETCP_LINK* existing_link = etcp_link_find_by_remote_id(conn, req->link_id); diff --git a/tools/chatgui/transport/chat_sync.c b/tools/chatgui/transport/chat_sync.c index e5cd8318..5f146b76 100644 --- a/tools/chatgui/transport/chat_sync.c +++ b/tools/chatgui/transport/chat_sync.c @@ -197,7 +197,7 @@ static void ac_result_cb(int result, uint64_t node_id, void* arg) { if (!g_ac || !g_ac->active) return; const char* rs = result == CC_OK ? "OK" : "FAIL"; DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: result node=0x%016llx %s", AC_ID, (unsigned long long)node_id, rs); - if (result == CC_OK) f->ca_state = NULL; /* already freed by ca_ready_cb, prevent double-free in GC/stop */ + f->ca_state = NULL; /* already freed by ca_ready_cb or ca_timeout_cb */ } /* ── retry timer callback (every AC_RETRY_MS) ── */ @@ -326,7 +326,9 @@ static int cs_send(struct chat_sync* cs, const char* ch_id, uint64_t dst, CS_ID, cs_msg_name(payload[0]), (unsigned long long)dst, ch_id, len); struct ETCP_CONN* conn = cs_find_conn_for_node(cs->inst, dst); if (!conn) { DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%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); + int rc = etcp_send(conn, entry); + DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: etcp_send rc=%d id=0x%02x to=%016llx conn=%s", CS_ID, rc, payload[0], (unsigned long long)dst, conn->log_name); + return rc; } /* ── Channel cache ── */