aria2-rust
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.
Features
- 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
Quick Start
One-Line Installation (Recommended)
Linux / macOS:
|
Windows (PowerShell):
irm https://raw.githubusercontent.com/balovess/aria2_rust/main/install.ps1 | iex
Docker:
Package 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 |
First Download
After installation, start downloading immediately:
# Download a file
# Download with multiple connections
# Download a torrent
# Download with custom directory
Build from Source
Prerequisites:
- Rust 1.70+ (stable)
- Windows / macOS / Linux
Build Commands:
# Clone the repository
# Build all crates
# Download a file (HTTP)
# Download with custom options
# Show help
# Show version
Usage
Configuration Templates
We 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
# Edit as needed
# Run with configuration
Basic HTTP Download
With Options
| 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 |
BitTorrent Download
URI List File
Create 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:
Architecture
Total 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
Library Usage
As a library in your Rust project
Add to your Cargo.toml:
[]
= { = "../aria2-core" }
= { = "../aria2-rpc" }
Minimal download example
use ConfigManager;
use RequestGroupMan;
use DownloadOptions;
use OptionValue;
async
RPC server example
use RpcEngine;
use JsonRpcRequest;
async
Building from Source
Requirements
- Rust: 1.70 or later (install)
- OS: Windows 10+, macOS 10.15+, Linux (glibc 2.17+)
Build Commands
# Debug build (fast compilation)
# Release build (optimized)
# Run tests
# Generate documentation
# Run a specific example
Testing
Running Tests
# Run all tests in workspace
# Run tests for specific crate
# Run tests with verbose output
# Run specific test category
Test Categories
| 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 |
Coverage Report
# Install cargo-tarpaulin (Linux/macOS)
# Generate HTML coverage report
# Generate LCOV format for CI
Running Benchmarks
# Run all benchmarks
# Run specific benchmark
For comprehensive testing guidance, see docs/testing-guide.md.
Compatibility with Original aria2
| 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)
License
This project is licensed under GPL-2.0-or-later, consistent with the original aria2 project.
Copyright (C) 2024 aria2-rust contributors.