node.js - 连接到 torrent 跟踪器/对等点

标签 node.js udp bittorrent

我目前正在尝试在 nodeJS 中实现一个最小的 torrent 客户端。

我正在阅读此规范:https://wiki.theory.org/index.php/BitTorrentSpecification

我有 2 个磁铁 URI:

magnet:?xt=urn:btih:633ab5b0cc27218bca2f9fec9b68ae4f7cbf0c5f&dn=dmb2017-05-31.dpa4021.flac16


xt=urn:btih:633ab5b0cc27218bca2f9fec9b68ae4f7cbf0c5f
dn=dmb2017-05-31.dpa4021.flac16
<小时/>
magnet:?xt=urn:btih:9f9165d9a281a9b8e782cd5176bbcc8256fd1871&dn=Ubuntu+16.04.1+LTS+Desktop+64-bit&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969

xt=urn:btih:9f9165d9a281a9b8e782cd5176bbcc8256fd1871
dn=Ubuntu+16.04.1+LTS+Desktop+64-bit
tr=udp://tracker.leechers-paradise.org:6969
tr=udp://zer0day.ch:1337
tr=udp://open.demonii.com:1337
tr=udp://tracker.coppersurfer.tk:6969
tr=udp://exodus.desync.com:6969

据我所知,跟踪器用于查找对等点,并从中下载数据。那么如何下载第一个种子呢?它没有跟踪器。

我实际上如何进行此连接?

该规范没有任何关于磁力链接的内容,并声明跟踪器可以通过 HTTP(S) 协议(protocol)使用,但这些显然是 UDP。

我对此进行了尝试:

var PORT = 6969 ;
var HOST = 'tracker.leechers-paradise.org';

var dgram = require('dgram');
var message = new Buffer("xt=urn:btih:9f9165d9a281a9b8e782cd5176bbcc8256fd1871");

var client = dgram.createSocket('udp4');

client.on('listening', function () {
    var address = client.address();
    console.log('UDP Server listening on ' + address.address + ":" + address.port);
});

client.on('message', function (message, remote) {

    console.log(remote.address + ':' + remote.port +' - ' + message);

});

client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {

    if (err) throw err;
    console.log('UDP message sent to ' + HOST +':'+ PORT);
    console.log(bytes);

});

显然,这不起作用,但我找不到任何可以提供帮助的文档。

最佳答案

非官方Wiki.theory.org/BitTorrentSpecification毫无疑问,这是开始学习 BitTorrent 协议(protocol)的最佳起点,但它并不完整。它只涵盖了基础协议(protocol)和早年开发的扩展。这就是为什么您无法在那里找到所需的所有信息。

自 2008 年以来,可以在 BitTorrent.org 找到该协议(protocol)的官方*文档。 .
官方版本的基础协议(protocol)简洁而密集BEP3 - The BitTorrent Protocol Specification

磁力链接包含在 BEP9 - Extension for Peers to Send Metadata Files 中.
您可以在那里阅读:

If no tracker is specified, the client SHOULD use the DHT to acquire peers.

DHT 在 BEP5 - DHT Protocol 中指定。

正如您所注意到的,现在的跟踪器使用 UDP,这在 BEP15 - UDP Tracker Protocol 中指定。 。

<小时/>

脚注:* 官方仅表示它由 BitTorrentInc 运行,而不表示它是高级的或唯一可使用的来源。 BitTorrent 协议(protocol)不受权威机构管辖。没有客户宣誓效忠 BEP。该协议(protocol)是根据真实客户端的共识形成的。

关于node.js - 连接到 torrent 跟踪器/对等点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44332799/

相关文章:

bittorrent - torrent文件的内容

javascript - 使用具有多个查询的 Node.js 构建 JSON

ios - 如何使用 node.JS 创建基于 token 的登录机制?

c# - 为什么我的 UDP 数据包发送到我自己的公共(public) IP 时没有收到?

c# - .net 的多线程网络 UDP 服务器库

c# - 创建对象的新实例,还是修改现有实例?

node.js - 为什么每次关闭浏览器时我的 session 都会过期?

javascript - res.redirect 在表单提交后显示旧信息?

Java UDP数据包读取失败

javascript - 是否可以仅使用 HTML(5) 和 JavaScript 构建 Torrent 客户端?