- etcp.c:466: %d→%s for log_name (was printing garbage like -2012603448)
- etcp_connections.c:2235: Server type %d→%s with server_type_str()
- etcp_connections.c:845,1578,1587: type=%d/nat_type=%d→%s with helpers
conn_mgr_router_recv_handler (etcp_router_bind): DIRECT_REQ, INTERM_EXCHANGE, DISCONNECT
conn_mgr_direct_recv_handler (etcp_bind): INVITE_INFO_REQ, INVITE_INFO_RESP
Each transport path now has its own handler — no more mixed concerns.
svc_id=17 (ETCP_RT_ID_CONN_MGR) is a singleton resource — bind once
at utun_instance_init, unbind once at utun_instance_destroy.
Previously each conn_mgr (one per group) called bind/unbind separately,
causing 'overwriting' and 'not bound' WARNs on every group init/shutdown.
Handler dispatches by group_id from message — no need for per-group binding.
1. etcp_on_down: add down_link param — log the specific lost link + remaining
Connection DOWN — link 192.168.40.247:2122 lost, remaining: [::1]:6669, [::2]:9970
Connection DOWN — closing, links: ... (for reinit/close)
2. etcp_on_link_down: pass the triggering link through to etcp_on_down
3. etcp_update_log_name: always check registry for node_name
(n_5a1b... → SM-A525F when name is available in registry)
Add helper functions server_type_str() and nat_type_str() to convert
CFG_SERVER_TYPE_* and NAT_TYPE_* codes to readable names.
Now: Add Socket type=PUBLIC instead of type=1
self-detect check: type=PUBLIC nat=UNKNOWN instead of type=1 nat_type=0
etcp_update_log_name: if name is empty, look up peer_node_id in topo_node_registry
and use node_name (e.g. 'SM-A525F') instead of empty or generic name.
Result: [45C2->03D3 [SM-A525F]] instead of [45C2->03D3 []]
- etcp_on_up: list up-link addresses after connection summary
- etcp_on_down: show all link addresses that were lost
- Link UP (server/client): add addr=X
- Connection established: add addr=X
- Link closed: add addr=X before traffic stats
- Link down (keepalive timeout): add addr=X
Now: [conn] Link 1 UP (server, mtu=1600, addr=192.168.40.247:2122)
- member_sync apply_items: empty payload is normal sync completion, not error
- topo_node_sqlite node_load: no addresses is normal for stub/seed nodes
- conn_mgr_core: node skipped when not in routing (normal for nodes w/o addrs)
- topo_group send_nodeinfo: downgrade ERROR→WARN in DEBUG category
- db_sync INIT_RESP: protocol details belong in DEBUG, not INFO
cm_invite_fail and cm_handle_invite_info_resp: always close invite's NCD
handle before freeing the invite struct. Previously the NCD close was
skipped when nq->handle != NULL (success path never closed it at all),
leaving cm_invite_ncd_callback registered with a dangling pointer.
On subsequent NCD DOWN event the stale callback caused SIGSEGV.
utun_instance_create() allocated with u_calloc (zeroed) but never
set etcp_connect_timeout_tb. utun_instance_create_from_config() had it
at line 371, but utun_instance_create (used by chatgui) was missing.
Timer with tb=0 fires instantly → CLOSE sent before handshake completes.
Diagnostics confirmed: value_tb=0, tb=0, delta_tb=0 on Windows chatgui.
- block_availability: status column (0=processing, 1=completed)
- md_ba_complete_block(): DELETE old + check exists + INSERT new id
- BLOCK_PROCESSING subcmd (0x10) — INSERT with new id, no REPLACE/IGNORE
- BLOCK_RELAY_FULL subcmd (0x11) — redirect when source/relay at capacity
- relay_block_ctx: downstream forwarding from chunk file
- md_file_load: per-file source download limit (max_downloads_per_file)
- RELAY_FULL from source node when at capacity
- relay_full handler: retry existing peers, not just new ones
- sync.md: full documentation
5 new tests in test_media_delivery_download:
- conn_cb starts only first block (backpressure)
- conn_cb with multiple peers
- BLOCK_DONE triggers next block relay from same peer
- assembly after all blocks validated
- peer with more blocks than dl (OOB fix verification)
md_dl_conn_cb made non-static for test visibility
md_dl_send added NULL guard for test instances without routing
media_download.h: added conn_cb extern declaration
- md_dl_send_block_req now takes explicit block_id (not peer-local index
into dl->block_ids) — fixes OOB 'aaaaaaaa...' garbage block_id
- conn_cb sends only first unstarted block per peer (backpressure)
- BLOCK_DONE success triggers next block from same peer
- conn_mgr handles stored in peer->cm_handle, closed on assembly/cancel
chat_core_attachment_download: use sqlite3_column_text for null-term
on_msg_inserted: copy data to local null-term buf before strstr
Both caused b64_decode to misread body from garbage memory
* prefix prepended in on_media_registered before b64 data
on_msg_inserted, chat_core_attachment_download, get_messages_json
only attempt b64_decode when prefix starts with '*' marker
- _compute_bucket_hash: SELECT protocol, write proto byte
- _member_get_items: SELECT protocol, write proto byte
- _member_apply_items: consume proto byte in skip calculation
- topo_node_sqlite_channel_peers_all: SELECT protocol, write proto byte
All 5 writers and 5 readers now consistently include protocol byte.
- stcp_server_create: support AF_INET and AF_INET6 V6ONLY=1 (no dual-stack)
- Add listen_family to stcp_link_config
- init_sockets: return error (not partial) on any bind failure
- add chat_core_sync_my_addresses() call at chatgui startup
- collect_my_addrs: add proto byte (1=UDP, 2=TCP) to binary format
- chat_sync.c JOIN/WELCOME/PEER_UPSERT: read proto byte, write protocol column
- member_sync.c: read proto byte, dynamic protocol bind
- topo_node.c: debug logs for nodeinfo changed detection
- node_config.cpp: type=public for all servers
- Replace instance->stcp_server (single pointer) with stcp_servers linked list
- Add stcp_server_list_add/destroy_all/count API in stcp_link.h/c
- Fix port extraction for both AF_INET and AF_INET6 in init_sockets
- Filter out 0.0.0.0 and [::] addresses in chat_profile.c TCP address sync
- Add type=public to servers in node_config.cpp saveFull()
- conn_mgr_core.c: убрана запись node_name из cm_handle_invite_info_resp
- topo_node_sqlite.c: name в nodes не перезаписывается пустой строкой
- android_jni_bridge.c: bridge_get_node_name читает peers_<ch>.userinfo если nodes.name пуст
node_conn_direct:
- ncd_init_cb: skip UP when links_up==0, ncd_up_cb delivers when link comes up
- close/force_close: handle_count safety checks, callback clearing
- open/open_node case 2: create links on reused dead conn
- ncd_create_links: skip duplicate link on same conn (stale->etcp==conn)
- set_callback: optional callback change on live handle
conn_mgr:
- cm_ncd_callback: DOWN only delivers event (handle stays alive)
- cm_ncd_callback: TIMEOUT force_close BEFORE cm_deliver_event
- cm_deliver_event: read handle fields to locals before callback (reentrany-safe)
- INVITE_INFO_REQ/RESP: add duplicate cmd byte for direct-send protocol
- cm_handle_invite_info_resp: search invite by group_id in channel conn_mgr
Android:
- node_id computed by sc_derive_node_id_from_pubkey in C, not Kotlin
- utun_bridge_join_channel: recompute node_id, log mismatch
- invite_link_c: compute nodeId from pubkey via sc_derive_node_id_from_pubkey
- NativeLib.deriveNodeId, InviteLink.kt uses C function
Remote peers should not overwrite local node_addresses.
When member_sync_recv processes data about our own node_id,
we trust locally-synced addresses (from sync_my_addresses)
and ignore address data from the remote peer.
sync_my_addresses used interface_addr even when its family
differed from the socket's local_addr family. A v4 socket
bound to 0.0.0.0 could pick up a v6 interface_addr on
dual-stack Android, inserting a duplicate v6 entry.
Now interface_addr is only used when families match.
- CONN_MGR entries: replace dynamic array with ll_queue (hash=256, key_size=8)
cm_find_entry now O(1) via queue_find_data_by_index
cm_ensure_entry uses queue_entry_new + queue_data_put_with_index
cm_entry_cleanup removes from queue and frees entry
- TOPO_GROUP_NODE: replace handles** array with single CONN_MGR_HANDLE*
remove topo_node_handle_register/unregister/count — dead indirection
nq->handle = h / nq->handle = NULL in all call sites
- TOPO_GROUP_NODE: remove dead fields dirty, best_socket, tranzit_data/count
dirty replaced with local variable in nat_detection.c
tranzit_data removed from wire format (TOPOMSG_NODE), serialize, deserialize
update struct layout: one field per line with comments
- New files: transport_layer/socket_monitor.c/h — socket state monitoring with per-instance ctx
- etcp_api: expose get_latency/1s_pkt_count measuring, add etcp_hashrnd for tests
- utun_instance: store socket_monitor per instance, add is_socket_ok check
- topo_node: detect IPv4 addresses with port from listening sockets
- topo_group: use node_name for display in routes
- Makefile.am: add socket_monitor.c to build
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.
- CM_V6_ANY for :: socket (matches all v6 addr classes)
- sin6_scope_id from s->netif_index (not from local_addr where :: has scope=0)
- getnameinfo in stcp_link_connect to preserve scope_id in addr string
- scope_id in cm_invite_tcp_connect, ncd_create_links, connect_create_links_v6, cm_bg_ping_to_node
Android chatgui:
- New MemberListScreen with member list, detail card, edit dialog
- Link status dots (green/red/grey) per address in detail card (1s poll)
- Self-node name coloured green
- ChatScreen: people icon in TopAppBar
IPv6 autoconnect fixes (3 bugs in conn_mgr/topo):
- topo_node_sqlite_node_load: load v6 addresses from DB
- topo_node_registry_store: merge v6_addrs into existing node
- cm_sock_v6_classify: wildcard [::] treated as CM_V6_DIR
- cm_add_v6_link: htons(port) was missing
Memory fixes:
- strdup→u_strdup in bridge (7 instances)
- u_realloc cap update before success check (3 instances)
- char sql[256]→[512] for truncated SELECT
Chat member hash now includes addresses for change detection
Linux chatgui:
- Link status dots in AccountList detail panel (1s poll)
- Self-node name in green in member list