diff --git a/AGENTS.md b/AGENTS.md index 73e7bce4..4506d3be 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -75,7 +75,7 @@ ASAN_OPTIONS=detect_leaks=0:halt_on_error=0 ./src/utun -f -p /tmp/utun.pid -l /t ### Run All Tests ```bash -make check # Run all tests via automake, логи в tests/logs/ +make check # Run all tests via automake, логи в tests/logs/ - запускай после make без grep, вывод короткий ``` ```powershell powershell check.bat # Windows, запускает каждый .exe из tests/ diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 2df8aeee..c317ca32 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -1472,7 +1472,7 @@ static int handle_init_response_client(struct ETCP_SOCKET* e_sock, struct ETCP_D link->init_timer = NULL; } - if (pkt_code == ETCP_INIT_RESPONSE && !link->etcp->reset_done) { + if (pkt_code == ETCP_INIT_RESPONSE && link->etcp->got_initial_pkt) { DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] REINIT from client: INIT_RESPONSE(0x03) received, reinit conn=%p", link->etcp->log_name, link->etcp); etcp_conn_reinit(link->etcp); @@ -1779,25 +1779,15 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { conn->log_name); } - // Normal reinit check (skip if reset_done=1 unless session_id changed) - if (!conn->reset_done) { - if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || !conn->got_initial_pkt) { - send_reset = 1; - DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT existing link: code=0x%02x sess=%08x→%08x got_init=%d initialized=%d links_up=%d", - conn->log_name, code, conn->session_id, session_id, conn->got_initial_pkt, conn->initialized, conn->links_up); - conn->session_id = session_id; - etcp_conn_reinit(conn); - } - } else if (conn->session_id != session_id) { - send_reset = 1; - DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT existing link (session changed): sess=%08x→%08x", - conn->log_name, conn->session_id, session_id); - conn->session_id = session_id; - etcp_conn_reinit(conn); - } else { - send_reset = 0; - DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "same session_id, skip reinit"); - } + // Always sync session_id; reset if new session or data was flowing + { int sess_changed = (conn->session_id != session_id); + conn->session_id = session_id; + if (sess_changed || conn->got_initial_pkt) { + send_reset = 1; + DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT existing link: code=0x%02x sess=%08x→%08x got_init=%d initialized=%d links_up=%d", + conn->log_name, code, conn->session_id, session_id, conn->got_initial_pkt, conn->initialized, conn->links_up); + etcp_conn_reinit(conn); + } } } // Cancel existing timers @@ -1834,22 +1824,15 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { return; } - // Normal reinit check (skip if reset_done=1 unless session_id changed) - if (!conn->reset_done) { - if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || !conn->got_initial_pkt) { - send_reset = 1; - DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT new link: code=0x%02x sess=%08x→%08x got_init=%d initialized=%d links_up=%d", - conn->log_name, code, conn->session_id, session_id, conn->got_initial_pkt, conn->initialized, conn->links_up); - conn->session_id = session_id; - etcp_conn_reinit(conn); - } - } else if (conn->session_id != session_id) { - send_reset = 1; - DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT new link (session changed): sess=%08x→%08x", - conn->log_name, conn->session_id, session_id); - conn->session_id = session_id; - etcp_conn_reinit(conn); - } + // Always sync session_id; reset if new session or data was flowing + { int sess_changed = (conn->session_id != session_id); + conn->session_id = session_id; + if (sess_changed || conn->got_initial_pkt) { + send_reset = 1; + DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] REINIT new link: code=0x%02x sess=%08x→%08x got_init=%d initialized=%d links_up=%d", + conn->log_name, code, conn->session_id, session_id, conn->got_initial_pkt, conn->initialized, conn->links_up); + etcp_conn_reinit(conn); + } } } link->keepalive_interval=(req->keepalive[0]<<8) | req->keepalive[1]; link->recovery_interval=((req->recovery[0]<<8) | req->recovery[1])*100;// timebase в link, timebase/100 в кодограмме