Skip to content

feat(mirror): traffic_kinds dispatch for raw-file-only mirrors#600

Merged
rainxchzed merged 3 commits into
mainfrom
feat/mirror-traffic-kinds
May 14, 2026
Merged

feat(mirror): traffic_kinds dispatch for raw-file-only mirrors#600
rainxchzed merged 3 commits into
mainfrom
feat/mirror-traffic-kinds

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented May 14, 2026

Required for 1.8.3. Backend ships new traffic_kinds field; client must respect or jsDelivr-style mirrors 404 on release assets.

  • TrafficKind enum + MirrorConfig.trafficKinds (defaults to both for legacy responses)
  • MirrorRewriter.classify(url) + applyTemplate handles {url} and {owner}/{repo}@{ref}/{path} styles
  • ProxyManager.currentMirror(): MirrorActive? (template + kinds)
  • Interceptor + multi-source race + slow-download detector all gate on kind

Test plan

  • Android + JVM compile clean
  • Real-device: pick jsdelivr → APK download goes Direct, README routes via jsdelivr

Source: backend agent handoff.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced mirror capability tracking to distinguish which types of downloads each mirror supports.
  • Bug Fixes

    • Improved mirror selection logic to verify mirror compatibility before attempting rewrite, with automatic fallback to direct download when unsupported.
    • Optimized slow download detection to avoid redundant mirror suggestions when already using a compatible mirror.

Review Change Stack

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rainxchzed has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bbff0d92-68b7-429f-995a-1a86bfd31a39

📥 Commits

Reviewing files that changed from the base of the PR and between 8db46e9 and f96d49b.

📒 Files selected for processing (9)
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/download/MultiSourceDownloaderImpl.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/download/SlowDownloadDetectorImpl.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/MirrorListResponse.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/mirror/MirrorRepositoryImpl.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/MirrorRewriteInterceptor.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/MirrorRewriter.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/ProxyManager.kt
  • core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/MirrorConfig.kt
  • core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/TrafficKind.kt

Walkthrough

This PR refactors mirror routing from binary presence (mirror exists?) to capability-based decision-making (mirror supports this traffic kind?). A new TrafficKind enum distinguishes RELEASE_ASSET from RAW_FILE downloads. State management, HTTP interception, and download logic are updated to classify requests and check mirror capabilities before routing.

Changes

Traffic-Kind-Aware Mirror Routing

Layer / File(s) Summary
TrafficKind domain enum
core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/TrafficKind.kt
Introduces TrafficKind enum with RELEASE_ASSET and RAW_FILE values and a fromWire() companion parser for deserializing backend capabilities.
Mirror state and configuration wiring
core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/MirrorConfig.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/MirrorListResponse.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/mirror/MirrorRepositoryImpl.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/ProxyManager.kt
MirrorConfig adds trafficKinds field with defaults; DTO accepts trafficKinds from backend; repository maps wire values to domain; ProxyManager introduces MirrorActive data class to store template and trafficKinds together, with currentMirror() accessor and refactored collector logic.
Mirror classification and template rewriting
core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/MirrorRewriter.kt
classify(url) detects traffic kind via host/path patterns; shouldRewrite() simplified to host normalization and set membership; applyTemplate() now nullable and supports both {url} replacement and decomposed {owner}/{repo}@{ref}/{path} templates via new private decompose() and applyDecomposedTemplate() helpers.
HTTP interception with capability check
core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/MirrorRewriteInterceptor.kt
installMirrorRewrite intercepts requests: classifies the URL, retrieves active mirror, and rewrites only when the classified kind is in the mirror's trafficKinds; safely parses rewritten URLs with runCatching, strips Authorization header on host change.
Download and slow-detection decisions
core/data/src/commonMain/kotlin/zed/rainxch/core/data/download/MultiSourceDownloaderImpl.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/download/SlowDownloadDetectorImpl.kt
MultiSourceDownloaderImpl checks RELEASE_ASSET capability before using mirror, falls back to direct download if unsupported or template rewrite returns null; SlowDownloadDetectorImpl skips mirror suggestion prompt when active mirror already supports RELEASE_ASSET on the slow path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • OpenHub-Store/GitHub-Store#469: Introduces the initial E5 mirror system with template-based routing and slow-download mirror prompting; this PR extends that foundation with traffic-kind-aware routing.

Poem

🐰 The rabbit hops through mirrors bright,
Now knowing which routes fit just right—
Release assets, raw files clear,
Each traffic kind finds its home here!
No guessing, just capability—
Mirror routing with finality! 🪞✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding traffic_kinds dispatch to handle raw-file-only mirrors, which is the central feature of this multi-file PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mirror-traffic-kinds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rainxchzed rainxchzed merged commit 33b8041 into main May 14, 2026
1 check passed
@rainxchzed rainxchzed deleted the feat/mirror-traffic-kinds branch May 14, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant