bittorrent协议规范_英文

合集下载

BitTorrent协议规范

BitTorrent协议规范
Objective-C by Chrome
BitTorrent协议规范(BitTorrent Protocol Specification)系列之元信息文件结构(Metainfo File Structure)-第二部分 元信息文件结构(Metainfo File Structure)
元信息文件里面的所有数据都以B编码方式编码,B编码规范请参考本系列文档之B编码。
private: (可选),这个键(key)所对应值是整数类型,如果设置为1。客户端必须广播自己的存在,然后通过在元信息文件中显式描述的trackers得到其他的peers,如果设置为0或者不设置,则表明客户端可以通过其他的方式来得到其他的peers,例如:PEX peer exchange技术,DHT技术等。“private”可以解释为没有外部的peer源(如果客户端不提供PEX peer exchange技术、DHT技术等,那么BitTorrent客户端必须通过tracker来得到其他的peers)。(整数类型)
BitTorrent协议规范(BitTorrent Protocol Specification)之Tracker HTTP/HTTPS Protocol-第三部分 Tracker HTTP/HTTPS Protocol
Info Dictionary(即键Info对应的值)
这一节主要是讲述两种模式(单文件模式和多文件)所共有的键(key)
piece length: 该键对应的值是每一片(piece)的字节数。(整数类型)
pieces: 该键对应的值由所有的20字节SHA1散列值连接而成的字符串,每一片(piece)均含有一个唯一的SHA1散列值。(字节串类型)
length:参考单文件模式

BitTorrent完全使用教程

BitTorrent完全使用教程

从网上下载,听起来容易,但想真正成为高手,就要做到“下别人之不能下,载别人所不会载”,其中的门道可并不简单。

提到下载,很多人都认为所谓的download不过是从网上把软件或mp3复制到硬盘中的一个过程。

然而,如果真用这个标准来衡量的话,恐怕把全世界网民至少能数出几亿个下载高手来。

可实际上,下载包含的内容远不止于此。

从理论上讲,即使是浏览普通的网页也应该算是下载的一种,何况去下载软件、音乐、图书等更精彩的资源了。

网络的开放性不断吸引着人们去寻找对自身有价值的东西,而各种商业网站又为了自身的利益,不断依靠“先进”技术使它们提供的资源逐渐封闭化。

为了下载一个软件而打开三层页面的网站并不少见,而更多的图库站点更需要您不断点击大大小小的链接才肯露出庐山真面目;说是免费阅读图书,又不让您下载,给您一个连抓图都不支持的java窗口,慢慢看去吧!(估计等您把书看完,您的网费开销能买十本原版书了。

)有人说,网上的免费是糖衣炮弹:想下载软件,请您看广告;想聊天,请您看广告;想要免费信箱,请您看广告(更有附加在您每封邮件末尾的广告)。

还有,某些精彩的flash动画、real影片以及各种在线播放的音频和视频,更是“只可远观而不可亵玩焉”——不支持下载!难道就没有把糖衣吃掉再抛弃炸弹的方法吗?当然有!正所谓魔高一尺,道高一丈。

对付特别的站点就要使用特别的方法,才能获取某些平时无法取得或者十分难以取得的资源。

您想下载嵌在网页里的flash动画吗?您想下载只提供在线播放的real格式电影吗?您想下载收费的电子图书吗?您想学习更强大的超批量下载技巧吗?那就千万不要错过下面的文字,这就是——极限下载秘技!获取真实的下载地址工欲善其事,必先利其器,我们当然不必去研究如何更加科学地使用ie的下载窗口,因此您至少需要下面两个流行的下载软件之一:网际快车flashget(推荐使用)或网络蚂蚁netants。

作为一个网民,笔者有时不得不向朋友提供某个软件的下载地址,然而这就出现了一个关于真实下载地址的问题。

USB Type-C 规范1.2(中文版)

USB Type-C 规范1.2(中文版)
INTELLECTUAL PROPERTY DISCLAIMER
知识产权声明
THIS SPECIFICATION IS PROVIDED TO YOU “AS IS” WITH NO WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE. THE AUTHORS OF THIS SPECIFICATION DISCLAIM ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, RELATING TO USE OR IMPLEMENTATION OF INFORMATION IN THIS SPECIFICATION. THE PROVISION OF THIS SPECIFICATION TO YOU DOES NOT PROVIDE YOU WITH ANY LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS.
预发行行业审查公司提供反馈
Revision History.......................................................................................................................14
LIMITED COPYRIGHT LICENSE: The USB 3.0 Promoters grant a conditional copyright license under the copyrights embodied in the USB Type-C Cable and Connector Specification to use and reproduce the Specification for the sole purpose of, and solely to the extent necessary for, evaluating whether to implement the Specification in products that would comply with the specification.

bt协议详解基础篇(上)

bt协议详解基础篇(上)

bt协议详解基础篇(上)bt协议详解基础篇(上)最近开发了⼀个的⽹站,产⽣了仔细了解bt协议的想法,所以写了这⼀篇⽂章,后续还会写⼀些关于搜索和索引的东西,都是在开发这个⽹站的过程中学习到的技术,敬请期待。

1 简介bt是BitTorrent协议的简称,bt协议是最流⾏的p2p下载协议,另外⼀种⽐较流⾏的p2p下载协议叫ed2k,ed2k的全称叫eDonkey2000 network,这⾥我们只讨论bt协议,ed2k协议以后有机会再和⼤家分享。

相信很多⼈都听说过bt协议。

但是当我问周围的⼈究竟什么是bt协议呢?他们的解释让我对bt协议的理解变得更含糊,为了弄清楚⼼中的问题,我开始了⾃⼰对bt协议的学习。

我在上找到⼀篇⽂章。

这个标题翻译过来就是“bittorrent协议规范”,是bittorrent协议的基础篇,为什么说是基础篇呢?BT协议是⼀个协议簇。

有点像tcp/ip协议⼀样,bt协议不是⼀个简单的协议,⽽是⼀系列相关的协议组成的,⽽且这个协议簇⼀直在进化。

既然这篇⽂章的主题是“基础篇”,所以它的内容主要来⾃,也就是bittorrent协议规范,因为其它的协议都是以这个协议为基础的,可见这个的重要性。

2 bittorrent协议规范(中⽂版)bittorrent是⼀个⽂件分发协议,它使⽤url来定位⽂件⽽且跟web服务⽆缝集成。

当有多个⼈同时下载同⼀个⽂件时,下载者之间可以互相上传⾃⼰已有的那部分⽂件,让⼀个⽂件⽀持很多⼈同时下载却只增加⼩量的带宽负担变成可能,这就是bt协议相⽐http协议的优势。

bt⽂件分享由下列内容组成:1. 传统的⽂件服务器2. 种⼦⽂件(.torrent⽂件)3. bt tracker服务器4. ⽂件分享者5. web浏览器6. web浏览器⽤户(多个)⼀个服务器按照下⾯的步骤开始⽂件分享过程1. 启动⼀个bt tracker服务器2. 启动⼀个普通的web服务器,如apache3. 在web服务器上配置多媒体类型‘application/x-bittorrent’关联到.torrent⽂件4. ⽣成⼀个.torrent⽂件,在⽂件中添加bt tracker服务器的地址5. 上传torrent⽂件到web服务器6. 发布torrent⽂件下载页⾯7. 等待⽤户下载⼀个⽤户按照下⾯的步骤开始⽂件下载1. 安装bt客户端2. 浏览web页⾯3. 下载torrent⽂件4. 保存torrent⽂件到本地5. 使⽤bt客户端打开torrent⽂件,开始下载6. 等待⽂件下载完成bencoding编码strings(字符串)编码为:<字符串长度>:<字符串> 例如: 4:test 表⽰为字符串"test",4:例⼦表⽰为字符串“例⼦”,字符串长度单位为字节,没开始或结束标记integers(整数)编码为:i<整数>e,开始标记i,结束标记为e,例如:i1234e 表⽰为整数1234,i-1234e 表⽰为整数-1234,整数没有⼤⼩限制,i0e 表⽰为整数0,i-0e 为⾮法,以0开头的为⾮法如: i01234e 为⾮法lists(列表)编码为:le,开始标记为l,结束标记为e,列表⾥可以包含任何bencoding编码类型,包括整数,字符串,列表,字典。

bit torrent协议原理

bit torrent协议原理

bit torrent协议原理
BitTorrent协议是一种点对点(P2P)传输协议,用于高效地下载和上传大型文件。

它的原理是将文件分成较小的块,然后将这些块同时下载,从而实现更快的下载速度。

在BitTorrent网络中,每个用户都可以同时充当下载者和上传者,从而帮助其他用户下载文件。

BitTorrent协议使用一种称为“种子文件”的文件来描述要下载的文件。

种子文件包含有关文件的元数据,例如文件名、大小和哈希值(用于验证文件块的完整性)。

用户可以通过BitTorrent客户端打开种子文件,然后开始下载文件。

当用户下载文件时,BitTorrent客户端将文件分成较小的块,并从其他用户下载这些块。

如果一个用户没有完整的文件,但已经下载了一些块,他们可以立即将这些块上传给其他用户,以帮助他们更快地下载文件。

这种互相分享的方式有助于提高性能和可靠性。

BitTorrent协议还使用一种称为“种子”的机制来保持文件的可用性。

种子是指拥有完整文件的用户,他们可以选择继续上传文件,以帮助其他用户下载文件。

种子可以帮助保持文件的可用性,因为只要至少存在一个种子,其他用户就可以下载完整的文件。

如果没有种子,那么文件可能会变得不可用。

总的来说,BitTorrent协议是一种创新的P2P传输协议,它能够实现高效、可靠的大型文件传输。

通过将下载和上传相结合,BitTorrent使每个用户都成为网络的一部分,从而促进了文件的可用性和传输速度。

bittoorent协议

bittoorent协议

BitTorrent协议1. 简介BitTorrent协议是一种用于大规模文件共享的协议,它允许用户通过P2P(点对点)方式分享和下载文件。

该协议由布兰姆·科恩(Bram Cohen)在2001年开发,目前已成为最流行的P2P文件共享协议之一。

2. 工作原理BitTorrent协议的工作原理可以概括为以下几个步骤:2.1 种子文件在使用BitTorrent协议进行文件共享之前,用户首先需要创建一个种子文件。

种子文件包含了文件的元数据信息,如文件名、文件大小、文件分块等。

种子文件通常使用.torrent扩展名,并通过Tracker服务器进行分发。

2.2 Tracker服务器Tracker服务器是BitTorrent网络中的中央服务器,用于协调下载和上传的节点。

当用户想要下载一个文件时,他们需要连接到Tracker服务器,获取其他节点的列表。

Tracker服务器会返回一个包含其他节点信息的Peer列表,用户可以与这些节点建立连接。

2.3 分块下载一旦用户连接到其他节点,他们可以开始下载文件。

文件在BitTorrent协议中被分成多个固定大小的块。

用户可以选择下载特定的块,而不是整个文件。

这种分块下载的方式使得下载速度更快,并减轻了网络负荷。

2.4 分享与上传BitTorrent协议强调分享和上传的重要性。

用户在下载文件的同时也在上传文件的块给其他节点。

这种互相分享的机制使得文件能够更快地传播,同时也减轻了原始服务器的负荷。

2.5 智能下载策略BitTorrent协议具有智能下载策略,它会优先下载那些拥有更多块的节点。

这种策略可以提高整体下载速度,并减少下载时间。

3. BitTorrent协议的优势BitTorrent协议相对于传统的文件下载方式有以下优势:3.1 高速下载由于BitTorrent协议采用了分块下载的方式,用户可以同时从多个节点下载文件的不同块。

这样可以大大提高下载速度,尤其是在大文件和热门文件的情况下。

bittorrent的结构

bittorrent的结构

bittorrent的结构
BitTorrent协议的系统结构包括以下四个主要组成部分:
1. WWW服务器(或其他能让最终用户获得种子文件的服务):提供上传和下载Torrent种子文件的功能。

2. Tracker:Tracker是指运行于服务器上的一个服务程序,也称Tracker服务器。

这个程序能够追踪到底有多少人同时在下载或上传同一个文件。

客户端连上Tracker服务器,就会获得一个正在下载和上传的用户的IP地址、端口、客户端ID等信息列表,根据这些信息,BT客户端会自动连上别的用户进行下载和上传。

3. 最终用户web浏览器(或其他能让最终用户获得种子文件的软件):提供上传和下载Torrent种子文件的功能。

4. 最终用户下载软件:泛指运行在用户自己电脑上的支持BitTorrent协议的程序。

以上是BitTorrent协议的系统结构的主要内容,供您参考,详细信息可以查询官网。

bt协议书

bt协议书

bt协议书BT协议书写BT(BitTorrent)是一种用于文件共享的协议,也是一种点对点(P2P)通信协议。

它的主要特点是能够实现高效的文件传输和共享,以及支持大规模的用户参与。

在互联网的发展过程中,BT协议广泛应用于文件下载、资源分享等各个领域。

下面,我将详细介绍BT协议的基本原理和实现机制。

首先,BT协议的基本原理是将一个文件分割成若干个小块,并将这些小块分布在不同的用户之间进行共享。

在文件下载的过程中,每个用户既充当文件的下载者,同时也充当文件的上传者。

这种点对点的方式使得下载速度更快,同时也减轻了服务器的负担。

其次,BT协议的实现机制主要包括Tracker服务器、种子文件和对等下载。

Tracker服务器是一个集中的管理者,它负责监控和管理参与文件下载的所有用户,并维护一个用户列表。

用户需要首先通过Tracker服务器获取文件的种子文件,种子文件包含了文件的详细信息和下载地址。

一旦获得种子文件,用户就可以开始下载文件了。

对等下载是BT协议的核心机制,它实现了用户之间的资源共享和交换。

在下载过程中,用户首先连接Tracker服务器,向其报告自己的下载状态,并获取其他用户的IP地址列表。

然后,用户通过与其他用户建立连接,请求并下载文件的小块。

同时,用户也允许其他用户从自己这里下载文件的小块。

这种对等下载的方式使得文件的下载速度相对较快,并且可以实现较好的负载均衡。

除了基本原理和实现机制,BT协议还具有一些特殊的优势和问题。

首先,BT协议具有高效的文件传输能力。

由于文件被分割成多个小块,并且可以从多个用户处同时下载,因此可以实现更快的下载速度。

另外,BT协议还支持断点续传,即当下载过程中出现中断,用户可以继续之前的下载进度,而不需要从头开始。

然而,BT协议也存在一些问题。

首先,由于BT协议的文件共享特点,使得版权保护问题比较突出。

很多用户利用BT协议进行盗版行为,侵犯了版权者的权益。

其次,BT协议也容易受到网络攻击,例如DHT攻击和假种子攻击等。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

BitTorrentSpecification tryFrom TheoryOrgJump to: navigation, searchBittorrent Protocol Specification v1.0Contents[hide]∙ 1 Identification∙ 2 Purpose∙ 3 Scope∙ 4 Related Documents∙ 5 Conventions∙ 6 bencodingo 6.1 byte stringso 6.2 integerso 6.3 listso 6.4 dictionarieso 6.5 Implementations∙7 Metainfo File Structureo7.1 Info Dictionary▪7.1.1 Info in Single File Mode▪7.1.2 Info in Multiple File Modeo7.2 Notes∙8 Tracker HTTP/HTTPS Protocolo8.1 Tracker Request Parameterso8.2 Tracker Response∙9 Tracker 'scrape' Conventiono9.1 Unofficial extensions to scrape∙10 Peer wire protocol (TCP)o10.1 Overviewo10.2 Data Typeso10.3 Message flowo10.4 Handshake▪10.4.1 peer_ido10.5 Messages▪10.5.1 keep-alive: <len=0000>▪10.5.2 choke: <len=0001><id=0>▪10.5.3 unchoke: <len=0001><id=1>▪10.5.4 interested: <len=0001><id=2>▪10.5.5 not interested: <len=0001><id=3>▪10.5.6 have: <len=0005><id=4><piece index>▪10.5.7 bitfield: <len=0001+X><id=5><bitfield>▪10.5.8 request:<len=0013><id=6><index><begin><length>▪10.5.9 piece:<len=0009+X><id=7><index><begin><block>▪10.5.10 cancel:<len=0013><id<=8><index><begin><length>▪10.5.11 port: <len=0003><id=9><listen-port>∙11 Algorithmso11.1 Queuingo11.2 Super Seedingo11.3 Piece downloading strategyo11.4 End Gameo11.5 Choking and Optimistic Unchoking▪11.5.1 Anti-snubbing∙12 Official Extensions To The Protocolo12.1 Fast Peers Extensionso12.2 Distributed Hash Tableo12.3 Connection Encryption∙13 Unofficial Extensions To The Protocolo13.1 Azureus Messaging Protocolo13.2 WebSeedingo13.3 Extension protocolo13.4 Extension Negotiation Protocolo13.5 BitTorrent Location-aware Protocol 1.0o13.6 SimpleBT Extension Protocolo13.7 BitComet Extension Protocol∙14 Reserved Bytes∙15 Change LogIdentificationBitTorrent is a peer-to-peer file sharing protocol designed by Bram Cohen. Visit his pages at BitTorrent is designed tofacilitate file transfers among multiple peers across unreliablenetworks.PurposeThe purpose of this specification is to document version 1.0 of the BitTorrent protocol specification in detail. Bram's protocolspecification page outlines the protocol in somewhat general terms, and lacks behaviorial detail in some areas. The hope is that this document will become a formal specification, written in clear, unambiguous terms, which can be used as a basis for discussion and implementation in the future.This document is intended to be maintained and used by the BitTorrent development community. Everyone is invited to contribute to this document, with the understanding that the content here is intended to represent the current protocol, which is already deployed in a number of existing client implementations.This is not the place to suggest feature requests. For that, please go to the mailing list.ScopeThis document applies to the first version (i.e. version 1.0) of the BitTorrent protocol specification. Currently, this applies to the torrent file structure, peer wire protocol, and the Tracker HTTP/HTTPS protocol specifications. As newer revisions of each protocol are defined, they should be specified on their own separate pages, not here.Related DocumentsOfficial protocol specificationDeveloper and user wishlistTracker protocol extensionsConventionsIn this document, a number of conventions are used in an attempt to present information in a concise and unambiguous fashion.∙peer v/s client: In this document, a peeris any BitTorrent client participating ina download. The client is also a peer,however it is the BitTorrent client thatis running on the local machine. Readersof this specification may choose to thinkof themselves as the client whichconnects to numerous peers.∙piece v/s block: In this document, a piecerefers to a portion of the downloaded datathat is described in the metainfo file,which can be verified by a SHA1 hash. Ablock is a portion of data that a clientmay request from a peer. Two or moreblocks make up a whole piece, which maythen be verified.∙defacto standard: Large blocks of text initalics indicates a practice so common invarious client implementations ofBitTorrent that it is considered adefacto standard.In order to help others find recent changes that have been made to this document, please fill out the change log (last section). This should contain a brief (i.e. one-line) entry for each major change that you've made to the document.bencodingBencoding is a way to specify and organize data in a terse format. It supports the following types: byte strings, integers, lists, and dictionaries.byte stringsByte strings are encoded as follows: <string length encoded in base ten ASCII>:<string data>Note that there is no constant beginning delimiter, and no ending delimiter."spam"integersIntegers are encoded as follows: i<integer encoded in base ten ASCII>e The initial i and trailing e are beginning and ending delimiters. You can have negative numbers such as i-3e. You cannot prefix the number with a zero such as i04e. However, i0e is valid.Example: i3e represents the integer "3"NOTE: The maximum number of bit of thisinteger is unspecified, but to handle itas a signed 64bit integer is mandatory tohandle "large files" aka .torrent formore that 4GbytelistsLists are encoded as follows: l<bencoded values>eThe initial l and trailing e are beginning and ending delimiters. Lists may contain any bencoded type, including integers, strings, dictionaries, and other lists.Example:l4:spam4:eggs e represents thelist of two strings: [ "spam", "eggs" ] dictionariesDictionaries are encoded as follows: d<bencoded string><bencoded element>eThe initial d and trailing e are the beginning and ending delimiters. Note that the keys must be bencoded strings. The values may be any bencoded type, including integers, strings, lists, and other dictionaries. Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics). The strings should be compared using a binary comparison, not a culture-specific "natural" comparison.Example: d3:cow3:moo4:spam4:eggs erepresents the dictionary { "cow" =>"moo", "spam" => "eggs" }dictionary { "spam" => [ "a", "b" ] }Example:d9:publisher3:bob17:publisher-webpage15:18:publisher.location4:home e represents { "publisher" => "bob","publisher-webpage" =>"", "publisher.location"=> "home" }Implementations∙C∙Perl∙Java∙Python by Hackeron∙Decoding encoding bencoded data withhaskell by Edi∙Objective-C by ChromeMetainfo File StructureAll data in a metainfo file is bencoded. The specification for bencoding is defined above.The content of a metainfo file (the file ending in ".torrent") is a bencoded dictionary, containing the keys listed below. All character string values are UTF-8 encoded.∙info: a dictionary that describes thefile(s) of the torrent. There are twopossible forms: one for the case of a'single-file' torrent with no directorystructure, and one for the case of a'multi-file' torrent (see below fordetails)∙announce: The announce URL of the tracker(string)∙announce-list: (optional) this is anextention to the official specification,which is also backwards compatible. Thiskey is used to implement lists of backuptrackers. The full specification can befound here.∙creation date: (optional) the creationtime of the torrent, in standard UNIXepoch format (integer seconds since1-Jan-1970 00:00:00 UTC)∙comment: (optional) free-form textualcomments of the author (string)∙created by: (optional) name and versionof the program used to create the .torrent(string)Info DictionaryThis section contains the field which are common to both mode, "single file" and "multiple file".∙piece length: number of bytes in eachpiece (integer)∙pieces: string consisting of theconcatenation of all 20-byte SHA1 hashvalues, one per piece (byte string)∙private: (optional) this field is aninteger. If it is set to "1", the clientMUST publish its presence to get otherpeers ONLY via the trackers explicitlydescribed in the metainfo file. If thisfield is set to "0" or is not present, theclient may obtain peer from other means,e.g. PEX peer exchange, dht. Here,"private" may be read as "no external peersource".o NOTE:this definition is a stub, useit at your own risk, some disagreewith it. feel free to improve it./index.php/Secure_Torrents is thedefinition from azureus wikio Additionnally it should be notedthat even if this field is used inpractice, it is not part of theofficial specification.Info in Single File ModeFor the case of the single-file mode, the info dictionary contains the following structure:∙name: the filename of the file. This ispurely advisory. (string)∙length: length of the file in bytes(integer)∙md5sum: (optional) a 32-characterhexadecimal string corresponding to theMD5 sum of the file. This is not used byBitTorrent at all, but it is included bysome programs for greater compatibility. Info in Multiple File ModeFor the case of the multi-file mode, the info dictionary contains the following structure:∙name: the filename of the directory inwhich to store all the files. This ispurely advisory. (string)∙files: a list of dictionaries, one foreach file. Each dictionary in this listcontains the following keys:o length: length of the file in bytes(integer)o md5sum: (optional) a 32-characterhexadecimal string correspondingto the MD5 sum of the file. This isnot used by BitTorrent at all, butit is included by some programs forgreater compatibility.o path: a list containing one or morestring elements that togetherrepresent the path and filename.Each element in the listcorresponds to either a directoryname or (in the case of the finalelement) the filename. For example,a the file "dir1/dir2/file.ext"would consist of three stringelements: "dir1", "dir2", and"file.ext". This is encoded as abencoded list of strings such asl4:dir14:dir28:file.exteNotes∙The piece length specifies the nominalpiece size, and is usually a power of 2.The piece size is typically chosen basedon the total amount of file data in thetorrent, constrained by the fact thatpiece sizes too large cause inefficiency,and too small a piece size will result ina large .torrent metadata file. Theconventional wisdom used to be to pick thesmallest piece size that results ina .torrent file no greater than approx.50 - 75 kB (presumably to ease the loadon the server hosting the torrent files).However, now that hosting storage andbandwidth are not tightly constrained, itis best to keep the piece size to 512KBor less, at least for torrents under8-10GB or so, even if that results in alarger torrent file, in order to have amore efficient swarm for sharing files.The most common sizes are 256 kB, 512 kB,and 1 MB. Every piece is of equal lengthexcept for the final piece, which isirregular. The number of pieces is thusdetermined by 'ceil( total length / piecesize )'. For the purposes of pieceboundaries in the multi-file case,consider the file data as one longcontinuous stream, composed of theconcatenation of each file in the orderlisted in the files list. The number ofpieces and their boundaries are thendetermined in the same manner as the caseof a single file. Pieces may overlap fileboundaries.∙Each piece has a corresponding SHA1 hashof the data contained within that piece.These hashes are concatenated to form thepieces value in the above info dictionary.Note that this is not a list but rathera single string. The length of the stringmust be a multiple of 20.Tracker HTTP/HTTPS ProtocolThe tracker is an HTTP/HTTPS service which responds to HTTP GET requests. The requests include metrics from clients that help the tracker keep overall statistics about the torrent. The response includes a peer list that helps the client participate in the torrent. The base URL consists of the "announce URL" as defined in the metadata (.torrent) file. The parameters are then added to this URL, using standard CGI methods (i.e.a '?' after the announce URL, followed by 'param=value' sequences separated by '&').Note that all binary data in the URL (particularly info_hash and peer_id) must be properly escaped. This means any byte not in the set 0-9, a-z, A-Z, '.', '-', '_' and '~', must be encoded using the "%nn" format, where nn is the hexadecimal value of the byte. (See RFC1738 for details.)For a 20-byte hash of\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a,The right encoded form is %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A Tracker Request ParametersThe parameters used in the client->tracker GET request are as follows:∙info_hash: urlencoded 20-byte SHA1 hashof the value of the info key from theMetainfo file. Note that the value willbe a bencoded dictionary, given thedefinition of the info key above.∙peer_id: urlencoded 20-byte string usedas a unique ID for the client, generatedby the client at startup. This is allowedto be any value, and may be binary data.There are currently no guidelines forgenerating this peer ID. However, one mayrightly presume that it must at least beunique for your local machine, thusshould probably incorporate things likeprocess ID and perhaps a timestamprecorded at startup. See peer_id belowfor common client encodings of thisfield.∙port: The port number that the client is listening on. Ports reserved forBitTorrent are typically 6881-6889.Clients may choose to give up if it cannot establish a port within this range.∙uploaded: The total amount uploaded (since the client sent the 'started'event to the tracker) in base ten ASCII.While not explicitly stated in theofficial specification, the concensus is that this should be the total number of bytes uploaded.∙downloaded: The total amount downloaded (since the client sent the 'started'event to the tracker) in base ten ASCII.While not explicitly stated in theofficial specification, the consensus is that this should be the total number of bytes downloaded.∙left: The number of bytes this client still has to download, encoded in base ten ASCII.∙compact: Setting this to 1 indicates that the client accepts a compact response.The peers list is replaced by a peersstring with 6 bytes per peer. The first four bytes are the host (in network byte order), the last two bytes are the port (again in network byte order). It should be noted that some trackers only support compact responses (for saving bandwidth) and either refuse requests without"compact=1" or simply send a compactresponse unless the request contains"compact=0" (in which case they willrefuse the request.)∙no_peer_id: Indicates that the tracker can omit peer id field in peers dictionary.This option is ignored if compact isenabled.∙event: If specified, must be one of started, completed, stopped, (or emptywhich is the same as not being specified).If not specified, then this request is one performed at regular intervals.o started: The first request to thetracker must include the event keywith this value.o stopped: Must be sent to the tracker if the client is shutting downgracefully.o completed: Must be sent to thetracker when the downloadcompletes. However, must not besent if the download was already100% complete when the clientstarted. Presumably, this is toallow the tracker to increment the"completed downloads" metric basedsoley on this event.∙ip: Optional. The true IP address of the client machine, in dotted quad format or rfc3513 defined hexed IPv6 address. Notes: In general this parameter is notnecessary as the address of the client can be determined from the IP address fromwhich the HTTP request came. Theparameter is only needed in the case where the IP address that the request came in on is not the IP address of the client.This happens if the client iscommunicating to the tracker through aproxy (or a transparent web proxy/cache.) It also is necessary when both the client and the tracker are on the same local side of a NAT gateway. The reason for this is that otherwise the tracker would give out the internal (RFC1918) address of theclient, which is not routeable. Therefore the client must explicitly state its(external, routeable) IP address to begiven out to external peers. Varioustrackers treat this parameterdifferently. Some only honor it only ifthe IP address that the request came inon is in RFC1918 space. Others honor itunconditionally, while others ignore itcompletely. In case of IPv6 address (e.g.:2001:db8:1:2::100) it indicates onlythat client can communicate via IPv6.∙numwant: Optional. Number of peers thatthe client would like to receive from thetracker. This value is permitted to bezero. If omitted, typically defaults to50 peers.∙key: Optional. An additionalidentification that is not shared withany users. It is intended to allow aclient to prove their identity shouldtheir IP address change.∙trackerid: Optional. If a previousannounce contained a tracker id, itshould be set here.Tracker ResponseThe tracker responds with "text/plain" document consisting of a bencoded dictionary with the following keys:∙failure reason: If present, then no otherkeys may be present. The value is ahuman-readable error message as to whythe request failed (string).∙warning message: (new, optional) Similarto failure reason, but the response stillgets processed normally. The warningmessage is shown just like an error.∙interval: Interval in seconds that theclient should wait between sendingregular requests to the tracker∙min interval: (optional) Minimumannounce interval. If present clientsmust not reannounce more frequently thanthis.∙tracker id: A string that the clientshould send back on its nextannouncements. If absent and a previousannounce sent a tracker id, do not discardthe old value; keep using it.∙complete: number of peers with the entirefile, i.e. seeders (integer)∙incomplete: number of non-seeder peers,aka "leechers" (integer)∙peers: (dictionary model) The value is alist of dictionaries, each with thefollowing keys:o peer id: peer's self-selected ID, asdescribed above for the trackerrequest (string)o ip: peer's IP address either IPv6(hexed) or IPv4 (dotted quad) orDNS name (string)o port: peer's port number (integer)∙peers: (binary model) Instead of usingthe dictionary model described above, thepeers value may be a string consisting ofmultiples of 6 bytes. First 4 bytes arethe IP address and last 2 bytes are theport number. All in network (big endian)notation.As mentioned above, the list of peers is length 50 by default. If there are fewer peers in the torrent, then the list will be smaller. Otherwise, the tracker randomly selects peers to include in the response. The tracker may choose to implement a more intelligent mechanism for peer selection when responding to a request. For instance, reporting seeds to other seeders could be avoided.Clients may send a request to the tracker more often than the specified interval, if an event occurs (i.e. stopped or completed) or if the client needs to learn about more peers. However, it is considered bad practice to "hammer" on a tracker to get multiple peers. If a client wants a large peer list in the response, then it should specify the numwant parameter.Implementer's Note: Even 30 peers is plenty, the official client version 3 in fact only actively forms new connections if it has less than 30 peers and will refuse connections if it has 55. This value is important to performance. When a new piece has completed download, HAVE messages (see below) will need to be sent to most active peers. As a result the cost of broadcast traffic grows in direct proportion to the number of peers. Above 25, new peers are highly unlikely to increase download speed. UIdesigners are strongly advised to make this obscure and hard to change as it is very rare to be useful to do so.Tracker 'scrape' ConventionBy convention most trackers support another form of request, which queries the state of a given torrent (or all torrents) that the tracker is managing. This is referred to as the "scrape page" because it automates the otherwise tedious process of "screen scraping" the tracker's stats page.The scrape URL is also a HTTP GET method, similar to the one described above. However the base URL is different. To derive the scrape URL use the following steps: Begin with the announce URL. Find the last '/' in it. If the text immediately following that '/' isn't 'announce' it will be taken as a sign that that tracker doesn't support the scrape convention. If it does, substitute 'scrape' for 'announce' to find the scrape page.Examples: (announce URL -> scrape URL)~/announce -> ~/scrape ~/x/announce ->~/x/scrape~/announce.php ->~/scrape.php~/a -> (scrape not supported)~/announce?x2%0644 ->~/scrape?x2%0644~/announce?x=2/4 -> (scrape not supported)~/x%064announce -> (scrape not supported)Note especially that entity unquoting is not to be done. This standard is documented by Bram in the BitTorrent development list archive: /group/BitTorrent/message/3275The scrape URL may be supplemented by the optional parameter info_hash, a 20-byte value as described above. This restricts the tracker's report to that particular torrent. Otherwise stats for all torrents that the tracker is managing are returned. Software authors are strongly encouraged to use the info_hash parameter when at all possible, to reduce the load and bandwidth of the tracker.You may also specify multiple info_hash parameters to trackers that support it. While this isn't part of the official specifications it has become somewhat a defacto standard - for example:/scrape.php?info_hash=aaaaaaaaaaaaaaaaaaaa&info_hash=bbbbbbbbbbbbbbbbbbbb&info_hash=ccccccccccccccccccccThe response of this HTTP GET method is a "text/plain" or sometimes gzip compressed document consisting of a bencoded dictionary, containing the following keys:files: a dictionary containing onekey/value pair for each torrent for whichthere are stats. If info_hash wassupplied and was valid, this dictionarywill contain a single key/value. Each keyconsists of a 20-byte binary info_hash.The value of each entry is anotherdictionary containing the following:o complete: number of peers with theentire file, i.e. seeders(integer)o downloaded: total number of timesthe tracker has registered acompletion ("event=complete", i.e.a client finished downloading thetorrent)o incomplete: number of non-seederpeers, aka "leechers" (integer)o name: (optional) the torrent'sinternal name, as specified by the"name" file in the info section ofthe .torrent fileNote that this response has three levels of dictionary nesting. Here's an example:d5:files d20:....................d8:complete i5e10:downloaded i50e10:inc omplete i10eeeeWhere .................... is the 20 byte info_hash and there are 5 seeders, 10 leechers, and 50 complete downloads.Unofficial extensions to scrapeBelow are the response keys are being unofficially used. Since they are unofficial, they are all optional.∙failure reason: Human-readable errormessage as to why the request failed(string). Clients known to handle thiskey: Azureus.∙flags: a dictionary containingmiscellaneous flags. The value of theflags key is another nested dictionary,possibly containing the following:o min_request_interval: The value forthis key is an integer specifyinghow the minimum number of secondsfor the client to wait beforescraping the tracker again.Trackers known to send this key:BNBT. Clients known to handle thiskey: Azureus.Peer wire protocol (TCP)OverviewThe peer protocol facilitates the exchange of pieces as described in the 'metainfo file.Note here that the original specification also used the term "piece" when describing the peer protocol, but as a different term than "piece" in the metainfo file. For that reason, the term "block" will be used in this specification to describe the data that is exchanged between peers over the wire.A client must maintain state information for each connection that it has with a remote peer:∙choked: Whether or not the remote peer haschoked this client. When a peer chokes theclient, it is a notification that norequests will be answered until theclient is unchoked. The client should notattempt to send requests for blocks, andit should consider all pending(unanswered) requests to be discarded bythe remote peer.∙interested: Whether or not the remotepeer is interested in something thisclient has to offer. This is anotification that the remote peer willbegin requesting blocks when the clientunchokes them.Note that this also implies that the client will also need to keep track of whether or not it is interested in the remote peer, and if it has the remote peer choked or unchoked. So, the real list looks something like this:∙am_choking: this client is choking thepeer∙am_interested: this client is interestedin the peer∙peer_choking: peer is choking this client∙peer_interested: peer is interested inthis clientClient connections start out as "choked" and "not interested". In other words:∙am_choking = 1∙am_interested = 0∙peer_choking = 1∙peer_interested = 0A block is downloaded by the client when the client is interested in a peer, and that peer is not choking the client. A block is uploaded by a client when the client is not choking a peer, and that peer is interested in the client.It is important for the client to keep its peers informed as to whether or not it is interested in them. This state information should be kept up-to-date with each peer even when the client is choked. This will allow peers to know if the client will begin downloading when it is unchoked (and vice-versa).Data TypesUnless specified otherwise, all integers in the peer wire protocol are encoded as four byte big-endian values. This includes the length prefix on all messages that come after the handshake.。

相关文档
最新文档