The ultra-fast download utility β rewritten in Rust
Features β’ Quick Start β’ Usage β’ Architecture β’ Building β’ License
aria2-rust is a complete rewrite of the renowned aria2 download utility in Rust. It supports HTTP/HTTPS, FTP/SFTP, BitTorrent, and Metalink protocols, with JSON-RPC/XML-RPC/WebSocket remote control capabilities.
- Multi-Protocol Download: HTTP/HTTPS, FTP/SFTP, BitTorrent (DHT/PEX/MSE), Metalink V3/V4
- Multi-Source Mirrors: Automatic segmented parallel downloads from multiple URIs for maximum bandwidth utilization
- Resume Support: Breakpoint resume on all protocols with seamless recovery after network interruptions
- Full BitTorrent Support:
- β DHT network (KRPC + routing table + bootstrap)
- β Tracker communication (UDP/HTTP)
- β Peer Exchange (PEX)
- β MSE/PE encryption (BEP14 handshake)
- β Choking algorithms + seed-time/ratio support
- β RarestFirst piece selection
- β uTP protocol (BEP 29) - Not in original aria2 C++
- β Web Seeds (BEP 19)
- β LPD (Local Peer Discovery)
- β Complete seeding mode with upload support
- Rate Limiting: Token bucket algorithm with per-task/global limits
- Cookie Management: Netscape format persistence + auto-loading from files
- Session Management: Auto-save + manual save/load with .aria2 control files
- RPC Remote Control: JSON-RPC 2.0, XML-RPC, WebSocket (34 methods + 7 events, 94% coverage)
- Configuration System: ~95 core options with four-source merging (CLI/file/environment/defaults)
- NetRC Authentication: Automatic FTP/HTTP credential loading from
.netrcfiles - URI List Files: Batch import download tasks via
-iparameter - Public Tracker List: Auto-update from trackerslist.com for BT peer discovery
Linux / macOS:
curl -fsSL https://raw.githubusercontent.com/balovess/aria2_rust/main/install.sh | bashWindows (PowerShell):
irm https://raw.githubusercontent.com/balovess/aria2_rust/main/install.ps1 | iexDocker:
docker run -d --name aria2 -p 6800:6800 -v ~/downloads:/downloads ghcr.io/balovess/aria2-rust:latestPackage Managers:
| Platform | Command |
|---|---|
| Homebrew (macOS/Linux) | brew install ./homebrew/aria2-rust.rb |
| Scoop (Windows) | scoop install ./scoop/aria2-rust.json |
| Cargo (from source) | cargo install --path aria2 |
After installation, start downloading immediately:
# Download a file
aria2c http://example.com/file.zip
# Download with multiple connections
aria2c -x 16 -s 16 http://example.com/large.iso
# Download a torrent
aria2c file.torrent
# Download with custom directory
aria2c -d ~/downloads http://example.com/file.zipClick to expand build instructions
Prerequisites:
- Rust 1.70+ (stable)
- Windows / macOS / Linux
Build Commands:
# Clone the repository
git clone https://github.com/balovess/aria2_rust.git
cd aria2_rust
# Build all crates
cargo build --release
# Download a file (HTTP)
cargo run --release -- http://example.com/file.zip
# Download with custom options
cargo run --release -- -d ./downloads -s 4 http://example.com/large.iso
# Show help
cargo run --release -- --help
# Show version
cargo run --release -- --versionWe provide ready-to-use configuration templates in examples/configs/:
| Template | Description |
|---|---|
| minimal.conf | Minimal configuration for quick setup |
| basic.conf | Basic configuration with common options |
| advanced.conf | Advanced configuration with RPC, proxy, etc. |
| bittorrent.conf | Optimized for BitTorrent downloads |
Usage:
# Copy template to config directory
mkdir -p ~/.aria2
cp examples/configs/basic.conf ~/.aria2/aria2.conf
# Edit as needed
nano ~/.aria2/aria2.conf
# Run with configuration
aria2c --conf-path=~/.aria2/aria2.conf http://example.com/file.ziparia2c http://example.com/file.ziparia2c -o output.dat -d /downloads -s 4 -x 8 http://example.com/large.bin| Option | Description | Default |
|---|---|---|
-d, --dir |
Save directory | . |
-o, --out |
Output filename | auto |
-s, --split |
Connections per server | 1 |
-x, --max-connection-per-server |
Max connections per server | 1 |
--max-download-limit |
Max download speed | unlimited |
--timeout |
Timeout in seconds | 60 |
-q, --quiet |
Quiet mode | false |
aria2c file.torrentCreate a text file with URIs (one entry per block, Tab-separated mirrors):
dir=/downloads
split=5
http://mirror1.example.com/file.iso http://mirror2.example.com/file.iso
http://mirror3.example.com/file.iso
Then:
aria2c -i uris.txtTotal Codebase: ~35,000+ lines Rust/TS
Test Suite: 1432+ tests passing
The project is organized as a Cargo workspace with 4 crates:
aria2-rust/
βββ aria2/ # Binary crate (CLI entry point, ~550 lines)
β βββ src/main.rs # Entry point
β βββ src/app.rs # App runtime (ConfigManager + Engine)
β βββ examples/ # Usage examples
βββ aria2-core/ # Core library (~7,000 lines)
β βββ src/engine/ # Download engine (12 command implementations)
β β βββ download_engine.rs # Event loop with command queue
β β βββ download_command.rs # HTTP/HTTPS downloader
β β βββ ftp_download_command.rs # FTP/SFTP downloader
β β βββ bt_download_command.rs # BitTorrent downloader
β β βββ magnet_download_command.rs # Magnet link downloader
β β βββ metalink_download_command.rs # Metalink downloader
β β βββ concurrent_download_command.rs # Multi-segment downloader
β βββ src/config/ # Configuration system (~95 options)
β β βββ option.rs # OptionType/Value/Def/Registry
β β βββ parser.rs # Multi-source parser (CLI/file/env/defaults)
β β βββ netrc.rs # NetRC authentication parser
β β βββ uri_list.rs # URI list file (-i option) parser
β β βββ mod.rs # ConfigManager unified runtime manager
β βββ src/request/ # Request management
β β βββ request_group_man.rs # Global task manager
β β βββ request_group.rs # Per-task state machine
β βββ src/filesystem/ # Disk I/O
β β βββ disk_writer.rs # Disk writer trait
β β βββ disk_cache.rs # Cached writer (256KB direct write)
β β βββ control_file.rs # .aria2 control file format
β β βββ file_allocation.rs # Pre-allocation strategies
β β βββ checksum.rs # Checksum verification
β βββ src/http/ # Cookie management
β β βββ cookie.rs # Cookie structure
β β βββ cookie_storage.rs # Persistent storage
β β βββ ns_cookie_parser.rs # Netscape format parser
β βββ src/session/ # Session persistence
β β βββ session_serializer.rs # Serialization
β β βββ auto_save_session.rs # Auto-save
β β βββ save_session_command.rs # Save on exit
β βββ src/rate_limiter.rs # Token bucket rate limiting
β βββ src/ui.rs # Progress bar & status panel
βββ aria2-protocol/ # Protocol stack (~5,000 lines)
β βββ src/http/ # HTTP/HTTPS client (auth/proxy/cookies/compression)
β βββ src/ftp/ # FTP/SFTP client (anonymous+auth, passive mode)
β βββ src/bittorrent/ # Full BT stack
β β βββ bencode/ # BEP3 bencode codec
β β βββ torrent/ # .torrent parsing
β β βββ magnet.rs # Magnet link parsing
β β βββ dht/ # KRPC + routing table + bootstrap
β β βββ tracker/ # UDP/HTTP tracker
β β βββ peer/ # Peer connection + handshake
β β βββ extension/ # MSE/PEX/ut_metadata
β β βββ piece/ # Piece manager + picker
β βββ src/metalink/ # Metalink V3/V4 parser
βββ aria2-rpc/ # RPC server (~1,000 lines)
β βββ src/json_rpc.rs # JSON-RPC 2.0 codec
β βββ src/xml_rpc.rs # XML-RPC codec
β βββ src/websocket.rs # WebSocket event publisher
β βββ src/server.rs # HTTP server (auth/CORS/status)
β βββ src/engine.rs # RpcEngine bridge (25 RPC methods)
βββ bindings/ # Language bindings (~1,200 lines)
βββ python/ # Python SDK (~600 lines)
βββ nodejs/ # Node.js SDK (~627 lines TS)
βββ Cargo.toml # Workspace configuration
Add to your Cargo.toml:
[dependencies]
aria2-core = { path = "../aria2-core" }
aria2-rpc = { path = "../aria2-rpc" }use aria2_core::config::ConfigManager;
use aria2_core::request::request_group_man::RequestGroupMan;
use aria2_core::request::request_group::DownloadOptions;
use aria2_core::config::OptionValue;
#[tokio::main]
async fn main() {
let mut config = ConfigManager::new();
config.set_global_option("dir", OptionValue::Str("./downloads".into())).await.unwrap();
config.set_global_option("split", OptionValue::Int(4)).await.unwrap();
let man = RequestGroupMan::new();
let opts = DownloadOptions {
split: Some(4),
..Default::default()
};
match man.add_group(vec!["http://example.com/file.zip".into()], opts).await {
Ok(gid) => println!("Download started: #{}", gid.value()),
Err(e) => eprintln!("Error: {}", e),
}
}use aria2_rpc::engine::RpcEngine;
use aria2_rpc::json_rpc::JsonRpcRequest;
#[tokio::main]
async fn main() {
let engine = RpcEngine::new();
let req = JsonRpcRequest {
version: Some("2.0".into()),
method: "aria2.addUri".into(),
params: serde_json::json!([["http://example.com/file.zip"]]),
id: Some(serde_json::Value::String("req-1".into())),
};
let resp = engine.handle_request(&req).await;
println!("{}", serde_json::to_string_pretty(&resp).unwrap());
}- Rust: 1.70 or later (install)
- OS: Windows 10+, macOS 10.15+, Linux (glibc 2.17+)
# Debug build (fast compilation)
cargo build
# Release build (optimized)
cargo build --release
# Run tests
cargo test --workspace
# Generate documentation
cargo doc --workspace --no-deps
# Run a specific example
cargo run --example simple_download -- http://example.com/test.bin# Run all tests in workspace
cargo test --workspace
# Run tests for specific crate
cargo test -p aria2-core
# Run tests with verbose output
cargo test --workspace -- --nocapture
# Run specific test category
cargo test "test_e2e" # E2E tests
cargo test "test_stress" # Stress tests
cargo test "test_edge" # Edge case tests
cargo test "test_error" # Error path tests| Category | Prefix | Description |
|---|---|---|
| Unit Tests | test_ |
Inline tests for individual functions |
| Integration Tests | test_ |
Module interaction tests |
| E2E Tests | test_e2e_ |
Complete workflow tests |
| Stress Tests | test_stress_ |
High-load stability tests |
| Edge Case Tests | test_edge_ |
Boundary condition tests |
| Error Path Tests | test_error_ |
Error handling tests |
# Install cargo-tarpaulin (Linux/macOS)
cargo install cargo-tarpaulin
# Generate HTML coverage report
cargo tarpaulin --workspace --out Html --output-dir coverage/
# Generate LCOV format for CI
cargo tarpaulin --workspace --out Lcov --output-dir coverage/# Run all benchmarks
cargo bench --workspace
# Run specific benchmark
cargo bench --bench config_benchFor comprehensive testing guidance, see docs/testing-guide.md.
| Feature | Status | Notes |
|---|---|---|
| CLI arguments | β Core | ~50 most-used options |
Configuration file (aria2.conf) |
β | Same syntax format |
| Environment variables | β | ARIA2_* prefix mapping |
| JSON-RPC API | β | 34 methods (94% coverage) |
| XML-RPC API | β | Full methodCall/response/fault support |
| WebSocket events | β | 7 event types |
URI list file (-i) |
β | Mirror + inline options |
| NetRC auth | β | machine/default/macdef parsing |
| Session save/load | β | Round-trip consistent |
| Metalink V3/V4 | β | Full parsing |
| BitTorrent DHT | β | KRPC + routing table + bootstrap |
| FTP/SFTP | β | Passive mode + auth |
| Rate limiting | β | Token bucket algorithm |
| Cookie management | β | Netscape format persistence |
| MSE/PE encryption | β Complete | BEP14 handshake |
| Magnet link support | β Complete | ut_metadata fetching |
| RarestFirst piece | β Complete | Full implementation |
| Endgame mode | β Complete | Last-piece optimization |
| DHT persistence | β Complete | dht.dat serialization |
| uTP Protocol | β Complete | Not in original aria2 C++ |
| Web Seeds | β Complete | BEP 19 |
| LPD | β Complete | Local Peer Discovery |
| Seeding Mode | β Complete | Upload support |
Not yet implemented (planned for future):
aria2.forceShutdownRPC methodsystem.listMethods/listNotifications- HTTPS RPC support
- IPv6 DHT
- More CLI options (~132 missing)
This project is licensed under GPL-2.0-or-later, consistent with the original aria2 project.
Copyright (C) 2024 aria2-rust contributors.