Browse Source

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)
nodeinfo-routing-update
Evgeny 2 months ago
parent
commit
0a4373ffe1
  1. 4
      src/etcp_connections.c

4
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); 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); // 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"); // printf("[ETCP DEBUG] No existing link found, trying to decrypt as INIT packet\n");
struct secure_channel sc; 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; } 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; }

Loading…
Cancel
Save