Commit Graph
2210 Commits
Author SHA1 Message Date
Evgeny f7d88e5532 fix segfault in ca_ready_cb: ca_state owns all ca_ctx, single cleanup point
- Added struct ca_ctx** ctxs to ca_state (parallel array)
- ca_cleanup now frees all ctxs[i] and the ctxs array
- ca_ready_cb: removed u_free(ctx), added etcp_conn_remove_ready_cbk before cleanup
- ca_timeout_cb: removed u_free(ctx) — ctx lives until ca_cleanup
- All error paths set ctxs[i]=NULL for ca_cleanup safety
2026-07-15 11:21:31 +03:00
Evgeny 1e7585438d chat_core_connect_auto: add outbound conn to inst->connections
etcp_connection_create does NOT add conn to inst->connections list.
Without this, incoming INIT handler can't find the outbound conn
by peer_node_id and creates a new one, causing insert_link collision.
2026-07-15 11:05:27 +03:00
Evgeny a8164baf41 chat_core_connect_auto: set peer_node_id on ETCP_CONN
Without peer_node_id, incoming INIT handler can't find the existing
outbound connection, creates a new one, and fails on insert_link collision.
2026-07-15 10:51:53 +03:00
Evgeny fc6a873b5c etcp_connections: reuse existing outbound link for incoming INIT by addr
When two peers send INIT simultaneously, the first link occupies the socket.
Incoming INIT arriving after finds the existing outbound link by (ip,port)
instead of failing with 'Can not insert link to socket'.
2026-07-15 10:46:33 +03:00
Evgeny 0adf7d07ef chat_core_connect_auto: dedup addresses by (addr,port) 2026-07-15 10:32:06 +03:00
Evgeny 33aa6bbd5a auto-connect: cursor-based, no close on timeout, GC every 1s, cancel API
- ca_timeout_cb: removed etcp_connection_close, ETCP lives past 3s timeout
- ca_state.cancelled flag + chat_core_connect_auto_cancel() for external cancel
- chat_core_connect_auto returns ca_state* via out_state
- Rewritten auto_connect: cursor (ch,peer) instead of bulk collect
- GC every 1s: closes flights with no link_status after 3s
- ac_result_cb no longer clears ca_state (GC handles cleanup)
- stop: cancels all flights via chat_core_connect_auto_cancel
2026-07-15 10:24:44 +03:00
Evgeny dccf54b30b auto-connect + GUI per-channel indicators
- chat_core_connect_auto: direct ETCP connect from SQLite (no BGP)
- auto_connect: parallel connect to peers with 3s timeout, retry 10s
- RTT saved to node_addresses on disconnect
- vertical status bar + circle badge with online count per channel
- ChannelListView prevents deselection
2026-07-15 06:00:43 +03:00
Evgeny 1a0229fd4f add NTP time synchronization module 2026-07-14 20:14:00 +03:00
Evgeny f3719a28df fix: change timestamp unit from microseconds to milliseconds
- db_sync.c: last_timestamp_us → last_timestamp_ms, use tv_sec*1000 + tv_usec/1000
- db_sync_stub.c: same change
- QDateTime::fromMSecsSinceEpoch() in chatgui expects milliseconds
- 1 µs → 1 ms change fixes 'minutes ticking like seconds' display bug
2026-07-14 19:33:16 +03:00
Evgeny 5fc621690a fix: wall-clock timestamps + merkle_sync timeout + build script
- Replace get_time_us() with utun_gettimeofday() for PUSH message timestamps
  (db_sync.c, chat_core.c) — monotonic clocks differ across Linux/Windows
- Fix merkle_sync: restart session timer in _handle_request to prevent
  double-sided timeout when both nodes start member_sync simultaneously
- Fix INIT_RESP short-format: don't mark synced when my_count > peer_count
- Add db_sync_get_last_timestamp() to avoid duplicate timestamp generation
  between db_sync and chat_core on_db_sync_insert
- Fix db_sync_stub to generate timestamps consistently
- build.sh: auto-rebuild chatgui via CMake after utun build
2026-07-14 19:23:02 +03:00
Evgeny 4636a69225 fix chatgui: pass chain_hash in PUSH + start member_sync on server join
chat_sync_push: add chain_hash parameter, use it instead of zeros
  (fixes chain_hash mismatch → all PUSH messages were rejected)

on_db_sync_insert: pass computed chain_h to chat_sync_push

cs_handle_channel_join: call member_sync_start for the joiner
  (server now initiates member sync when client joins.
  Previously merkle_sync was only started by client → timeout
  because server never responded)

cs_handle_welcome: add DEBUG_INFO before member_sync_start on client side
2026-07-14 18:43:04 +03:00
Evgeny f9f516c2e9 fix chatgui: PUSH new messages to peers + comprehensive debug logging
chat_sync_push: fix PUSH format to match cs_handle_push expectations
  (was missing insert_record header: ts+dh+nid before ct+dlen+data)
  Add DEBUG_INFO log with peer count after send.

on_db_sync_insert: call chat_sync_push after successful local insert
  → new messages are now pushed to all connected peers
  Add DEBUG_ERROR to 4 silent returns (JSON parse fail, SQL errors)

chat_core_submit_message: add DEBUG_INFO entry log (ch, ct, len)

chat_core_insert_record: add DEBUG_WARN/ERROR to 7 silent returns
  (truncated record, SQL prepare fail, unknown step error)

cs_handle_push: add DEBUG_INFO for ACK send, DEBUG_ERROR for insert fail

cs_handle_send_data: DEBUG_WARN when record truncated mid-loop

cs_on_conn_up: DEBUG_INFO sync path with channel count

Full trace now shows every message: SUBMIT → insert → PUSH → RECV PUSH → ACK
2026-07-14 18:34:24 +03:00
Evgeny 58b9f28149 fix chatgui: prevent invite deadlock on connection flap
cs_on_conn_down: remove invite state zeroing on disconnection.
Only timeout callbacks and explicit protocol end (CS_MSG_ERROR,
transition to JOIN phase) clear the invite state.

Connection flap now causes automatic retry:
  conn_up → pending_invite_ch_id != 0 && !info_req_timer → resend
  CHANNEL_INFO_REQ. No deadlock possible.
2026-07-14 18:22:05 +03:00
Evgeny 8c41b44718 fix chatgui: repair INIT_RESP handler, add debug logging to all sync handlers
- cs_handle_init_resp: change silent reject len<37→len<5 (actual payload
  sent is 6 bytes, plen=5 after stripping type byte).
  Support short format (synced, peer_count+sparse_count) and long format
  (divergence, with test_pos+peer_ch). Add INFO logs at each decision.
  (fixes sync never starting after invite join — RECV INIT_RESP len=5
  was silently rejected)

- All 12 silent return branches in handlers: add DEBUG_WARN with
  handler name, peer, ch_id, and reason (makes malformed packets
  visible in logs)

- Key sync flow INFO logs:
  cs_handle_init_sync: peer_count, my_count
  cs_handle_send_data: records sent/received count
  cs_on_conn_up: invite vs sync path
  chat_core_insert_record: successful insert
2026-07-14 18:07:57 +03:00
Evgeny 2d179ec41d fix chatgui: message format, member notify, chain_hash sync
- on_db_sync_insert: parse JSON {"n":...,"ct":...,"d":...}, store
  d→data, n→node_id, ct→content_type with proper chain_hash
  (fixes JSON displayed instead of message text)
- chat_core_cursor_open: SELECT chain_hash column
- chat_core_cursor_next: include chain_hash(32) in output record
- cs_handle_send_data: parse chain_hash in received records
  (fixes chain_hash mismatch → all sync records were dropped)
- cs_handle_channel_join: post GUI_EVT_MEMBERS_CHANGED
  (fixes creator not seeing new member after join)
- cs_handle_welcome: trigger INIT_SYNC with inviter after join
  (fixes no message sync after invite join)
2026-07-14 17:46:33 +03:00
Evgeny c4751557b1 fix chatgui: ensure msg table + db_sync instance on join and restart
- chat_core_ensure_channel_ready(ch_id): idempotent — creates
  msg_<id> table + registers db_sync instance if missing
- chat_core_create_channel: refactored to use ensure_channel_ready
- cs_handle_channel_info_resp: call ensure_channel_ready on join
- chat_core_init: iterate existing channels on restart
- Fixes 'no such table: msg_<id>' after invite join
- Fixes 'no db_sync instance for ch=<id>' after restart
2026-07-14 17:22:01 +03:00
Evgeny 4254ab97bb fix chatgui: db_sync_stub + chat_sync_init for invite link join
- db_sync_stub.c: complete rewrite — proper structs, all API functions
  (db_sync_instance_add, insert_signed, set_insert_cb, select)
  Fixes db_sync_instance_add returning NULL (inst->db_sync was NULL)
- libutun/CMakeLists.txt: remove src/db_sync.c, stub replaces it
- chatgui/CMakeLists.txt: add transport/db_sync_stub.c
- utun_node.cpp: remove redundant db_sync_init/destroy,
  add chat_sync_init/destroy — server now registers svc_id=48
  Fixes 'no handler for svc_id=48' on incoming CHANNEL_INFO_REQ
2026-07-14 17:03:00 +03:00
Evgeny ccd25813f6 refactor: extract merkle_sync — universal Merkle-tree sync module
- merkle_sync.h/c: tree (5-level prefix, SHA256 buckets), wire protocol
  (HASHES/REQUEST/BATCH), sessions (10s timeout, 3 retries), async API
  with done_cb
- member_sync: thin glue layer, implements 3 data model callbacks
  (update_bucket_hash, get_items, apply_items) for chat members
- chat_sync: updated member_sync_start() calls with done_cb callback
- member_tree_hash table renamed to merkle_tree_hash
- member_sync.h public API preserved, internal tree/wire logic removed
2026-07-14 16:35:58 +03:00
Evgeny f617dcd68e db_sync: LMDB→SQLite, multi-instance, etcp_api, chatgui integration
- src/db_sync: LMDB replaced with SQLite (separate tables per instance: db_sync_name_id)
  TTL index (author, timestamp), WAL mode, per-instance peers/timers
  opaque DB_SYNC_INSTANCE* handle, insert callback, select API
  new fields: author_signature, delivered_peers, delivery_chain
  transport: etcp_api direct P2P (was etcp_router)

- src/db_sync.h: user-oriented API docs, multi-instance lifecycle

- lib/Makefile.am: liblmdb sources removed
- lib/sqlite3.c+h: SQLite amalgamation added

- topo_node: LMDB→SQLite (src/topo_node_sqlite.c moved from chatgui)

- chatgui: real db_sync.c replaces db_sync_stub.c
  chat_core: db_sync_insert_signed + dual-write insert callback
  utun_node: db_sync_init/destroy replaces chat_sync_init/destroy
  CMakeLists: stubs removed, real db_sync.c added
2026-07-14 14:17:43 +03:00
Evgeny 37417ba49d Fix: my_node_name insert inside [global] section, add button tooltips in channellist 2026-07-14 09:17:01 +03:00
Evgeny cca3511503 fix: replace deprecated SHA256 API with EVP, conditional dl linkage for Windows 2026-07-14 09:07:03 +03:00
Evgeny d70cdbb040 chatgui: preserve active channel selection on reload, members sync, profile settings, member list model 2026-07-14 08:52:10 +03:00
Evgeny c3f946fb63 chat_sync: fix join group stall — remove node_id match in cs_on_conn_up, add CS_MSG_ERROR protocol response 2026-07-13 18:11:18 +03:00
jeka 93de0aa591 agents 2026-07-13 15:46:29 +03:00
Evgeny 0c2eeb8820 chatgui: validate config options on startup, refuse to start on errors 2026-07-13 15:46:20 +03:00
Evgeny 637b21da9e debug: remove console_level/file_level — simplified output routing
Remove secondary level filtering in debug_output(). Now the only filter
is debug_should_output() (per-category + global fallback). Output goes
to file (if file_output set) or console (if console_enabled), with no
additional level check.

Removed:
- debug_set_console_level(), debug_set_file_level()
- console_level, file_level fields from debug_config_t
- debug_set_level() no longer sets console_level
2026-07-13 15:38:08 +03:00
Evgeny c0935aba6c docs: update AGENTS.md and etcp_arch.md 2026-07-13 15:21:30 +03:00
Evgeny 6bf267924d add DEBUG_CATEGORY_CONNECTIVITY for handshake/protocol lifecycle logs
New category (id=25) replaces DEBUG_CATEGORY_DEBUG in chat_sync and
chat_core. This allows enabling only protocol-level logs (SEND/RECV,
timeouts, handshake) without the noise from DEBUG category.

Changes:
- debug_config.h: add CONNECTIVITY=25, COUNT→26
- debug_config.c: add 'connectivity' to g_debug_categories
- chat_sync.c: DEBUG→CONNECTIVITY in all protocol logs
- chat_core.c: DEBUG→CONNECTIVITY in connection/create logs
- utun_node.cpp: remove hardcoded DEBUG=TRACE (now config-driven)
- chatgui.cfg: connectivity=info in debug_categories
2026-07-13 15:14:48 +03:00
Evgeny 5318476cdf chat_sync: add protocol request timeouts and SEND/RECV debug logs
- Add info_req_timer (5s) for CHANNEL_INFO_REQ — reports CONN_MGR_ERR_TIMEOUT
  to GUI on timeout, clears pending invite state
- Add join_timer (8s) for CHANNEL_JOIN → WELCOME — reports timeout on failure
- cs_on_conn_down: cancel all proto timers, reset pending invite state
- cs_send: log every outgoing message (SEND <type> to=<peer> ch=<id> len=<n>)
- Dispatcher: log every incoming message (RECV <type> from=<peer> ch=<id> len=<n>)
- Add cs_msg_name() helper for readable message type names
- pending_invite_node_id/ch_id no longer cleared immediately after send —
  kept until response or timeout, enabling proper error reporting
2026-07-13 15:06:06 +03:00
Evgeny 24294b22f6 fix: use got_initial_pkt instead of new_conn for send_reset decision
new_conn is only true for the first INIT after server restart.
Subsequent INITs from same peer (recovery loop) see new_conn=0
and revert to old logic, sending 0x05 (no reset) and overwriting
the first 0x03 response.

got_initial_pkt stays 0 until client actually sends seq=1, so
server keeps sending 0x03 across all INIT retries until client
resets and starts from seq=1.
2026-07-13 14:32:16 +03:00
Evgeny 43d95016ae fix: send INIT_RESPONSE with reset when server creates new connection after restart
When server restarts, new ETCP_CONN has session_id=0 (calloc).
If client sends INIT_REQUEST_NOINIT (0x04) with session_id=0,
the condition conn->session_id != session_id is false (both 0),
so no reset was sent. Client kept old seq numbers while server
expected seq=1, causing 'Waiting for initial packet' deadlock.

Fix: add || new_conn to the condition — when server created a
fresh connection (was restarted), always send reset to client.
2026-07-13 14:19:27 +03:00
Evgeny 41e0736b75 etcp_connections: force reinit when client sends ETCP_INIT_REQUEST (reset)
Server now checks both code==ETCP_INIT_REQUEST and session_id mismatch
to decide send_reset. Previously only session_id was checked, so if
session matched (both sides had 00000000), reinit was skipped even
when client explicitly requested reset (code 0x02).

Client side already correct: handle_init_response_client:1473 calls
etcp_conn_reinit if pkt_code==ETCP_INIT_RESPONSE (0x03).
2026-07-13 13:29:58 +03:00
Evgeny 1d29cab751 etcp: INFO-level TX DATA log + Initial packet received log
- 1133: DEBUG_DEBUG -> DEBUG_INFO for TX DATA (seq, len, retry, queue lengths)
- 1437: add DEBUG_INFO when initial packet seq=1 accepted

These two INFO lines show the exact order of first sends and receives
to diagnose INIT sequencer sync without guessing.
2026-07-13 13:19:08 +03:00
Evgeny d0f5a2970f etcp_connections: improve INIT diagnostics (demote spam, add type/source/fields)
- 1556: Normal decryption failed -> DEBUG_DEBUG (expected for INIT, no more spam)
- 1581: added 'INIT X25519 OK from %s' with source address
- 1604-1617: INFO log for decrypted packet type (PING/PONG/INIT) with peer_id+src
- 1662-1668: expanded INIT accepted log with all fields:
  peer_id, mtu, link_id, socket_id, type, only_local, src_ip:src_port,
  session_id, actual src (UDP) — shows NAT mismatch
2026-07-13 11:01:50 +03:00
Evgeny 03701f525f conn_mgr: add missing sc_init_ctx before sc_set_peer_public_key
Without sc_init_ctx, crypto_ctx.initialized==0, sc_set_peer_public_key returns
SC_ERR_NOT_INITIALIZED, and all subsequent sc_encrypt (INIT, etc) fail with
'encryption failed' error 2. Fixed in cm_start_phase_direct and
reverse-connect path (both places that create ETCP_CONN for conn_mgr).
2026-07-13 10:03:15 +03:00
Evgeny 89b1a01448 invite+clipboard+conn_mgr: sock_meta for alien nodes, clipboard fix, bg_ping fix
- chat_core_connect_from_invite: add TOPO_SOCKMETA4 (id=0, UNKNOWN, UNKNOWN)
  so cm_has_direct_ip/cm_start_phase_direct can match socket_id=0 addr
- conn_mgr: cm_bg_ping_timer_cb reads real addr from nq->node->v4_addrs
  instead of NULL; added cm_bg_ping_noop_cb per required etcp_send_ping_to_socket
- invitedialog: set both QClipboard::Clipboard and Selection on Linux/X11
2026-07-13 09:37:46 +03:00
Evgeny e3b32cf4d3 conn_mgr: fix all etcp_route_send calls (dgram was NULL) + improve error diagnostics
- conn_mgr.c: 5 call sites used queue_entry_new(data_size) with data[] instead
  of dgram — all etcp_route_send calls silently dropped. Fixed by switching to
  dgram-based allocation (queue_entry_new(0)+u_malloc) matching all other callers.
- DIRCECT_REQ reuses already-allocated pkt as qe->dgram (no extra memcpy).
- etcp_router.c:1078 — 'empty entry' now shows dgram=%p len=%u dst=0x... force=%d
- etcp_connections.c:1139 — 'bad args' now shows all arg pointers to identify NULL
- etcp_connections.c:1145 — 'no socket' now shows addr_family=%d
- conn_mgr.c:633 — 'no candidates' now notes direct+reverse failed
2026-07-13 08:49:20 +03:00
Evgeny 2d93dd66c8 chatgui: fix Windows build - replace netinet/in.h with socket_compat.h 2026-07-13 08:08:27 +03:00
Evgeny 85a91a1320 chatgui: invite link connect flow + GUI_ERROR always-on diagnostics
- debug_ui.h: remove NDEBUG guard so GUI_ERROR works in Release builds
- invite_link.h/cpp: add error field to InviteData with specific failure reason
- joindialog: show exact decode error in QLabel instead of generic message
- chat_sync: implement invite connect flow (CHANNEL_INFO_REQ/RESP, JOIN, WELCOME)
- topo_node_sqlite: node/address table init and lookup
- utun_node: getInviteAddresses fallback from ETCP sockets
- minor fixes in mainwindow, chat_core, gui_bridge
2026-07-13 08:06:19 +03:00
Evgeny 102816d0dc node_config: load() returns true on parse success; main: specific diagnostics per missing field 2026-07-13 07:52:49 +03:00
Evgeny c65940f499 Copy Qt platforms/qwindows.dll plugin alongside executable 2026-07-13 07:44:06 +03:00
Evgeny 79bdafc9a7 Optimize recursive DLL resolution: scan only newly added DLLs 2026-07-13 07:43:25 +03:00
Evgeny cb1021f231 Recursive DLL dependency resolution via objdump for build.sh windeployqt fallback 2026-07-13 07:36:51 +03:00
Evgeny 58503907b5 Use objdump -p for smart DLL dependency discovery as windeployqt fallback 2026-07-13 07:33:49 +03:00
Evgeny 666507d3fe Move Qt DLL deployment from CMake to build.sh (windeployqt + manual fallback) 2026-07-13 07:30:56 +03:00
Evgeny f0f20c158b Simplify windeployqt: use PATH, add diagnostics, --no-compiler-runtime 2026-07-13 07:23:35 +03:00
Evgeny ed5ccd1ffb Add windeployqt post-build step for automatic Qt DLL deployment on Windows 2026-07-13 07:19:37 +03:00
Evgeny 65611790fa Fix enterEvent signature for Qt5/Qt6 compatibility 2026-07-13 07:06:58 +03:00
Evgeny e74240f0dd Add my_ed25519_privkey field to UTUN_INSTANCE struct 2026-07-13 07:01:42 +03:00
Evgeny e438e19f9e Add cross-platform utun_mkdir() wrapper for Windows compatibility 2026-07-13 06:44:18 +03:00