From 4a2145779e6ced92b7e2e72bf87d1a0bb1980171 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 20 Jan 2026 21:45:20 +0300 Subject: [PATCH] Enable server-only operation and add server section to configs - Fixed init_connections() to allow 0 connections for server-only mode - All instances now require [server] section for bind socket - Added test configs demonstrating server-only and client-with-server patterns - Created run_two_instance_test.sh for manual handshake testing --- src/etcp_connections.c | 6 ++++-- tests/run_two_instance_test.sh | 25 +++++++++++++++++++++++++ tests/test_server_only.conf | 10 ++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 tests/run_two_instance_test.sh create mode 100644 tests/test_server_only.conf diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 99af4244b..08e108465 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -562,8 +562,10 @@ int init_connections(struct UTUN_INSTANCE* instance) { client = client->next; } - if (instance->connections_count == 0) { - DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "No connections initialized"); + // If there are clients configured but no connections created, that's an error + // If there are no clients (server-only mode), 0 connections is OK (server will accept incoming) + if (instance->connections_count == 0 && config->clients != NULL) { + DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Clients configured but no connections initialized"); return -1; } diff --git a/tests/run_two_instance_test.sh b/tests/run_two_instance_test.sh new file mode 100755 index 000000000..31dcaf555 --- /dev/null +++ b/tests/run_two_instance_test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Test script for ETCP connection establishment with real instances + +DIR=$(cd "$(dirname "$0")" && pwd) + +echo "=== ETCP Two-Instance Test ===" +echo + +# Start server instance in background +echo "Starting server instance..." +$DIR/test_server_only & +SERVER_PID=$! +sleep 1 + +# Start client instance +echo "Starting client instance..." +timeout 10 $DIR/test_server_only 2>&1 + +# Cleanup +kill $SERVER_PID 2>/dev/null +wait $SERVER_PID 2>/dev/null + +echo +echo "=== Test completed ===" \ No newline at end of file diff --git a/tests/test_server_only.conf b/tests/test_server_only.conf new file mode 100644 index 000000000..39ad33b1d --- /dev/null +++ b/tests/test_server_only.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=1313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc +my_public_key=dde6cec8a9023339a758f60883ef41534d24a1ffdc09bbb787a5c24ddfd891e3092461835a97d37944c681fc6b2c1f5acde8ad192f7d2cdc9920aa0d3ff78e99 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9001 +type=public