From 4eaabf2e1cc1445c2d93d53b1c32d6451d3e9ee9 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 15 Feb 2026 23:35:23 +0300 Subject: [PATCH] Fix: Treat client links as INIT packets on receive When receiving an INIT packet, the code was looking up existing links by address. However, in a mesh topology where each node has both client and server connections to peers, a client link created during initialization would be found when receiving an incoming INIT packet from that peer. This caused the code to try decrypting the INIT packet using the client link's crypto context, which failed because the session keys weren't properly established yet. The fix checks if the found link is a client link (is_server==0) and if so, treats the packet as a new INIT connection that needs to create a server-side link instead. Changed condition from: if (link==NULL) to: if (link==NULL || link->is_server==0) --- src/etcp_connections.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/etcp_connections.c b/src/etcp_connections.c index b03fb0c89..ea38a650c 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -572,7 +572,9 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) { struct ETCP_LINK* link=etcp_link_find_by_addr(e_sock, &addr); // printf("[ETCP DEBUG] Received packet, link=%p, recv_len=%zd\n", link, recv_len); - if (link==NULL) {// пробуем расшифровать, возможно это init + // If no link found OR found link is a client link (not server), treat as potential INIT + // Client links shouldn't receive incoming INIT packets - only server links should + if (link==NULL || link->is_server==0) {// пробуем расшифровать, возможно это init // printf("[ETCP DEBUG] No existing link found, trying to decrypt as INIT packet\n"); struct secure_channel sc; if (recv_len<=SC_PUBKEY_SIZE) { errorcode=1; DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_connections_read_callback: packet too small for init, size=%zd", recv_len); goto ec_fr; }