2023-11-22 07:44:52 +00:00
[](https://crates.io/crates/rqbit)
[](https://crates.io/crates/librqbit)
[](https://docs.rs/crate/librqbit/latest)
2023-11-22 07:39:42 +00:00
2021-07-04 18:35:54 +01:00
# rqbit - bittorrent client in Rust
2021-09-29 15:16:18 +01:00
**rqbit** is a bittorrent client written in Rust.
2021-10-17 18:27:07 +01:00
## Installation
2021-10-25 10:44:13 +01:00
There are pre-built binaries in [releases ](https://github.com/ikatson/rqbit/releases ).
2021-10-17 18:27:07 +01:00
If someone wants to put rqbit into e.g. homebrew, PRs welcome :)
2023-11-15 19:07:24 +00:00
If you have rust toolchain installed, this should work:
```
cargo install rqbit
```
2021-10-17 18:27:07 +01:00
## Build
2021-09-29 15:16:18 +01:00
Just a regular Rust binary build process.
cargo build --release
## Usage quick start
2021-10-22 08:03:04 +01:00
### Optional - start the server
2021-09-29 15:16:18 +01:00
2021-10-22 08:03:04 +01:00
Assuming you are downloading to ~/Downloads.
2021-09-29 15:16:18 +01:00
2021-10-22 08:03:04 +01:00
rqbit server start ~/Downloads
2021-09-29 15:16:18 +01:00
2021-10-22 08:03:04 +01:00
### Download torrents
Assuming you are downloading to ~/Downloads. If the server is already started, ```-o ~/Downloads` `` can be omitted.
rqbit download -o ~/Downloads 'magnet:?....' [https?://url/to/.torrent] [/path/to/local/file.torrent]
2021-09-29 15:16:18 +01:00
## Useful options
2021-09-29 15:25:47 +01:00
### -v <log-level>
Increase verbosity. Possible values: trace, debug, info, warn, error.
2021-09-29 15:16:18 +01:00
### --list
Will print the contents of the torrent file or the magnet link.
### --overwrite
If you want to resume downloading a file that already exists, you'll need to add this option.
### --peer-connect-timeout=10s
2021-09-29 15:25:47 +01:00
This will increase the default peer connect timeout. The default one is 2 seconds, and it's sometimes not enough.
2021-09-29 15:16:18 +01:00
### -r / --filename-re
Use a regex here to select files by their names.
## Features and missing features
### Some supported features
2021-09-29 16:41:55 +01:00
- Sequential downloading (the default and only option)
2021-09-29 15:25:47 +01:00
- Resume downloading file(s) if they already exist on disk
- Selective downloading using a regular expression for filename
- DHT support. Allows magnet links to work, and makes more peers available.
2021-09-29 15:16:18 +01:00
- HTTP API
2023-11-22 07:39:42 +00:00
- Web UI
2021-09-29 15:16:18 +01:00
### Code features
- Serde-based bencode serializer/deserializer
2021-09-29 15:25:47 +01:00
- Custom code for binary protocol serialization/deserialization. And for everything else too :)
2021-09-29 15:16:18 +01:00
- Supports several SHA1 implementations, as this seems to be the biggest performance bottleneck. Default is openssl as it's the fastest in my benchmarks.
- In theory, the libraries that rqbit is made of are re-usable.
2021-09-29 15:25:47 +01:00
- No unsafe
2021-09-29 15:16:18 +01:00
### Bugs, missing features and other caveats
2023-11-22 07:39:42 +00:00
PRs are very welcome.
2021-09-29 15:16:18 +01:00
2021-09-29 15:25:47 +01:00
- Only supports BitTorrent V1 over TCP
- As this was created for personal needs, and for educational purposes, documentation, commit message quality etc. leave a lot to be desired.
2021-09-29 15:16:18 +01:00
## HTTP API
2021-09-29 16:41:55 +01:00
By default it listens on http://127.0.0.1:3030.
curl -s 'http://127.0.0.1:3030/'
{
"apis": {
"GET /": "list all available APIs",
"GET /dht/stats": "DHT stats",
"GET /dht/table": "DHT routing table",
"GET /torrents": "List torrents (default torrent is 0)",
"GET /torrents/{index}": "Torrent details",
"GET /torrents/{index}/haves": "The bitfield of have pieces",
2021-10-18 13:11:45 +01:00
"GET /torrents/{index}/stats": "Torrent stats",
2023-11-22 07:39:42 +00:00
"POST /torrents/": "Add a torrent here. magnet: or http:// or a local file.",
"GET /web/": "Web UI"
2021-09-29 16:41:55 +01:00
}
2021-10-18 13:11:45 +01:00
}
### Add torrent through HTTP API
```curl -d 'magnet:?...' http://127.0.0.1:3030/torrents` ``
OR
```curl -d 'http://.../file.torrent' http://127.0.0.1:3030/torrents` ``
OR
```curl -d '/some/local/file.torrent' http://127.0.0.1:3030/torrents` ``
2021-10-25 10:46:10 +01:00
Supported query parameters, all optional:
2021-10-25 10:44:13 +01:00
- overwrite=true|false
2021-10-25 10:46:10 +01:00
- only_files_regex - the regular expression string to match filenames
- output_folder - the folder to download to. If not specified, defaults to the one that rqbit server started with
- list_only=true|false - if you want to just list the files in the torrent instead of downloading
2023-11-22 07:39:42 +00:00
## Web UI
Access with http://localhost:3030/web/
< img width = "1165" alt = "Web UI" src = "https://github.com/ikatson/rqbit/assets/221386/3854c1d6-94ee-4416-8af5-7ede6cd2047a" >
## Code organization
- crates/rqbit - main binary
- crates/librqbit - main library
- crates/librqbit-core - torrent utils
- crates/bencode - bencode serializing/deserializing
- crates/buffers - wrappers around binary buffers
- crates/clone_to_owned - a trait to make something owned
- crates/sha1w - wrappers around sha1 libraries
- crates/peer_binary_protocol - the protocol to talk to peers
- crates/dht - Distributed Hash Table implementation
## Motivation
First of all, I love Rust. The project was created purely for the fun of the process of writing code in Rust.
I was not satisfied with my regular bittorrent client, and was wondering how much work would it be to create a new one from scratch, and it got where it is, starting from bencode protocol implemenation, then peer protocol, etc, etc.