feat: Add bandwidth & speed scheduler with timetable and metered connection support
- Dominant language
- Rust
- Stars
- 528
- Forks
- 38
- Avg merge
- 5h 26m
- Merged PRs (30d)
- 131
Description
### Preflight checklist
* [x] I searched [existing issues](https://github.com/ja7ad/hydra/issues?q=is%3Aissue) and this has not been proposed already.
* [x] I checked the [README](https://github.com/ja7ad/hydra/blob/main/README.md) and this is not already supported.
### Component
Core Engine / Desktop GUI / Configuration
### Problem
1. **Network Congestion During Active Hours:** Hydra's multi-connection engine aggressively consumes available bandwidth, which saturates shared home/office networks during working hours or peak gaming/streaming times.
2. **Manual Intervention Overhead:** Users currently have to manually pause downloads or manually tweak global speed limits when starting/stopping work.
3. **Metered Connection Hazards:** When switching to mobile hotspots or metered connections, unconstrained background downloads can rapidly deplete limited data quotas.
### Proposed solution
Implement a dynamic **Bandwidth & Speed Scheduler** that programmatically adjusts download rates, connection limits, and active queues based on time windows and network status.
#### Key Capabilities
1. **Configurable Time-Window Rules (Config / CLI):**
* Support a timetable configuration in `config.toml` (or daemon configuration) specifying time blocks, days of the week, and respective rate limits:
* *Normal Speed Limit:* Default speed ceiling during general usage.
* *Alternative / Off-Peak Speed Limit:* Unrestricted or high speeds during off-peak hours (e.g., 12:00 AM – 07:00 AM).
* *Work/Strict Limit:* Restrictive cap during business hours (e.g., Mon–Fri, 09:00 AM – 06:00 PM: 2 MB/s).
2. **GUI Weekly Timetable Grid:**
* Provide an interactive 7x24 weekly matrix view in **Options > Speed / Scheduler** (similar to qBittorrent/Transmission) where users can paint hourly slots with:
* `Full Speed`
* `Alternative Speed Limit`
* `Paused / Queue Only`
3. **Live Rate Limiter Adaptation (Zero Disconnection):**
* The underlying token-bucket rate limiter in the core engine should dynamically update its refill capacity upon schedule transitions without terminating active multi-part TCP streams or resetting chunk buffers.
4. **Metered Network Detection & Guard:**
* Detect OS metered connection states (via `NetworkInformation` on Windows, NetworkManager `metered` property on Linux, or SCNetworkReachability flags on macOS) to auto-pause or throttle downloads unless explicitly bypassed.
### Alternatives considered
* **Static Global Speed Limit:** Requires manual switching twice a day.
* **External OS-Level Traffic Control (`tc`, NetLimiter, pf):** Hard to configure, platform-dependent, and outside Hydra's direct control.
### Platforms this should cover
* [x] Linux
* [x] macOS
* [x] Windows
* [ ] Android / iOS (via `libhydra`)
### Additional context
#### Proposed Configuration Schema (`config.toml`)
```toml
[speed_limit]
global_download_rate = "0" # 0 = unlimited
[scheduler]
enabled = true
alt_download_rate = "2MB/s"
alt_upload_rate = "500KB/s"
# Active alternative speed windows
[[scheduler.rules]]
days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
start_time = "09:00"
end_time = "18:00"
action = "alt_limit" # "alt_limit" | "pause" | "unlimited"
[[scheduler.rules]]
days = ["Everyday"]
start_time = "00:00"
end_time = "07:00"
action = "unlimited"
```
### Compatibility
* [ ] This changes existing behavior (flags, defaults, output format, or the C ABI).
### Contribution
* [x] I'm willing to open a pull request implementing this.
Contributor guide
Research direction
Start by mapping the core engine's token-bucket rate limiter, the config.toml schema, and the Options > Speed / Scheduler GUI entry point. Check how platform network status is exposed on Linux, macOS, and Windows. Done means scheduled limits, timetable controls, and metered-connection behavior work without disconnecting active downloads.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, cli, desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100