16 个稳定版本 (4 个主要版本)

6.0.0 2024 年 8 月 6 日
5.6.4 2024 年 4 月 29 日
5.5.4 2024 年 3 月 29 日
5.4.1 2024 年 1 月 3 日
2.2.2 2023 年 11 月 16 日

#165网络编程

Download history 366/week @ 2024-04-29 18/week @ 2024-05-06 2/week @ 2024-05-13 15/week @ 2024-05-20 16/week @ 2024-05-27 12/week @ 2024-06-03 13/week @ 2024-06-10 10/week @ 2024-06-17 104/week @ 2024-07-22 3/week @ 2024-07-29 144/week @ 2024-08-05 16/week @ 2024-08-12

每月 267 次下载

Apache-2.0

755KB
11K SLoC

Rust 9K SLoC // 0.0% comments TSX 2K SLoC // 0.0% comments TypeScript 480 SLoC // 0.1% comments JavaScript 15 SLoC // 0.8% comments

crates.io crates.io docs.rs

rqbit - Rust 中的 BitTorrent 客户端

rqbit 是一个用 Rust 编写的 BitTorrent 客户端。具有 HTTP API 和 Web UI,可作为库使用。

还有一个使用 Tauri 构建的桌面应用程序。

使用快速入门

可选 - 启动服务器

假设您正在将下载内容保存到 ~/Downloads。

rqbit server start ~/Downloads

下载 BitTorrent 文件

假设您正在将下载内容保存到 ~/Downloads。如果服务器已经启动,则可以省略 -o ~/Downloads

rqbit download -o ~/Downloads 'magnet:?....' [https?://url/to/.torrent] [/path/to/local/file.torrent]

Web UI

通过 https://127.0.0.1:3030/web/ 访问。它看起来与桌面应用程序类似,请参见下面的截图。

桌面应用程序

桌面应用程序是 Web UI 前端的一个 轻量级包装

您可以在 发布版 中下载适用于 OSX 和 Windows 的应用程序。对于 Linux,请使用以下命令手动构建:

cargo tauri build
Rqbit desktop

性能

根据一些报告的轶事,rqbit 比他们尝试的其他客户端更快,至少在他们默认设置的情况下。

服务器内存使用量通常在几兆字节以内,这使得它非常适合例如 RaspberryPI。

CPU 主要用于 SHA1 校验和。

安装

发布版 中有预构建的二进制文件。如果有人想把 rqbit 放到例如 homebrew 中,欢迎 PR :)

如果您已安装 Rust 工具链,则应该可以工作

cargo install rqbit

构建

这是一个常规的 Rust 二进制文件构建过程。

cargo build --release

有用选项

-v

增加详细程度。可能的值:trace、debug、info、warn、error。

--list

将打印出托运行或磁力链接的内容。

--overwrite

如果您想要恢复下载已存在的文件,则需要添加此选项。

--peer-connect-timeout=10s

这将增加默认的对等连接超时时间。默认值为2秒,有时可能不够。

-r / --filename-re

在此处使用正则表达式选择文件名。

功能和缺失的功能

一些支持的功能

  • 顺序下载(默认且唯一选项)
  • 如果文件已存在于磁盘上,则恢复下载文件(s)
  • 使用正则表达式对文件名进行选择性下载
  • DHT支持。允许磁力链接工作,并使更多对等点可用。
  • HTTP API
  • 暂停/取消暂停/删除(带或不带文件)API
  • 有状态服务器
  • Web UI

错误、缺失功能和其它注意事项

非常欢迎提交PR。

  • 仅支持通过TCP的BitTorrent V1
  • 由于这是为了个人需求和教学目的而创建的,因此文档、提交消息质量等方面还有很多不足。

HTTP API

默认监听地址为 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",
        "GET /torrents/{index}/peer_stats": "Per peer stats",
        "GET /torrents/{index}/stats/v1": "Torrent stats",
        "GET /web/": "Web UI",
        "POST /rust_log": "Set RUST_LOG to this post launch (for debugging)",
        "POST /torrents": "Add a torrent here. magnet: or http:// or a local file.",
        "POST /torrents/{index}/delete": "Forget about the torrent, remove the files",
        "POST /torrents/{index}/forget": "Forget about the torrent, keep the files",
        "POST /torrents/{index}/pause": "Pause torrent",
        "POST /torrents/{index}/start": "Resume torrent",
        "POST /torrents/{index}/update_only_files": "Change the selection of files to download. You need to POST json of the following form {"only_files": [0, 1, 2]}"
    },
    "server": "rqbit"
}

通过HTTP API添加种子

curl -d 'magnet:?...'http://127.0.0.1:3030/torrents

或者

curl -d 'http://.../file.torrent'http://127.0.0.1:3030/torrents

或者

curl --data-binary@/tmp/xubuntu-23.04-minimal-amd64.iso.torrent http://127.0.0.1:3030/torrents

支持的查询参数,所有都是可选的

  • overwrite=true|false
  • only_files_regex - 匹配文件名的正则表达式字符串
  • output_folder - 下载到的文件夹。如果没有指定,默认为rqbit服务器启动时的文件夹
  • list_only=true|false - 如果你只想列出种子中的文件而不是下载

代码组织

  • crates/rqbit - 主二进制文件
  • crates/librqbit - 主库
  • crates/librqbit-core - 种子工具
  • crates/bencode - bencode序列化/反序列化
  • crates/buffers - 二进制缓冲区的包装器
  • crates/clone_to_owned - 一个使某物变为所有权的特例
  • crates/sha1w - sha1库的包装器
  • crates/peer_binary_protocol - 与对等点通信的协议
  • crates/dht - 分布式哈希表实现
  • desktop - 使用 Tauri 构建桌面应用

动机

首先,我喜欢Rust。项目纯粹是为了编写Rust代码的过程而创建的。

我对我的常规bittorrent客户端不满意,想知道从头开始创建一个新客户端需要多少工作量,它就到了这里,从bencode协议实现开始,然后是 peer 协议等等。

依赖关系

~25–46MB
~731K SLoC