Commit Graph
2171 Commits
Author SHA1 Message Date
evgeny 9348706736 etcp_keepalive: протокол смены keepalive-режима (standby/normal) + событие active mode
- новый модуль etcp_keepalive.c/h: keepalive-пакеты, таймер, адаптивный период,
  согласование при handshake вынесены из etcp_connections.c как есть
- протокол KEEPALIVE_REQ/RESP (0x09/0x0A): мобильный узел при смене active mode
  шлёт желаемый режим; отвечающий считает max (standby при любом standby), не-мобильный
  применяет как есть; инициатор применяет согласованный режим после RESP
- режимы: NORMAL (3с, адаптивный рост), STANDBY (30с, ka_pinned=1 без роста)
- active mode как событие: utun_add/remove_activity_cbk; подписчики topo_group
  (nodeinfo) и etcp_keepalive (рассылка REQ всем линкам)
2026-08-12 20:32:57 +03:00
evgeny ff84d0d986 1 2026-08-12 20:05:13 +03:00
evgeny ef115e0539 android: bind v4 server to real interface IP instead of 0.0.0.0 2026-08-12 19:17:37 +03:00
evgeny 0492b19468 topo_group_connect: infinite reconnect cycle + connecting status for GUI
- dedup double ETCP_CONN_STATUS_UP (UDP+TCP links) in topo_group_new_conn
- close conn_mgr handle on TIMEOUT in Phase2/3 (fix stuck 'already connecting')
- infinite Phase1→2→3 cycle with pause (1s active / 30s standby)
- CHAT_EVT_CONNECTING_NODES: yellow circle in member list while connecting
- Android: client_activity wiring via onStart/onStop + nativeSetActive
- function-level comments in topo_group_connect.c
2026-08-12 18:49:16 +03:00
evgeny 54ad03185b topo_group_connect: infinite auto-connect cycle with pause + connecting nodes notification
- client_activity: desktop/server now ACTIVE by default, only mobile starts STANDBY
- topo_group_connect: endless Phase1→2→3→1 cycle until connected
- Pause between failed Phase2/3 attempts: 1s active, 30s standby
- on_down always triggers cycle_restart when active_conn_count=0
- re-init destroys previous state and starts fresh
- CHAT_EVT_CONNECTING_NODES event notifies GUI of current connecting nodes
- Android: ConfigProvider default mode='auto', PTT fix, UDP log timer fix
2026-08-12 18:05:44 +03:00
evgeny 5d02a6d419 android: debug categories from GUI, fix poll log format, event loop sleeps until traffic
- android_jni_bridge: utun_bridge_set_debug_level actually calls debug_set_level / debug_set_category_level_by_name (was stub)
- SettingsScreen: CATEGORIES updated to match current g_debug_categories from debug_config.c
- ConfigProvider: persist category levels in [debug] section of generated INI config
- u_async: poll() log uses computed timeout_ms instead of confusing %d.%dms format
- u_async: timeout_node char name[16] → const char* name (no truncation, smaller struct)
- memory_pool: pool alloc/free debug logs moved from DEBUG to TRACE
- instance_lite: poll timeout changed from 10ms (100tb) to infinite (-1) — sleeps until traffic
- instance_lite: removed useless heartbeat timer
2026-08-12 09:02:19 +03:00
evgeny a73cc1beea fix: conn_reset only on got_initial_pkt==0 or sess_changed
- etcp_link_enter_init: new link on live conn sends NOINIT, not full reset
- etcp_link_enter_reinit: don't conn_reinit on single link recovery, preserve inflight
- handle_nl_link: fall through to remove_iface_sockets when if_indextoname fails
- duplicate INIT: add INFO log for diagnostic

Test: sequence checking (gaps=0 dups=0), exact socket/link counts, stale link
detection, conn health checks, full disconnect+reconnect phase
2026-08-12 00:18:33 +03:00
evgeny 8583d4216f fix auto_socket: handle_nl_link silently skipped on if_indextoname failure for deleted interfaces
When ip link del removes an interface, the kernel sends RTM_DELLINK after the interface is unregistered from the name table.
if_indextoname fails and handle_nl_link silently returned without calling remove_iface_sockets,
causing old ETCP sockets to accumulate indefinitely.

Fix: fall through to remove_iface_sockets(ifindex) even when if_indextoname fails.

Test: added diagnostics (diag_dump_state, per-category debug levels to file) to verify socket/links cleanup.
2026-08-11 23:30:31 +03:00
evgeny b503fa4418 etcp: cyclic link_id, link close on addr change, inflight nullify; test rewrite 2026-08-11 23:10:24 +03:00
evgeny d4a170b5c7 auto_socket: TCP links support, chat_sync retry on socket change, link dedup by is_tcp 2026-08-11 18:57:24 +03:00
evgeny fec3ea38a7 member detail: structured display with addresses, connections, BGP summary and socket names
- Extend MEMBER_DETAIL_LINK_SIZE to 63B with 20B sock_name per link
- Replace link_count with links_up/links_down (two uint16) in sock snap
- Add BGP hop list collection via topo_node_best_hop_list, post as CHAT_EVT_BGP_INFO
- Add direct RTT summary text via same event
- Rework AccountList detail panel: header + QTextEdit with monospace layout
- Display protocol (TCP/UDP), socket name line, colored dots for connections
- Show [up/down] link counts for self listen sockets
- Remove * prefix from link count display in Android
2026-08-11 16:05:35 +03:00
evgeny 5a42741d06 android: restore live member/connection updates lost in Kotlin source restore
- ChatRepository: MemberWire, parseMemberWire, cleanSocketName, parseMemberDetail, LinkStatus.linkId, LocalSocketState.linksUp/linksDown
- ChatViewModel: handlers 24/25/22, fix 16 (selectedMember update), 17 (in-place sync + status!=1 refresh), moder param
- MemberListScreen: compact header, no-dot addresses, TextAlign.Start connections, cleanSocketName, fonts 13sp, spacing 4dp, self *[up/down]
- SettingsScreen: linksCount -> *[linksUp/linksDown]
- NativeLib: moder in setMemberFlags JNI
2026-08-11 14:06:17 +03:00
evgeny 3f5dd43109 android: restore Kotlin sources + fix build
- Restore chat Kotlin sources deleted in d773f17 (refactor STCP)
  from d773f17~1: ChatApplication, MainActivity, data/, headless/,
  viewmodel/, ui/screens/, ui/components/
- Add InviteLinkDialog.kt (new file, never committed)
- Add missing libcrypto.a for arm64-v8a and x86_64
  (cross-compiled OpenSSL 3.5.5 via NDK 29)
- Build and install successful
2026-08-11 13:50:45 +03:00
evgeny f667e7bd74 fix: prevent use-after-free in etcp_ack_recv when link closed with pending inflight
When etcp_link_close() frees a link while INFLIGHT_PACKET entries
still reference it via last_link, a later ACK causes SIGSEGV in
bbr_main(link->bbr=NULL).

Fix:
- etcp_inflight_nullify_link(): nullifies last_link in both
  input_wait_ack and input_send_q for entries pointing to dead_link
- Called from etcp_link_close() before u_free(link)
- Guard etcp_ack_recv: check acked_pkt->last_link->bbr before
  accessing BBR/inflight stats
- Also fix bbr leak in etcp_link_close !link->conn path

Verified: 30/30 runs of test_etcp_link_stress pass (was ~50% crash)
Full suite: 71/71 pass
2026-08-11 13:37:42 +03:00
evgeny 63b1f1bc16 fix: init client_type and keepalive_interval in utun_instance_init()
utun_instance_init() did not call instance_init_common(), leaving
instance->client_type and instance->keepalive_interval as 0.
This broke the INIT handshake in V4 protocol: server wrote
keepalive=0 into INIT_RESPONSE, causing negotiate_keepalive
to see 0 and client to receive empty keepalive.

Also added guard: keepalive < 100ms clamped to 100ms with ERROR log.
2026-08-11 13:31:18 +03:00
evgeny bd6cd17bdf tests: fix close/restart detection after loopback_conn change
bb0866b changed close/restart notifications from NULL to loopback_conn().
Remove !conn check — use entry->len==9 alone to distinguish (9 bytes = svc_id+node_id, data always longer).
2026-08-11 12:21:10 +03:00
evgeny 0f1bd3d120 keepalive handshake: device_type + keepalive negotiation in UDP/TCP INIT
- Добавлен device_type (1 байт, CLIENT_TYPE_*) в INIT_REQUEST и INIT_RESPONSE
- Добавлен keepalive_interval (2 байта) в INIT_RESPONSE
- STCP handshake расширен с 43 до 46 байт (device_type+keepalive)
- negotiate_keepalive(): оба desktop/server → min, иначе (есть mobile) → max
- keepalive_interval вынесен в UTUN_INSTANCE для использования в handshake
- stcp_client_connect() принимает device_type и keepalive_interval
- peer_device_type/peer_keepalive_interval передаются через stcp_link в ETCP_LINK
2026-08-11 11:16:27 +03:00
Evgeny 43aca4a41b tcp_proxy_server: fix reentrant UAF in read_queue_drain_cb via loopback 2026-08-10 22:25:16 +03:00
Evgeny e7623e38b2 config_parser: add missing tcp_proxy_server options (fib, so_mark, netif, bind_ip); tcp_proxy_server: move diag log to TRACE 2026-08-10 22:07:12 +03:00
Evgeny bb0866b4c3 tcp_proxy: split svc_id into SERVER(0x04) and CLIENT(0x08), fix loopback conn=NULL 2026-08-10 22:00:39 +03:00
Evgeny 5a404fbc97 tcp_proxy_server: add fib/so_mark/netif/bind_ip socket options 2026-08-10 20:12:07 +03:00
evgeny 544c77efff unify TCP_SOCKET into ETCP_SOCKET with is_tcp flag; add local+remote addr to member detail links with arrow display 2026-08-10 12:06:32 +03:00
evgeny 477b4dfc98 move is_server indicator from per-connection to per-link in member detail and links JSON 2026-08-10 10:58:14 +03:00
evgeny 496f0f7d2b add server/client (S/C) indicator based on ETCP_LINK.is_server in connection monitor, member detail, and Android JSON 2026-08-10 10:47:52 +03:00
evgeny cf956cf2f0 add proxy server/client indicator (S/C) in connection monitor 2026-08-10 10:30:07 +03:00
evgeny f1941e61a2 fix: MemberLinkSnap/MemberSockSnap port int→uint16_t avoids stack garbage 2026-08-10 10:03:43 +03:00
evgeny 312876a0b2 fix: add strbuf.c/h to lib/Makefile.am 2026-08-10 00:20:02 +03:00
evgeny f2228202e3 fix: FORTIFY vsnprintf crash on Android + foreground service type
Root cause: etcp_on_up/etcp_on_down/etcp_conn_process_send_queue
used fixed buffers (links_str[256], l_status[256]) with snprintf
chains in loops over links. With 15+ links (IPv6 addresses),
sizeof(buf)-offset turned negative → vsnprintf size=(size_t)(-17)
→ FORTIFY abort on Bionic.

Fixes:
- lib/strbuf.h/c: safe growable printf buffer (auto-realloc)
- etcp.c: 3 snprintf chains → strbuf
- debug_config.c: BUF_ADVANCE macro prevents offset overflow
- android_jni_bridge.c: bridge_log va_list fix, set_member_flags guard
- chat_core.c: TAGS_ADVANCE macro in tags_commit
- AndroidManifest.xml: dataSync→specialUse (time limit exhausted)
- stcp: ed25519 pubkey exchange, tcp link addr/status in JNI bridge
- etcp_router: encrypted flag + ECDH per peer-pair
- node_conn_direct: TCP link support
- topo_node: group nodes cleanup
- media_delivery: buffer overflow fix
- test_stcp: ed25519 key exchange test
- tests: invite_group_create + Makefile update
2026-08-10 00:11:30 +03:00
evgeny ae80dae8ee tests: add Stage 7 merkle stress test — 13 instances, 5s spam, hash convergence
10 spammers (1-30ms random) + 2 observers (1-10ms), star topology via hub.
5s of concurrent modifications, then verify all 13 merkle root hashes
are identical and tree is internally consistent (recompute vs stored).
2026-08-09 19:39:41 +03:00
evgeny d8921f0e3d merkle_sync: fix infinite WAL growth from bg_check
- _recompute_bucket: skip INSERT OR REPLACE when hash unchanged,
  also skip DELETE when row doesn't exist (was always writing)
- bg_check interval: 100ms → 5000ms (was writing 10x/sec × 4KB/page
  into WAL = ~1.4GB over hours)
- bg_timer: round-robin across channels instead of only first
- bg_timer: periodic WAL checkpoint (every ~60s) to prevent
  unbounded WAL growth from any source
- test: sync ms_session struct copy with real definition

- stcp_link: handle race where conn already CLOSED before close
- stcp_client: remove double-free c->free_on_close = cli
- etcp_connections: stcp_link_close on TCP link down
- u_async: round sub-ms timeouts to 1ms to avoid busy-loop
2026-08-09 19:25:36 +03:00
Evgeny a646b35b9a etcp_router: router_deliver INFO→TRACE (спам на каждый пакет) 2026-08-09 18:15:25 +03:00
Evgeny e71f68736b socket_monitor: fix RT_ROUNDUP + пропавшая скобка функции (FreeBSD) 2026-08-09 17:56:39 +03:00
Evgeny f9417f06b4 BSD route sockaddr парсинг: addr/plen/gw/dev в INFO; убрал спам v6_send/v6_recv 2026-08-09 17:51:33 +03:00
Evgeny d8bae76ac7 socket monitor: BSD ifindex + UP/DOWN + фильтр спама; fallback idx%u → ? 2026-08-09 17:39:31 +03:00
Evgeny 15e3eeae65 socket monitor: осмысленные INFO-логи с именем интерфейса (UP/DOWN/NEW/DEL/route) 2026-08-09 17:32:50 +03:00
Evgeny 2cba839de4 Убрал DEBUG_CATEGORY_DEBUG: сообщения разбросаны по модульным категориям (+CHAT=25, MEDIA=23) 2026-08-09 17:24:15 +03:00
Evgeny 869f7c60d5 debug: add PROXY category, move all proxy logs to it 2026-08-09 16:31:21 +03:00
Evgeny 0de44e3117 remove spam TRACE messages: topo_group_find_conn_for_node, raw_recv, CRYPTO_DECRYPT_OK 2026-08-09 15:55:15 +03:00
Evgeny 6b6657c6b8 fix NTP ping-pong + normalizer counters
- ntp_node_time.c: respond to TIME_SYNC only when peer is unsynced (not always)
  Prevents infinite 10-byte ping-pong that ate bandwidth when both sides synced.

- pkt_normalizer.c: add in_total_pkts/in_total_bytes increments in
  etcp_input_ready_cb (real send path), matching pn_packer_send (test path).

- conn_mgr_core.c/conn_mgr_priv.h: full INVITE_INFO_RESP with channel info
2026-08-09 15:38:56 +03:00
evgeny 229a508022 etcpmon: add Makefile to git (was ignored by *.gitignore Makefile pattern) 2026-08-09 14:20:46 +03:00
evgeny c61c0639b9 remove utun.sh 2026-08-09 14:08:48 +03:00
evgeny 9066ae6a1f tests: add test_utils.h to git (was ignored by tests/test_* rule) 2026-08-09 14:06:34 +03:00
evgeny 6337d0f608 tests: add -I$(srcdir) to AM_CPPFLAGS for test_utils.h in VPATH builds 2026-08-09 14:01:31 +03:00
evgeny 4bb9f9e9c2 crypto: EVP_PKEY_generate → EVP_PKEY_keygen + OPENSSL_API_COMPAT для BSD/LibreSSL 2026-08-09 13:59:38 +03:00
evgeny d8337b9c3b whisper: опциональный configure --with-whisper; chatgui: парсер [debug]; stdint.h в AC_CHECK_HEADERS 2026-08-09 13:54:22 +03:00
evgeny 7f901c01e1 etcp: переупорядочить close + защита state==2 во всех API-точках; topo: правильная очистка group nodes и registry; chat/member: новый модуль member_sync; chatgui: обновления транспорта и UI 2026-08-09 12:39:53 +03:00
evgeny b2e4aadbf0 e2e: AES-128-CCM encryption via BGP router (ROUTER_FLAG_ENCRYPTED), ECDH key per peer-pair from NODEINFO pubkeys, cache 8 entries
- etcp_router.h/c: new flag ROUTER_FLAG_ENCRYPTED (0x04), etcp_route_send_encrypted(), inflight/retrans/send_q support
- utun_instance.h: e2e_ctx_cache[8] — per-peer sc_context_t cache with derived session key
- topo_node.c: topo_node_sign_self() — single point for Ed25519 self-signing of NODEINFO
- topo_node.c: fix stale x25519_self_sig after address update (topo_node_sign_self call)
- nat_detection.c: fix stale x25519_self_sig after in-place socket meta modification
- test_etcp_router_unit: 5 E2E tests (basic round-trip, no NODEINFO drop, tampered, cache reuse, ENCRYPTED+SIGNED combined)
- builds clean, 70/70 tests pass
2026-08-09 08:19:20 +03:00
evgeny ca176e1f24 encrypt overhead fix (33→36, noencrypt_len), mtu default 1280, connmonitor window, total_decrypted for TCP, check.sh 2026-08-08 16:56:32 +03:00
evgeny 9846599086 stcp: fix memory leaks and cleanup architecture
- stcp_conn_do_close: always deferred free for allocated conns (was else-if)
- stcp_link_on_stcp_close: don't null link->conn (close_impl needs it for rx_queue)
- stcp_link_close_impl: free rx_queue/tx_queue before close, null conn after cleanup
- stcp_client_connect: return NULL on derive_session failure (was returning dead cli)
- stcp_frame_decrypt/stcp_recv_try: dedup CRC check into stcp_check_crc helper
- test_stcp: add test8_srv_recv_close (error-recv close chain)
2026-08-08 11:42:16 +03:00
evgeny 5c8355ee63 stcp: unified recv FSM, handshake timeout, RX backpressure, opaque pointer fix
- stcp_recv_try / stcp_recv_set: unified chunk reader with raw+stream modes
  replacing duplicated stcp_conn_process_recv in server+client (~250 LOC removed)
- stcp_conn_read / stcp_conn_do_close / stcp_tx_queue_cb: unified shared functions
- continuous stream XOR: stcp_frame_encrypt now XORs len+data+CRC
- handshake timeout via uasync_set_timeout (5s server, 10s client)
- RX backpressure: stcp_rx_push / stcp_rx_resume_if_needed with hysteresis
- stcp_server_list_remove: new API fixes opaque pointer violation in auto_socket
  and 4 double-free bugs on shutdown
- removed hs_expected_len/hs_key_processed fields (replaced by callback chain)
- removed recv_buf<4096 debug workaround
- stcp_try_send const fix (takes ownership of malloc'd data)
2026-08-08 10:48:12 +03:00