StatManager aggregates activity per host, so clients can see which hosts
are used, through which outbound, and which ones fail and need a rule.
The host is the requested domain, else a sniffed domain (TLS, HTTP, DNS),
else the destination IP. Recording happens only when HOST_STATS is true
(off by default), so servers skip the extra locks and allocations.
Per host (at most 2000 hosts; when full, the least recently seen tenth is
evicted in one pass):
- sessions, bytes of finished sessions, the outbound most recently chosen
- failed sessions (outbound connect/handshake failed, TCP and UDP), not
included in the session count, so hosts that only ever fail show up
- the most recent destination IPs and ports (up to 8 each)
Each session start (sequence number, time in ms, host, outbound) also goes
into a ring of the most recent 20000 events, so clients can correlate
hosts that are accessed together, e.g. the hosts behind one web page.
"handled ... dst=<ip>:<port>" log lines append " sniffed=<domain>" when
the route was picked for a sniffed domain, so UDP flows (e.g. QUIC) to an
IP can be matched to the host they are counted under.
- RuntimeManager::get_host_stats() / get_host_events_since(seq)
- leaf_get_host_stats(rt_id, ctx, cb): sessions, failed, bytes, outbound,
ips and ports as comma-separated strings
- leaf_reset_host_stats(rt_id)
- leaf_get_host_events(rt_id, since_seq, latest_seq, ctx, cb)
- tests: per-host counts, live + finished bytes, reset; event sequencing,
bound, incremental reads; IPs under the sniffed domain; ports; failed
sessions
StatManager now keeps cumulative (sent, recvd) bytes per outbound tag.
A finished session is added once, when its session end is logged; live
sessions are added at query time, so the totals stay exact without
touching the per-byte read/write path.
- RuntimeManager::get_outbound_traffic() returns (tag, sent, recvd)
- leaf_get_outbound_traffic(rt_id, ctx, cb) reports them over FFI,
taking the stat lock synchronously rather than building a tokio
runtime per call
- test: closed + live accounting, and a repeated session end
* Added "api" config to JSON format
* Added "api-interface" and "api-port" options to Conf format
* Added "--auto-reload" flag to the command line program
* Added "--test" flag to the command line program
* Added FFIs leaf_run(), leaf_reload(), leaf_shutdown(), leaf_test_config()
* Removed FFI run_leaf()
* Added Web APIs:
* POST /api/v1/runtime/reload
* POST /api/v1/runtime/shutdown