

Kestrel: A Subtractive Network & Cryptographic Shield
Kestrel is Bilvalabs' primary systems engineering artifact — built to test whether deep HTTP/2 content filtering, per-application firewalling, encrypted DNS, and censorship-resistant zero-trust tunneling can coexist inside a tiny, auditable Rust core without kernel root, Electron bloat, or battery drain.
- DNS / SNI Lookup
- 161.3 ns ~6.20M ops/s · flat HashSet
- Screen-Off CPU
- 0.70% 993K rules · 0 Hz idle TUN
- Dalvik Heap PSS
- 9.2 MB −95.5% via Rust stream loader
- Relay Peak RAM
- 5.26 MB 64 streams · 1.1 MB musl binary
Why Kestrel: biological precision backed by Rust
A kestrel is a compact falcon built for speed, open-sky hunting, motionless wind-hovering, and ultraviolet vision. Every trait of the bird maps directly to an engineering invariant inside kestrel-core:
Escalates Direct → DoH → ShadowMux-WSS past ISP blocks without caging clean traffic.
Parks in Linux epoll at 0.70% CPU — motionless at rest while scanning every packet.
Sees inside TLS 1.3 HTTP/2 streams to strip ads and trackers invisible to plain DNS.
A 3.7 MB core and 1.1 MB relay outperforming bloated 200 MB security suites.
On unrooted Android, only one VpnService slot exists; on desktop, security suites routinely ship 150+ MB Electron shells. Kestrel solves both through one shared Rust engine attached to smoltcp on mobile and a fail-open loopback proxy (PROXY 127.0.0.1:47800; DIRECT) on Linux, Windows, and macOS.
Four crates, explicit platform boundaries
4-layer AdGuard/uBO/DNS filter (~993K rules), ECDSA P-256 dynamic CA (84.8 ns LRU hit), HTTP/2 & HTTP/1.1 MITM, single-pass lol_html rewriter, SmartRouter, and lock-free telemetry.
Userspace smoltcp TCP/UDP stack, 0 Hz epoll-parked idle TUN loop, AtomicWaker backpressure, 16 KB page alignment, and VpnService-level auto-bypass for Indian UPI & banking apps.
Single 6–10 MB Rust binary with native OS tray, hardened loopback proxy (:47800), fail-open PAC generator, crash-recovery proxy journal, OS/NSS CA trust, and MDM policy layer.
Single-threaded Tokio server for 256 MB VMs. BLAKE3 keyed upgrade auth, inner ChaCha20-Poly1305 E2EE across TLS-terminating edges, 64 KB stream credit windows, and fdaa::/16 SSRF guard.
ShadowMux-WSS v1: Zero-trust inner AEAD over untrusted edges
Clean traffic flows directly on Tier 0 with 0 ms detour. ISP DNS sinkholes promote automatically to Tier 1 encrypted HTTP/2 DoH/DoT. Only flows experiencing active SNI or TCP-RST censorship escalate to Tier 2: a personal 1.1 MB relay running on a 256 MB VM. Even though edge proxies terminate outer TLS 1.3, inner streams remain end-to-end encrypted:
# 1. Anti-probing HTTP Upgrade (±60s window, replay cache; unauthenticated probes -> static 200 OK) X-Kestrel-Auth: <unix_ts>.<nonce_16hex>.BLAKE3_KEYED(PSK, "kestrel-auth-v1|...")[0..16] # 2. Ephemeral 33-byte salt exchange & directional key derivation ikm = BLAKE3_KEYED(PSK, client_salt_32B || server_salt_32B) c2s_key = BLAKE3_KEYED(ikm, "kestrel-shadowmux-v1-c2s") s2c_key = BLAKE3_KEYED(ikm, "kestrel-shadowmux-v1-s2c")
0 for control plane (PING/PONG); odd IDs for client streams
0x01 SYN_TCP · 0x02 SYN_UDP · 0x03 SYN_ACK · 0x04 DATA · 0x06 WINDOW_UPDATE · 0x07 FIN · 0x08 RST
Reserved (0x00 in v1)
Payload length in bytes (0..=16,384 B)
Encrypted inside ChaCha20-Poly1305 AEAD [dir_tag(4B), counter_le(u64)]
| Byte Offset | Field | Width | Semantics |
|---|---|---|---|
| 0x00..0x03 | stream_id | 4 B (BE) | 0 for control plane (PING/PONG); odd IDs for client streams |
| 0x04 | cmd | 1 B | 0x01 SYN_TCP · 0x02 SYN_UDP · 0x03 SYN_ACK · 0x04 DATA · 0x06 WINDOW_UPDATE · 0x07 FIN · 0x08 RST |
| 0x05 | flags | 1 B | Reserved (0x00 in v1) |
| 0x06..0x07 | length | 2 B (BE) | Payload length in bytes (0..=16,384 B) |
| 0x08..N | payload | length B | Encrypted inside ChaCha20-Poly1305 AEAD [dir_tag(4B), counter_le(u64)] |
Measured benchmarks & power engineering
Environment: rustc 1.93.1 --release · Sony Xperia SOG09 (Android 14, arm64-v8a) · Fly.io 256 MB shared-cpu-1x
| Subsystem / Operation | Workload | Measured | Architectural Impact |
|---|---|---|---|
| Filter Rule Compilation | 115,134 mixed DNS + AdGuard/uBO rules | 103.32 ms | ~1.11M rules/sec (rustc 1.93.1 --release) |
| DNS / SNI Suffix Lookup | 100,000 domains (50% hit / 50% miss) | 161.3 ns / op | ~6.20M lookups/sec |
| Indexed HTTP/URL Rule Eval | 15,000 deep network rules | 3.74 µs / op | ~267K requests/sec |
| Streaming HTML Rewrite | 52 KB HTML (CSS + scriptlets + CSP nonce, plain / gzip) | 356.5 µs / 432.5 µs | Single-pass lol_html · 2 MB stream cap |
| Dynamic ECDSA P-256 Leaf Cert | Cold sign vs. 512-entry LRU hit | 0.12 ms / 84.8 ns | ~8.3K certs/s cold · ~11.8M hits/s cached |
| ShadowMux AEAD Throughput | ChaCha20-Poly1305 duplex (64 MB, 16 KB frames) | 168.5 MB/s | ~1.35 Gbps single-core |
| Relay Peak RAM (VmHWM) | 64 concurrent multiplexed streams, 4 MB echo | 5.26 MB | 97.9% of 256 MB Fly.io cap free · 5.04 MB post-stress |
| Android Dalvik Heap PSS | 993K active rules on Xperia SOG09 (Android 14) | 9.2 MB | Down 95.5% from 204.5 MB via streaming JNI loader |
| Settled Screen-Off Idle CPU | 993K rules loaded, active VPN, 10s sample | 0.70% of 1 core | 0 Hz idle TUN + 0 JNI calls while screen locked |
| Live adblock-tester.com | Zero-cache Chrome HTTP/2 session | 22 / 22 checks | 11/11 services blocked (H2 403 + NXDOMAIN w/ 30s SOA) |
Trade-offs & active desktop research
- Certificate Pinning & Opt-In CA: Deep HTTP/2 cosmetic filtering requires installing Kestrel's on-device ECDSA P-256 Root CA; pinned financial and Indian UPI applications are excluded automatically at the OS tunnel/proxy boundary so payments never fail. Layers 1–3 operate with zero CA installed.
- Bounded Streaming Ceilings: HTML rewriting is strictly capped at
2 MBper document and4,000global CSS selectors so large downloads and video streams pass through without buffering. - Desktop QUIC & TLS Fingerprint Parity: Active desktop work focuses on deterministic
Alt-Svchandling for HTTP/3 flows, TTL-cached auto-bypass on strict anti-bot origins, and sandboxed Linux NSS certificate store detection.