Commit Graph
34 Commits
Author SHA1 Message Date
evgeny 38c9f229bc stcp: ed25519 pubkey exchange in handshake, fix instance destroy segfault, fix chat_tcp_test
- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll
- stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close
- utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP),
  add deferred drain in both Phase J and L
- stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39,
  exchange ed25519_pubkey in both handshake directions
- etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in
  etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb
- chat_sync.c: fix lk->conn NULL dereference for TCP links
- test_stcp.c: update stcp_server_create/stcp_client_connect callsites
- tools/chat_tcp_test: change transport udp→tcp
2026-08-07 00:48:27 +03:00
evgeny d773f1724a refactor: STCP connections as ETCP links (is_tcp)
- Add is_tcp, tcp_link, tcp_reconnect_* fields to ETCP_LINK
- Remove transport_link from ETCP_CONN, add tcp_link_count
- stcp_link: replace embedded etcp_conn with pointer; add etcp_link backpointer
- stcp_link: link_rx_cb routes ETCP data to etcp_conn_input
- stcp_link: call on_close_cb in close
- New TCP functions: etcp_link_enter_ready_tcp, etcp_tcp_link_start_connect,
  etcp_tcp_link_start_reconnect, tcp_link_close_cb, etcp_tcp_send
- etcp_link_new: handle NULL conn for TCP links; skip enter_init for TCP
- etcp_link_close: close stcp_link for TCP
- etcp_encrypt_send: redirect TCP to etcp_tcp_send (skips AES-CCM)
- tcp_server_on_link: create ETCP_LINK(is_tcp=1) + enter_ready_tcp
- etcp_connect: TCP addrs -> etcp_tcp_link_start_connect
- Remove ctx->tcp_link/tcp_ready
- test_stcp_traffic: find stcp_link via links->is_tcp instead of transport_link
- 66/68 tests pass; 2 STCP tests expected to fail (integration not complete)
2026-08-06 22:14:32 +03:00
evgeny fdbb5b7bc0 ipv6: use netlink RTM_GETADDR to properly detect permanent vs temporary IPv6 addresses
getifaddrs() ifa_flags contains interface flags (IFF_UP etc.), NOT address
flags (IFA_F_TEMPORARY). Since IFA_F_TEMPORARY == IFA_F_SECONDARY == 0x01,
and 0x01 in interface flags is IFF_UP, ALL addresses appeared as 'temporary',
making the permanent>temporary priority non-functional.

New netlink-based get_interface_ipv6_addr_nl() reads real IFA_FLAGS from
RTM_GETADDR response, correctly identifying:
- Temporary:     IFA_F_TEMPORARY=1, IFA_F_MANAGETEMPADDR=0
- Stable/mngtmp: IFA_F_TEMPORARY=1, IFA_F_MANAGETEMPADDR=1
- Legacy static: IFA_F_TEMPORARY=0

Verified: wlo1 permanent (3a7a:eff:fef5:9637) now correctly selected
for prefer_stable=1, temporary (1fb5:b7c:7538:dcf4) for prefer_stable=0.
2026-08-02 11:13:47 +03:00
evgeny 6719a1e23c IPv6: STCP dual-stack + Android config + invite fixes
- stcp_server: dual-stack (AF_INET6 + IPV6_V6ONLY=0) instead of IPv4-only
- stcp_client: getaddrinfo(AF_UNSPEC) instead of inet_pton(AF_INET)
- stcp_link: detect address family from remote_addr->ss_family
- platform_compat.h: add <netdb.h> for getaddrinfo on POSIX
- ConfigProvider.kt: add [server:main6] addr=[::]:PORT for Android
- invite_link_c.c: invite_serialize_addrs handles IPv6 (was IPv4-only)
2026-08-01 20:19:00 +03:00
Evgeny 2785845acf platform_compat: use #include <process.h> instead of getpid macro 2026-07-22 09:13:36 +03:00
Evgeny b1bf27d023 fix Windows warnings: getpid, htole64, gettimeofday, socket_t mismatches, radix min 2026-07-22 09:08:19 +03:00
Evgeny e438e19f9e Add cross-platform utun_mkdir() wrapper for Windows compatibility 2026-07-13 06:44:18 +03:00
Evgeny 797c0736a7 headers: add extern "C" guards for C++ interop (chatgui)
Added #ifdef __cplusplus / extern "C" { ... } / #endif to ~65 headers
in src/ and lib/, enabling the C library to be linked into C++ code (chatgui).
Fixed packet_dump.h (added missing header guard) and etcp_bbr.h
(#pragma once guard).
2026-07-06 11:44:29 +03:00
Evgeny 389ef00da6 refactor: split socket meta 'type' into config_type and nat_type — separate config (PUBLIC/NAT/PRIVATE) from detected NAT (EIM/STRICT/DIRECT) across NODEINFO, conn_mgr, route_bgp, route_node, etcpmon; win32 compat fixes (memmem, SHUT_WR, tun test_mode, tcp_proxy guards) 2026-07-02 18:58:34 +03:00
Evgeny c24a6367cc add IPv6 default route interface auto-detection for permanent/temporary IPv6 without netif
- get_default_route_netif_index(): UDP connect trick + getifaddrs to find default route iface
- etcp_socket_add(): auto-detect netif_index when not specified in config
- queue_new() API: explicit index_offset/index_size params instead of implicit from hash_size
- radix: cleanup types (uint8_t*), replace bzero/bcmp with memset/memcmp, remove kernel ifdefs
- route6_lib: new IPv6 routing library + get_node_v6_routes()
2026-05-10 00:05:23 +03:00
Evgeny d0d4199273 etcp: unified send hook via etcp_udp_send, remove loss_rate, add dummynet_filter inline mode, rewrite BGP test
- Add etcp_udp_send_fn_t hook typedef, send_hook/send_hook_ctx fields to ETCP_LINK
- Implement etcp_udp_send() wrapper — all UDP sends go through one point
- Remove loss_rate from ETCP_SOCKET, CFG_SERVER, config parser, send path
- Add dummynet_filter: inline send-hook with loss/delay, no proxy socket needed
- Rewrite test_bgp_route_exchange: 3-node chain A(2 links)↔B↔C, 7 phases
  with dummynet_filter-based link failure/recovery simulation
- Clean up tests: remove skeleton test_routing_mesh, 6 debug/stale test files
- Refactor test_etcp_simple_traffic and test_pkt_normalizer_etcp (remove debug spam)
- Fix test_etcp_two_instances: remove private field access, fix false PASS on timeout
2026-04-27 12:43:52 +03:00
Evgeny 595d2b177b Refactor: Replace custom tc_hton*/tc_ntoh* with standard htobe16/be16toh/htobe32/be32toh, move htobe16/be16toh to platform_compat.h 2026-04-25 01:16:09 +03:00
Evgeny 6284a95267 Fix: Define tc_htonl/tc_htons as macros before winsock2.h to avoid struct-in_addr redefinition 2026-04-25 00:59:50 +03:00
Evgeny aafa0cfcab Fix: Add portable tc_htonl/tc_htons/tc_ntohl/tc_ntohs macros, replace winsock2-incompatible hton*/nto* in NAT test files 2026-04-25 00:52:33 +03:00
Evgeny 45a181370f Add htobe32/be32toh macros for Windows build 2026-04-24 14:44:24 +03:00
Evgeny 6aedf5fe91 Replace buggy get_default_route_ip() with get_outgoing_local_ip() for reliable local IP detection
- Add lib/getmyip.c/h with get_outgoing_local_ip() using UDP connect+getsockname
- Update etcp_socket_add() to use new function for 0.0.0.0 and :: bindings
- Support both IPv4 (8.8.8.8) and IPv6 (2001:4860:4860::8888) auto-detection
- Remove broken get_default_route_ip() from platform_compat (it returned gateway IP, not local IP)
- Keep get_interface_ip_by_index() for explicit interface bindings
- Update Makefile.am to include new getmyip module
2026-04-24 14:07:41 +03:00
Evgeny b466d14fe4 Добавлено поле interface_addr в ETCP_SOCKET и interface_ip/port в BGP_NAT_CHECK_REQ
- platform_compat: get_interface_ip_by_index() для получения IP по ifindex
- ETCP_SOCKET: interface_addr заполняется из конфига/interface/default route
- BGP_NAT_CHECK_REQ: добавлены interface_ip/interface_port (network byte order)
- route_bgp_send_nat_check_req: отправляет interface_addr линка
- route_bgp_handle_nat_check_req: принимает interface данные в sockaddr-заглушку
2026-04-22 18:16:49 +03:00
Evgeny 389124d327 Fix test_bgp_route_exchange: correct IP byte order constants and platform_compat.h endian include 2026-04-13 14:05:32 +03:00
jeka 473190281a routing базово работает 2026-03-09 23:07:38 +03:00
Evgeny f168f1dc8b 1 2026-03-08 19:05:31 +03:00
jeka 2beb945bb0 1 2026-03-08 17:31:56 +03:00
jeka b27ea97055 1 2026-02-22 23:28:11 +03:00
jeka 3ab19094d0 Fix: segfault in ETCP tests and add wintun.dll to gitignore
- Fix segfault in ETCP tests by initializing uECC RNG in sc_init_local_keys()
- Fix segfault during cleanup by adding reference counting to socket_platform_cleanup()
- Add wintun.dll to .gitignore
- Update AGENTS.md and platform compatibility headers

All 19 tests now pass successfully.
2026-02-16 23:36:50 +03:00
jeka 4a3c5724b7 Windows: Исправлен запуск utun - TUN, логирование, права администратора
- Добавлен platform_compat.c с кроссплатформенной генерацией случайных чисел
- Исправлена генерация ключей и node_id на Windows (вместо /dev/urandom)
- PID файл отключен по умолчанию на Windows
- Добавлено двойное логирование: файл utun.log + консоль
- Добавлен манифест Windows для запроса прав администратора
- Исправлено завершение программы при ошибках отправки (Network unreachable)
- TUN инициализация включена по умолчанию
- Исправлен main loop (instance->running = 1)
2026-02-16 14:31:16 +03:00
jeka c8af35c4b9 Fix u_async: Windows socket registration, timers, and poll issues
- Remove FD_SETSIZE check for Windows sockets (can have any value)
- Fix process_timeouts to handle all expired timers (continue instead of break)
- Handle case when no sockets to poll (sleep instead of calling poll)
- Disable wakeup pipe on Windows (incompatible with WSAPoll)
- Add gettimeofday and ssize_t implementations for Windows
2026-02-15 17:38:45 +03:00
Evgeny f510d78bb5 Fix Windows: use sys/time.h for gettimeofday, remove custom implementation 2026-02-15 12:57:53 +03:00
Evgeny 4403c46788 Fix Windows build: skip gettimeofday on MSYS2, force recompile ecc_platform_specific 2026-02-15 12:26:32 +03:00
Evgeny 0798b149ab Fix Windows build: use WSAPoll instead of poll for linking 2026-02-15 03:54:35 +03:00
Evgeny 605a928350 Fix Windows build: POSIX dependencies (netdb.h, fork, setsid, SIGHUP, etc.)
- Wrap POSIX headers (netdb.h, ifaddrs.h, net/if.h) in #ifndef _WIN32 in config_parser.c
- Add Windows stub for get_netif_index() - returns 0 (no interface binding)
- Wrap daemonize() function for Windows - returns 0 (no fork/setsid support)
- Replace setlinebuf() with setvbuf() for Windows compatibility
- Wrap SIGHUP signal handler in #ifndef _WIN32
- Add explicit poll() declaration for Windows in platform_compat.h
- All 22 tests pass on Linux
2026-02-15 03:26:02 +03:00
Evgeny c83fdeeaad Fix Windows build: add sa_family_t typedef, replace arpa/inet.h, fix ll_queue warnings
- Add sa_family_t typedef for Windows in platform_compat.h
- Add forward declaration of struct ll_queue in ll_queue.h to fix warnings
- Replace arpa/inet.h includes with platform_compat.h in:
  tun_linux.c, etcp_connections.c, route_lib.c, route_bgp.c,
  utun_instance.c, routing.c, utun.c, packet_dump.h, config_parser.c
- All 22 tests pass on Linux
2026-02-15 03:06:02 +03:00
Evgeny 9b1d43996e Remove #include <poll.h> from Windows section - already in winsock2.h 2026-02-15 02:58:32 +03:00
Evgeny 1bd4bf5d11 Fix Windows build errors: config_parser.h, poll(), localtime()
- Replace sys/socket.h with platform_compat.h in config_parser.h
- Add #include <poll.h> for Windows in platform_compat.h
- Fix localtime() type mismatch: cast tv.tv_sec to time_t
- All 22 tests pass on Linux
2026-02-15 02:56:08 +03:00
Evgeny 0688efcd0e Fix platform_compat.h - remove duplicate definitions for MSYS2
- Remove duplicate struct pollfd (already in winsock2.h)
- Remove duplicate struct timezone (already in time.h)
- Remove duplicate nanosleep (already in pthread_time.h)
- Add fcntl.h include for _O_BINARY
- Use platform_pipe/fcntl to avoid naming conflicts
- All 22 tests pass on Linux
2026-02-15 02:52:27 +03:00
Evgeny 0c43a633b9 Add platform_compat.h for Windows POSIX compatibility
- Add platform_compat.h with Windows implementations of:
  * gettimeofday() using GetSystemTimeAsFileTime
  * poll() using select()
  * pipe() using _pipe()
  * fcntl() using ioctlsocket for O_NONBLOCK
  * pollfd structure and POLL* constants
  * strcasecmp/strncasecmp macros

- Update debug_config.c and u_async.c/h to use platform_compat.h
- Remove POSIX-specific headers (arpa/inet.h, sys/time.h, etc.)
- All 22 tests pass on Linux
- Fixes build errors on Windows MSYS2
2026-02-15 02:46:41 +03:00