Skip to content

Commit 5315dc3

Browse files
committed
Update CLAUDE.md with comprehensive v4.1.0 project state
1 parent 745a3df commit 5315dc3

1 file changed

Lines changed: 38 additions & 33 deletions

File tree

CLAUDE.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,46 @@ Modern, AMOLED-dark hosts-based ad blocker app for Android. Inspired by AdAway.
99
- Room + DataStore for persistence
1010
- Coroutines + Flow for async, ViewModels + StateFlow for UI state
1111
- OkHttp for source downloads + DoH resolver, libsu for root access
12-
- Gradle version catalog (`libs.versions.toml`) for dependency management
1312

1413
## Key Architecture
1514
- **BlocklistHolder** - Trie-based O(m) domain lookup, 200K+ domains, volatile root for thread safety. Regex rules capped at 500 chars with nested quantifier rejection (ReDoS prevention).
16-
- **DnsVpnService** - Local VPN DNS interception, TUN interface, dual-stack (IPv4+IPv6), DNS trap, DoH/DoT blocking, TCP DNS RST for both IPv4 and IPv6. Bounded log buffer (LinkedBlockingQueue 5000) with overflow detection. Context-aware firewall checks (screen off/background/metered). VPN stability tracking (uptime, rebuilds, fd errors, dropped queries).
15+
- **DnsVpnService** - Local VPN DNS interception, TUN interface, dual-stack (IPv4+IPv6), DNS trap, DoH/DoT blocking, TCP DNS RST for both IPv4 and IPv6. Bounded log buffer (LinkedBlockingQueue 5000) with overflow detection. Context-aware firewall checks (screen off/background/metered). VPN stability tracking (uptime, rebuilds, fd errors, dropped queries). Publishes cache stats + dropped count via companion object for UI.
1716
- **DohResolver** - RFC 8484 POST+GET, certificate pinning, smart latency-based failover (EMA per provider, auto-selects fastest), unpinned fallback as last resort.
18-
- **RootDnsLogger** - Root-mode DNS proxy on 127.0.0.1:5454, iptables NAT redirect, UID attribution
19-
- **IptablesManager** - AFWall+-style per-app firewall, 20+ interface patterns, BLACKLIST/WHITELIST modes
17+
- **RootDnsLogger** - Root-mode DNS proxy on 127.0.0.1:5454, iptables NAT redirect, UID attribution.
18+
- **IptablesManager** - AFWall+-style per-app firewall, 20+ interface patterns, BLACKLIST/WHITELIST modes.
2019
- **HostsUpdateWorker** - Periodic blocklist refresh + DoH bypass list update + allowlist subtraction. Uses shared singleton OkHttpClient (injected via Hilt).
21-
- **TrackerSignatureDb** - Exodus-style APK dex scanning for ~60 tracker SDK signatures. Results cached in Room DB (tracker_scan_cache table), invalidated on app version change. 7-day cache TTL.
22-
- **GeoIpLookup** - ip-api.com with in-memory cache, rate limiting (40 req/min window), exponential backoff on 429 responses.
23-
- **ContextState** - Screen on/off receiver + metered network detection + foreground app tracking. Drives context-aware firewall rules in DnsVpnService.
24-
- **PrivateDnsDetector** - Detects Strict/Automatic Private DNS that bypasses VPN filtering. Integrated into onboarding flow + Home screen re-check on resume.
25-
- **AutomationReceiver** - Broadcast intent API with rate limiting (5s per action per caller) and full audit logging to Room DB (automation_audit_log table).
20+
- **TrackerSignatureDb** - Exodus-style APK dex scanning for ~60 tracker SDK signatures. Results cached in Room DB (tracker_scan_cache table), invalidated on app version change. 7-day cache TTL. Progress callback for UI.
21+
- **GeoIpLookup** - ip-api.com with in-memory cache, rate limiting (40 req/min window), exponential backoff on 429.
22+
- **ContextState** - Screen on/off receiver + metered network detection + foreground app tracking. Drives context-aware firewall rules.
23+
- **PrivateDnsDetector** - Detects Strict/Automatic Private DNS that bypasses VPN filtering. Shows in onboarding + persistent Home re-check on resume.
24+
- **AutomationReceiver** - Broadcast intent API with rate limiting (5s per action per caller), full audit logging to Room DB. Audit log viewable in Settings > Tools.
25+
- **ImportExportUtil** - Supports HostShield JSON, AdAway, Blokada, NextDNS, Pi-hole, plain hosts. Firewall rule JSON export/import added in v4.1.0.
2626

2727
## Source Categories
2828
- ADS, TRACKERS, MALWARE, ADULT, SOCIAL, CRYPTO, **ALLOWLIST**, CUSTOM
29-
- ALLOWLIST sources are subtracted from blocklist during updates (not added to block trie)
29+
- ALLOWLIST sources subtracted from blocklist during updates (not added to block trie)
3030

3131
## Key Files
32-
- `app/app/src/main/java/com/hostshield/service/DnsVpnService.kt` - VPN packet loop (~1800 lines)
32+
- `app/app/src/main/java/com/hostshield/service/DnsVpnService.kt` - VPN packet loop (~1850 lines)
3333
- `app/app/src/main/java/com/hostshield/domain/BlocklistHolder.kt` - Trie + regex + wildcard engine
3434
- `app/app/src/main/java/com/hostshield/service/DohResolver.kt` - DoH with smart latency failover
3535
- `app/app/src/main/java/com/hostshield/service/DnsCache.kt` - LRU DNS cache with TTL
3636
- `app/app/src/main/java/com/hostshield/service/DnsPacketBuilder.kt` - DNS wire format builder/parser
37-
- `app/app/src/main/java/com/hostshield/util/TrackerSignatureDb.kt` - APK tracker SDK scanner (cached)
37+
- `app/app/src/main/java/com/hostshield/util/TrackerSignatureDb.kt` - APK tracker SDK scanner (Room-cached)
3838
- `app/app/src/main/java/com/hostshield/util/GeoIpLookup.kt` - GeoIP/ASN lookup (rate limited)
3939
- `app/app/src/main/java/com/hostshield/util/AppPrivacyScorer.kt` - Per-app A-F privacy grades
40+
- `app/app/src/main/java/com/hostshield/util/ImportExportUtil.kt` - Multi-format import/export + firewall rules
4041
- `app/app/src/main/java/com/hostshield/service/AutomationReceiver.kt` - Rate-limited automation API
4142
- `app/app/src/main/java/com/hostshield/service/ScreenStateReceiver.kt` - ContextState for firewall
42-
- `app/app/src/main/java/com/hostshield/ui/screens/sources/BlocklistGalleryScreen.kt` - Curated gallery
43-
- `app/app/src/main/java/com/hostshield/data/model/Entities.kt` - Room entities (including new v4.0 entities)
44-
- `app/app/src/main/java/com/hostshield/data/database/Migrations.kt` - DB migrations (v5-v9)
43+
- `app/app/src/main/java/com/hostshield/ui/screens/sources/BlocklistGalleryScreen.kt` - Curated gallery (70+)
44+
- `app/app/src/main/java/com/hostshield/ui/screens/settings/AutomationAuditScreen.kt` - Audit log viewer
45+
- `app/app/src/main/java/com/hostshield/data/model/Entities.kt` - Room entities (10 tables)
46+
- `app/app/src/main/java/com/hostshield/data/database/Migrations.kt` - DB migrations (v1-v9)
4547
- `app/app/src/main/java/com/hostshield/di/DatabaseModule.kt` - Hilt DI (DB + singleton OkHttpClient)
4648
- `app/app/src/main/assets/curated_blocklists.json` - 70+ categorized blocklist definitions
4749

48-
## Screens (22+)
49-
Home, Sources, Rules, Stats, Settings, Logs, Apps, AppPrivacy, Firewall (DNS/Network/Context tabs), ConnectionLog, DnsTools, NetworkStats, OverlapAnalysis, DnsLeakTest, RuleTest, HostsEditor, HostsDiff, AppExclusions, Onboarding (with Private DNS warning), BlocklistGallery
50+
## Screens (23+)
51+
Home, Sources, Rules, Stats, Settings, Logs, Apps, AppPrivacy, Firewall (DNS/Network/Context tabs), ConnectionLog, DnsTools, NetworkStats, OverlapAnalysis, DnsLeakTest, RuleTest, HostsEditor, HostsDiff, AppExclusions, Onboarding (with Private DNS warning), BlocklistGallery, AutomationAudit
5052

5153
## Build
5254
```bash
@@ -68,36 +70,39 @@ cd app
6870
- Secrets configured: `KEYSTORE_BASE64`, `KEY_ALIAS`, `KEY_PASSWORD`, `STORE_PASSWORD`
6971

7072
## Version History
71-
- v4.1.0: Custom upstream DNS UI in Settings, firewall rule export/import (JSON), automation audit log viewer screen, query rate anomaly detection (3x baseline warning on Home), dropped queries banner on Home, cache hit rate on Home, Peach TrendingUp icon for anomaly
73+
- v4.1.0: Custom upstream DNS UI in Settings, firewall rule export/import (JSON), automation audit log viewer screen, query rate anomaly detection (3x baseline warning on Home), dropped queries banner, cache hit rate on Home
7274
- v4.0.0: Automation API rate limiting + audit logging, GeoIP rate limit backoff, shared OkHttpClient pooling, tracker scanner Room caching, VPN stability metrics (uptime/rebuilds/errors/drops), DNS cache stats in Stats screen, VPN Health card, log buffer overflow detection, DB v9
73-
- v3.9.0: Private DNS conflict warning in onboarding, smart DNS latency-based failover, GeoIP/ASN/country in DNS log details, automation broadcast security fix, IPv6 TCP DNS support (RST blocking)
74-
- v3.8.0: Curated blocklist gallery (70+ lists), Exodus tracker SDK detection in App Privacy Report, context-aware firewall (screen off/background/metered), regex DoS protection, bounded log buffer, LRU cache fix, DNS answer cache cleanup
75-
- v3.7.0: App privacy report, rule sync URLs, blocked domain trends, per-app scoring, category toggles on Home
76-
- v3.6.0: Live query rate, category toggles, hosts editor, Pi-hole import, deep links, notification actions
77-
- v3.5.0: Rule tester, temporary allow, domain age check, stats widget, privacy score card, search history
78-
- v3.4.0: Privacy score, scheduled blocking, query type filter, suspicious TLD detection, batch source health check
79-
- v3.3.0: DNS leak test, clipboard import, accent color picker, auto backup, IP blocking, domain pinning
80-
- v3.2.0: App shortcuts, enhanced widget, bulk log actions, DNS latency chart, network-aware profiles, regex rules, domain reputation lookup, source changelog tracking
81-
- v3.1.0: DoH bypass scheduling, multi-upstream DNS, auto update check, allowlist sources, overlap analysis, CSV stats export
82-
- v3.0.0: DNS cache, CNAME cloaking, 7-day trend charts, diagnostic export, CI/CD
75+
- v3.9.0: Private DNS conflict warning in onboarding, smart DNS latency-based failover, GeoIP/ASN/country in DNS log details, automation broadcast security fix, IPv6 TCP DNS support
76+
- v3.8.0: Curated blocklist gallery (70+ lists), Exodus tracker SDK detection, context-aware firewall, regex DoS protection, bounded log buffer, LRU cache fix
77+
- v3.7.0: App privacy report, rule sync URLs, blocked domain trends, per-app scoring, category toggles
78+
- v3.6.0: Live query rate, hosts editor, Pi-hole import, deep links, notification actions
79+
- v3.5.0: Rule tester, temporary allow, domain age check, stats widget, search history
80+
- v3.4.0: Privacy score, scheduled blocking, query type filter, suspicious TLD, batch health
81+
- v3.3.0: DNS leak test, clipboard import, accent colors, auto backup, IP blocking, pinning
82+
- v3.2.0: App shortcuts, widget, bulk log, latency chart, network profiles, regex, reputation
83+
- v3.1.0: DoH scheduling, multi-DNS, auto update, allowlists, overlap analysis, CSV export
84+
- v3.0.0: DNS cache, CNAME cloaking, trend charts, diagnostic export, CI/CD
8385
- v2.1.0: Automation API, iptables firewall, connection logging
8486
- v2.0.0: DoH, DNS trap, batch domain test, network stats
8587

8688
## Gotchas
87-
- Room stores enums as strings — adding new enum values (like ALLOWLIST) doesn't need migration
89+
- Room stores enums as strings — adding new enum values doesn't need migration
8890
- HostsUpdateWorker has DohBypassUpdater injected — runs on every periodic cycle regardless of blocking state
8991
- OverlapAnalysisScreen downloads sources with `forceDownload=true` to bypass ETag caching
9092
- Regex rules limited to 500 chars with nested quantifier rejection (ReDoS prevention)
91-
- Log buffer is LinkedBlockingQueue(5000) — uses `offer()` instead of `add()` to detect overflow, tracks dropped count
93+
- Log buffer is LinkedBlockingQueue(5000) — uses `offer()` instead of `add()`, tracks dropped count
9294
- DB version is 9 (v8->v9 adds tracker_scan_cache, automation_audit_log, vpn_stability tables)
93-
- TrackerSignatureDb reads raw dex bytes from APK — scans are cached in Room, invalidated on app version change
95+
- TrackerSignatureDb reads raw dex bytes from APK — scans cached in Room, invalidated on app version change
9496
- ContextState.register() must be called in startVpn(), unregister() in stopVpn()
9597
- Context-aware firewall requires Usage Stats permission for foreground app detection
96-
- GeoIpLookup uses ip-api.com (free tier, 45 req/min) — has rate limiting + exponential backoff on 429
97-
- DohResolver smart DNS prefers fastest measured provider but falls back through all on failure
98+
- GeoIpLookup uses ip-api.com (free tier, 45 req/min) — rate limiting + exponential backoff on 429
99+
- DohResolver smart DNS prefers fastest measured provider, falls back through all on failure
98100
- Automation API has per-action rate limiting (5s cooldown) and audit log with 30-day retention
99101
- IPv6 TCP RST uses separate checksum function (computeTcpChecksumV6) with IPv6 pseudo-header
100102
- Private DNS warning shows in onboarding AND re-checks on Home screen resume
101103
- `gradlew` lives in `app/` not repo root — CI workflow uses `working-directory: app`
102104
- Release keystore is gitignored (*.keystore in .gitignore)
103105
- Shared OkHttpClient is provided as Hilt singleton in DatabaseModule — inject instead of creating new instances
106+
- Firewall export UIDs are device-specific — importer must resolve UIDs from package names
107+
- Query anomaly baseline needs 10 samples (~50s) before detection activates
108+
- DnsVpnService.currentCacheStats and currentDroppedQueries are companion @Volatile fields polled by UI

0 commit comments

Comments
 (0)