Commit Graph
2373 Commits
Author SHA1 Message Date
Evgeny 1b21ee9d73 chatgui: live NTP-corrected clock (HH:mm:ss) on Status page with per-second sync 2026-07-19 20:38:22 +03:00
Evgeny a7d842440c chatgui: split chat_core into chat_conn_mgr — connection manager with rotation, max_parallel slots, background ping, per-connection DOWN callback
- chat_conn_mgr.c/h: new connection manager (1 per instance, global in g_cc)
  - cm_rotation() — single rotation method: random addr pick, INIT, retry
  - 10 parallel slots per node (CM_MAX_PARALLEL), evict worst RTT on excess
  - DEAD slot reuse before close — close only when replacement ready
  - per-connection DOWN callback via etcp_conn_add_down_cbk
  - background ping cycle: random node→random addr RTT measurement
- chat_core.c: added g_cc.conn_mgr field, init/destroy/getter
- chat_sync.c: migrate to new API, add_node() at WELCOME/JOIN/PEER_UPSERT
- Removed old ca_state/ca_ctx/ca_* single-flight code
2026-07-19 19:00:29 +03:00
Evgeny 98bfb9dcd2 chatgui: per-event sound settings with DB persistence
- Sound files loaded from filesystem (sound_dir in INI config, absolute or relative)
- Per-event enable/disable + volume stored in DB (ui_state table)
- SoundManager: setEvent(), effective volume = master * per-event
- SoundSettingsPage UI: 4 event rows (checkbox + slider)
- chat_core_save_ui_state() for async DB writes via uasync thread
- DbManager::getUiStateInt() for reading settings from GUI thread
- Default sounds copied to sounds/ dir next to DB, config entries written
2026-07-19 15:17:52 +03:00
Evgeny 1593079da8 chatgui: fix sound_manager use-after-free crash on Windows
- Keep mp3Data + ma_decoder alive for sound lifetime (was freed before audio thread)
- Remove MA_SOUND_FLAG_DECODE — stream from decoder instead of pre-decoding
- Shutdown in reverse order: sound → decoder → mp3Data
2026-07-19 14:58:34 +03:00
Evgeny c2ad2e78c3 chatgui: add sound playback via miniaudio (MP3 notification sounds)
- SoundManager singleton wraps ma_engine + ma_sound (non-blocking, background thread)
- MP3 files embedded in QRC, decoded to PCM at startup with MA_SOUND_FLAG_DECODE
- miniaudio.h (MIT) in lib/, IMPLEMENTATION in separate miniaudio_impl.c
- Sound settings page in SettingsDialog: enable/disable, volume slider (0-100%)
- Config keys [gui] sound_enabled, sound_volume
- Incoming messages trigger msg_incoming.mp3 sound
2026-07-19 14:46:21 +03:00
Evgeny f6f7e12192 refactor: demote high-frequency debug logs (raw_recv/dispatch→TRACE, normalizer→DEBUG), NTP drift→WARN 2026-07-19 13:53:27 +03:00
Evgeny 42041dfe84 feat: log connection status changes at general=info level (NEW/UP/DOWN/DELETE) 2026-07-19 13:41:25 +03:00
Evgeny beed7a4e07 fix: INIT reset logic — reset only on session change or got_initial_pkt, always sync session_id 2026-07-19 13:18:42 +03:00
Evgeny 58df4d8571 ntp_node_time: переход с etcp_router на raw ETCP (P2P)
- Добавлен ETCP_ID_NTP_TIME=0x04 (raw ETCP packet ID)
- Удалён ETCP_RT_ID_NTP_TIME=0x12 (router-сервис)
- ntp_node_time.c: etcp_router_bind/send → etcp_bind/etcp_send
- send_time_sync() принимает ETCP_CONN* вместо dst_node_id
- recv_cb разбирает raw dgram вместо SVC_ROUTE_HDR
- Обновлены doc-файлы
2026-07-19 12:16:37 +03:00
Evgeny 2e7c32c893 fix(db): use INSERT ... ON CONFLICT instead of INSERT OR REPLACE for nodes table
INSERT OR REPLACE deletes the old row and inserts a new one,
resetting unspecified columns (online, update_ts) to DEFAULT 0.
This was wiping online=1 set by cs_on_peer_status_changed/member_sync_set_online.

Replaced 5 INSERT OR REPLACE INTO nodes with INSERT INTO ... ON CONFLICT
DO UPDATE SET — only updates the specified columns, preserving online status.

Files:
- chat_core.c:638 (invite flow)
- chat_sync.c:1045 (CHANNEL_INFO_RESP), 1193 (JOIN), 1449 (PEER_UPSERT)
- topo_node_sqlite.c:121 (BGP node_put)
2026-07-19 11:16:26 +03:00
Evgeny cf46a59d3a fix(chatgui): replace qDebug with DEBUG_INFO for online trace logs 2026-07-19 11:04:35 +03:00
Evgeny ac0d1c18ed debug(chatgui): add online status trace across full chain
- cs_is_peer_online: log found/init/links/online
- cs_on_peer_status_changed: log channel_count + found_in_channel
- cs_handle_welcome/cs_handle_channel_join: log before cs_post_channel_online
- MainWindow::onChannelPeersOnline: log cid+online
- ChannelList::setChannelPeersOnline: log search/rows, each row cid+match, SET or NOT FOUND
- ChannelList::loadChannels: log each added row cid+name
2026-07-19 10:58:25 +03:00
Evgeny 9de16be012 fix(chatgui): remove duplicate loadChannels after JoinDialog close, remove 800ms delay
- showJoinDialog: don't call loadChannels after dialog close — channel already in model via CHANNEL_UPDATED event, online badge via CHANNEL_PEERS_ONLINE. Duplicate loadChannels was resetting the peer online count.
- onConnectResult: remove 800ms QTimer — dialog closes immediately. Channel data arrives independently through the event pipeline.
2026-07-19 10:50:25 +03:00
Evgeny 3a7b359f87 fix(chat_sync): online status for joiner on inviter side not sent to GUI/peers
- cs_handle_channel_join: call cs_post_channel_online immediately after adding joiner
- member_sync_start with _on_invite_sync_done callback: on MT_OK push online=1 via merkle_sync_push_update
- DEBUG per-peer online status in cs_post_channel_online
2026-07-19 09:30:51 +03:00
Evgeny e3286d409f chatgui: кнопка + для invite в каналах, автокопирование ссылки, автоподключение из буфера
- Замена контекстного меню 'Пригласить' на кнопку + (18x18) справа снизу каждого канала с hover-эффектом
- InviteDialog: авто-копирование ссылки в буфер (Clipboard + Selection) при открытии
- JoinDialog: параметр autoJoinLink — если в буфере валидная utun:// ссылка, диалог сразу стартует подключение
2026-07-19 09:05:55 +03:00
Evgeny 501b636d19 topo_group: disable in chatgui; fix NAT detection for matching addresses
- Add utun_instance_set_topo_group_enabled() flag (default=1, chatgui sets 0)
- Move nat_detection create/destroy from topo_group.c to utun_instance.c (unconditional)
- NAT detection: simplify third_node search (any connected node)
- NAT detection: allow NULL topo_groups in receive_cbk and handlers
- NAT detection: handle NAT_INFO without topo_group (update socket directly)
- route_ping: make TOPO_GROUP optional in send_req_addr/handle_req
- topo_node: when NAT verified and address matches interface, set entry type to NAT instead of INTERFACE + socket_id|1
- topo_node: detect nat_type change in changed computation for rebuild
- test_nat_detection: fix socket_id check (|1 for NAT entries)
- chatgui: call utun_instance_set_topo_group_enabled(0)
2026-07-19 08:33:33 +03:00
Evgeny 208a0c8ae8 fix(chat_sync): peer online status not updated in invite flow
- cs_on_conn_up: call cs_on_peer_status_changed(peer,1) before return
  in invite path (was skipped, leaving inviter at online=0 in DB)
- cs_handle_welcome: remove unconditional set_online(0) — online
  status is managed by conn_up/conn_down, not by WELCOME
- cs_handle_welcome: add cs_post_channel_online() after WELCOME
  to send PEERS_ONLINE to GUI when channel is fully loaded
- cs_post_channel_online: add DEBUG log for PEERS_ONLINE event
- db_sync peer_check: suppress spam log when no peers connected
2026-07-19 07:54:06 +03:00
Evgeny ca6a27aadb BGP: 2 addr per socket (remove TOPO_ADDR_REAL), config IP priority, private IPs in SQLite, NAT addr != INTERFACE 2026-07-19 07:00:04 +03:00
Evgeny 4df7195a58 debug: add ADDR_SYNC logs for BGP node_put DELETE and member_sync recv ac 2026-07-19 00:09:46 +03:00
Evgeny 586d46f1e6 fix: WELCOME wire format — flags+update_sig parsing, peer_needed gap, invalid join_sig skip 2026-07-18 23:53:04 +03:00
Evgeny 39a376e255 fix: BGP и чат больше не затирают адреса друг друга в node_addresses
- BGP DELETE: +AND socket_id != 0 — не трогает чат-адреса (invite/JOIN/WELCOME)
- Чат invite DELETE: +AND socket_id=0 — не трогает BGP-адреса
2026-07-18 23:23:14 +03:00
Evgeny 70930b784f chatgui: fix — локальные адреса не записывались (g_cc.initialized до sync_my_addresses) + таймаут коллбэк 12→20 байт 2026-07-18 22:18:01 +03:00
Evgeny 57f861f360 chatgui: диагностические логи ADDR_SYNC во всех точках записи/удаления адресов в БД
- chat_core_sync_my_addresses: DELETE + INSERT с подсчётом строк, CHECK verify
- chat_core_connect_from_invite: DELETE + INSERT с IP:port
- member_sync_put: DELETE + INSERT с IP:port, warn если addrs_data=NULL
- cs_handle_channel_info_resp: адрес инвайтера из ETCP link
- cs_handle_channel_join: адреса джойнера
- cs_handle_peer_upsert: адреса пира
- cs_handle_welcome: адреса из WELCOME

Все логи с префиксом [ADDR_SYNC] в DEBUG_CATEGORY_DEBUG
2026-07-18 21:46:46 +03:00
Evgeny 0b385dca50 chatgui: обновление статуса/адресов узлов через чат-протокол
- merkle_sync: synced-флаг в сессии, MSG_ITEM_UPDATE(0x04), push_update() — рассылка лёгких дельт (online-статус) всем synced-соседям
- member_sync: apply_update в ops, node_updated_cb для GUI-нотификации внешних обновлений
- chat_sync: cs_on_peer_status_changed() — единая функция: БД + GUI + push_update + throttled member_sync_start (1/сек)
- cs_on_conn_down: исправлено — теперь сбрасывает nodes.online=0
- flush при destroy
2026-07-18 21:28:59 +03:00
Evgeny 20f5e6c953 sqlite: add cache_size/mmap_size/temp_store PRAGMAs to db_sync and topo_group — 159x insert speedup, fix test_chat_sync_stress timeout 2026-07-18 20:16:24 +03:00
Evgeny 0e0ad9316a fix race condition: DB_READY lost when utun thread starts before gui_bridge_init
- mainwindow.cpp: swap setupMessaging() before setupNode() so g_receiver is created first
- gui_bridge_impl.cpp: add DEBUG_WARN when gui_bridge_post drops event due to NULL g_receiver
2026-07-18 18:08:09 +03:00
Evgeny 29e2527b6b consolidate 3 SQLite connections into 1 shared handle
- utun_node.cpp: open topo_sqlite_db with FULLMUTEX + all PRAGMAs (WAL, FK, NORMAL sync, checkpoint)
- db_sync.c: reuse inst->topo_sqlite_db if available (shared_db flag)
- chat_core.c: reuse inst->topo_sqlite_db if available (shared_db flag)
- db_sync_destroy/chat_core_destroy: skip close on shared handle
- Only topo_groups_destroy closes the shared handle
- Fallback: each module opens own connection if topo_sqlite_db is NULL
2026-07-18 17:33:29 +03:00
Evgeny 853297290f chatgui: fix NodesPage truncated Node ID + add DB diagnostics
- NodesPage: show full 64-bit Node ID (hex16) instead of truncated 4 hex chars
- NodesPage: show diagnostic when DB handle is NULL (was silent return)
- DatabaseSettingsPage: show 'Database not connected' when DB handle is NULL
- DatabaseSettingsPage: add refreshStatus() called on tab select
- SettingsDialog: refresh Database tab on category change
2026-07-18 17:04:50 +03:00
Evgeny 93665c50f0 etcp: remove dead set_*_cbk functions, use add/remove only 2026-07-18 16:52:43 +03:00
Evgeny ef1922327a rename ready_cbks → init_cbks (connection init, not fully ready)
ready_cbks/etcp_conn_set_ready_cbk/add_ready/remove_ready → init_cbks/..._init_cbk
ca_ready_cb → ca_init_cb
cm_direct_ready_cb → cm_direct_init_cb
cm_reverse_ready_cb → cm_reverse_init_cb
ntp_node_on_conn_ready → ntp_node_on_conn_init
connect_ready_cb → connect_init_cb

init accurately describes when conn->initialized=1, before keepalives establish UP.
Also fire etcp_fire_conn_status INIT at this point instead of create time.
2026-07-18 16:38:24 +03:00
Evgeny ef3d7c3f37 chat_core: call ensure_channel_ready on invite — create msg/peers tables + register in db_sync
Without this, invite creates the channel in SQLite but db_sync never
knows about it, so peer sync fails with 'instance NOT FOUND'.
2026-07-18 16:14:53 +03:00
Evgeny 4188afb3c5 db_sync: lazy-register channel instance on INIT_SYNC when not pre-registered
When INIT_SYNC arrives for an unknown hash, scan all msg_* tables in
sqlite_master, compute SHA256 of channel_id, match the hash, and
auto-register via db_sync_instance_add. Fixes invite flow where
channel was created but db_sync wasn't notified.
2026-07-18 16:08:47 +03:00
Evgeny a510cb0018 auto_connect: add DB dump diagnostics (node_addresses state, node existence, db path+status)
- chat_core.c: dump node_addresses total, per-node counts, nodes lookup before addr query
- topo_group.c: log db path, rc, and db pointer after sqlite3_open
2026-07-18 15:47:05 +03:00
Evgeny 3aadaa3396 fix: sqlite3_open wrong path in topo_group.c (db_path vs db_path/chats.db), keep separate connections for perf
- topo_group.c: open {db_path}/chats.db instead of {db_path} — was opening a directory
- chat_core.c: remove inst->topo_sqlite_db = g_cc.db — keep topo_sqlite_db as separate
  uTun-only connection without FULLMUTEX, avoiding contention with GUI reads
2026-07-18 15:41:02 +03:00
Evgeny 9245a30fa5 auto_connect: diagnostic logging for early FAIL paths in chat_core_connect_auto
- chat_core.c: add DEBUG_INFO before each synchronous cb(FAIL) — pinpoints exact failure reason
- chat_sync.c: add log in ac_fill when ca_state=NULL after chat_core_connect_auto call
2026-07-18 15:06:23 +03:00
Evgeny aa1ed006d5 etcp: instance-level conn status callbacks (NEW/UP/DOWN/DELETE), fix member online in chatgui
- Add etcp_add_conn_status_cbk/remove/set — unified callback for all connections
- 4 statuses: NEW, UP, DOWN, DELETE — one subscription covers all connections
- Fire points in etcp.c: create→NEW, on_up→UP, on_down→DOWN, close→DELETE
- chat_sync.c: replace cs_on_new_conn+per-conn subs with cs_on_conn_status
- db_sync.c: same migration to instance-level callback
- cs_is_peer_online: use conn->links_up instead of link->link_status (was 0 during INIT handshake)
2026-07-18 14:51:01 +03:00
Evgeny ef27633a88 chatgui: clear clipboard before setText for reliable copy on Linux 2026-07-18 13:53:01 +03:00
Evgeny e71cae16c1 db_sync: unified msg table — one DB, one table per channel
- db_sync: rename column author→node_id, open chats.db instead of sync file,
  db_sync_instance_add takes table_name directly
- chat_core: remove CREATE TABLE msg_ch_*, remove on_db_sync_insert (74 lines),
  remove fallback INSERT in submit_message, add minimal on_msg_inserted
  for GUI notification only
- db_manager: update getMessages for new schema (parse JSON from data column),
  fix ORDER BY to use author_signature instead of datahash,
  update syncCursorNext to parse JSON
- si_register simplified: db_count from same table, no more msg vs sync gap
2026-07-18 13:50:35 +03:00
Evgeny 7c2798ec0e debug: add diagnostic logging for ETCP recv/INIT/dispatch paths
- etcp_connections.c: raw_recv log, INIT conn lookup details, insert_link DUP details
- etcp_api.c: dispatch id/cb logs with DROPPED warning when no handler
- chat_sync.c: etcp_send rc log, fix ac_result_cb to always clear ca_state
2026-07-18 13:04:10 +03:00
Evgeny a65478edcc chatgui: fix duplicate connection on invite when node already connected
- chat_core_has_conn: search all connections (pending+ready) by peer_node_id
- chat_core_connect_from_invite: skip chat_core_connect_auto if already connected
- ca_timeout_cb: close timed-out connection to free socket link slot
  + cancel remaining timers + ca_cleanup on all-failed
2026-07-18 11:24:51 +03:00
Evgeny 93871c592b db_sync: timeout for stuck sync_state=1, handle ERROR properly
- Add sync_start_tb to SI_PEER, set in db_sync_initiate_sync
- peer_check_cb: after 15s timeout reset sync_state=0 with WARN
- db_handle_error: accept si, reset sync_state=0, DEBUG_ERROR with details
- DB_SYNC_SYNC_TIMEOUT=15 added to db_sync.h
2026-07-18 10:52:54 +03:00
Evgeny de4099a26b logging: cleanup connection establishment logs
- Fix wrong categories: BGP/DEBUG -> ETCP for connection lifecycle events
- Fix level: WARN -> DEBUG for normal out-of-order pkts before init
- Fix level: INFO -> DEBUG for per-packet TX DATA spam
- Remove duplicate socket init logs (GENERAL duplicates of ETCP)
- Add missing INFO: INIT_RESPONSE received (client), INIT_RESPONSE sent (server)
- Unify all connection establishment messages under ETCP category
- Remove redundant DEBUG address prints in INIT send (info already in INFO msg)
- PING/PONG operations: BGP -> CONNECTION
- DIRECT IP detection: BGP -> NAT
2026-07-18 10:35:31 +03:00
Evgeny 3cd494bead chatgui: auto-clean build dir on generator change 2026-07-18 03:31:55 +03:00
Evgeny 28c788658a chatgui: Ninja + parallel build for Windows speedup 2026-07-18 03:30:40 +03:00
Evgeny 8f695cc828 AGENTS.md: add chatgui config and log file paths 2026-07-18 03:22:29 +03:00
Evgeny 3bf5a7b01d Revert hardcoded default for db_sync in chatgui — enabled via config file instead 2026-07-18 03:21:37 +03:00
Evgeny 2a826b62bc chatgui: enable db_sync=info debug category by default 2026-07-18 03:20:03 +03:00
Evgeny 4b7c7738de debug: add DEBUG_CATEGORY_DB_SYNC (26) + TRACE logs for db_sync, merkle_sync, chat_sync, member_sync 2026-07-18 03:19:46 +03:00
Evgeny 9e34e9f838 fix chatgui: self in member list, online status on reconnect, lb spam
- cs_handle_welcome(): add self to local peers_<ch_id> so
  joiner sees own account in channel member list
- cs_on_conn_up(): post CHANNEL_PEERS_ONLINE after reconnect
  so GUI shows connected status (was only posted on conn_down)
- etcp_loadbalancer: DEBUG_WARN -> DEBUG_DEBUG for no suitable
  link: tmr:wait — normal shaper behavior, not a warning
2026-07-18 02:55:10 +03:00
Evgeny 3e0b9483b7 fix chatgui: channel persistence & peer list after restart
- chat_core_sync_my_addresses(): remove private IP filter (192.168, 10.x, etc.)
  so LAN addresses are stored for direct connections
- topo_node_sqlite_channel_peers_all(): include peers without addresses
  in WELCOME message (was skipped entirely, causing empty peer list)
- chat_core_create_channel(): pass real local addresses to member_sync_put()
  instead of NULL,0
- chat_core_init(): log number of channels loaded from DB on startup
2026-07-18 02:46:53 +03:00