12 Commits
Author SHA1 Message Date
eric 3e126eb063 feat(stats): per-host stats and session events behind HOST_STATS
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
2026-12-03 19:27:21 +08:00
eric 263cff16b7 feat(stats): track traffic per outbound and expose it over FFI
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
2026-12-03 19:27:20 +08:00
eric 67e9ed2f36 Add FFI for outbound tests 2026-02-23 19:18:04 +08:00
eric 9dafaf5278 clippy fix 2026-01-01 16:38:58 +08:00
eric 1a66eb47a8 Added health check functions for client 2025-10-28 19:39:14 +08:00
eric 2dab68c940 Fix clippy lints 2024-10-08 21:12:02 +08:00
eric ec81206469 ffi: run with config string in alternative to file path 2022-05-01 09:57:59 +08:00
eric 7a892236e7 Exposes more runtime management APIs
* 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
2021-04-12 23:05:35 +08:00
eric a2dadff60d outbound/select: new outbound 2021-04-07 18:49:48 +08:00
eric 021391608c refactor 2021-04-05 22:35:35 +08:00
eric 0132b5ced1 ffi: fix build error 2021-04-05 18:53:44 +08:00
eric ea3454f0b2 ffi: allows building as static library for all targets 2021-04-05 18:21:19 +08:00