Commit Graph
23 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 822889c78a Support ECH 2026-03-13 16:58:55 +08:00
eric 67e9ed2f36 Add FFI for outbound tests 2026-02-23 19:18:04 +08:00
eric 1abd136284 Support VMessAEAD (enabled by default) 2026-02-14 16:18:12 +08:00
eric 016a7fa9bc Enable QUIC by default 2026-02-05 16:11: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 93000df6aa Support NetFilter inbound 2025-10-01 17:27:23 +08:00
eric cecb7772a6 Remove private config 2025-08-18 21:00:30 +08:00
lanthora 9ec9046abd support windows 2025-02-17 21:18:13 +08:00
eric 2dab68c940 Fix clippy lints 2024-10-08 21:12:02 +08:00
eric 42c9d74676 Use ring as default crypto backend 2024-05-06 19:45:50 +08:00
eric effac11504 Support aws-lc-rs crypto backend 2024-05-02 02:24:26 +08:00
eric b38aaca42b build: include QUIC outbound in FFI crate 2023-08-27 10:27:29 +08:00
eric 4e6117b376 Build Android and iOS/macOS libraries on CI 2023-03-31 06:56:22 +08:00
eric ec81206469 ffi: run with config string in alternative to file path 2022-05-01 09:57:59 +08:00
eric b66e2efa1d ffi: Rust 2021 2022-01-15 00:20:08 +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