失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 学习笔记——torrent文件解析

学习笔记——torrent文件解析

时间:2021-10-03 16:48:08

相关推荐

学习笔记——torrent文件解析

bencoding编码

B编码有4种类型,分别为:

字符串:<字符串长度>:<字符串>,如announce,编码后为8:announce;

整型:i<十进制整型数>e,如9,编码后为i9e;

列表:l<任何合法类型>e;

字典:d<关键字><值>e,其中,关键字是一个经过B编码的字符串,值可以是任何合法的B编码类型。

torrent文件结构

announce:Tracker的主服务器

announce-list:Tracker服务器列表

comment:种子文件的注释

comment.utf-8:种子文件注释的utf-8编码

creation date:种子文件建立的时间,是从1970年1月1日00:00:00到现在的秒数。

encoding:种子文件的默认编码,比如GB2312,Big5,utf-8等

info:所有关于下载的文件的信息都在这个字段里,它包括多个子字段,而且根据下载的是单个文件还是多个文件,子字段的项目会不同,具体介绍在后面。

nodes:最后的一个字段是nodes字段,这个字段包含一系列ip和相应端口的列表,是用于连接DHT初始node。

多文件torrent结构树形图:

Multi-file Torrent

├─announce

├─announce-list

├─comment

├─comment.utf-8

├─creation date

├─encoding

├─info

│ ├─files

│ │ ├─length

│ │ ├─path

│ │ └─path.utf-8

│ ├─name

│ ├─name.utf-8

│ ├─piece length

│ ├─pieces

│ ├─publisher

│ ├─publisher-url

│ ├─publisher-url.utf-8

│ └─publisher.utf-8

└─nodes

单文件结构树形图:

Single-File Torrent

├─announce

├─announce-list

├─comment

├─comment.utf-8

├─creation date

├─encoding

├─info

│ ├─length

│ ├─name

│ ├─name.utf-8

│ ├─piece length

│ ├─pieces

│ ├─publisher

│ ├─publisher-url

│ ├─publisher-url.utf-8

│ └─publisher.utf-8

└─nodes

区别在于multi-file的info字段内包括files字段,其中:

lenghth:文件的大小,用byte计算;

path:文件的名字,在下载时不可更改;

path.utf-8:文件名的UTF-8编码。

info中其他字段含义如下:

name:推荐的文件夹名,此项可于下载时更改;

name.utf-8:推荐的文件夹名的utf-8编码;

piece length:每个文件块的大小,用Byte计算;

publisher:文件发布者的名字;

publisher.utf-8:文件发布者的名字的utf-8编码;

publisher-url:文件发布者的网址;

publisher-url.utf-8:文件发布者网址的utf-8编码。

注:

info_hash的计算从info字段开始(不包括info)到nodes字段前(包括nodes);

编辑器打开torrent文件,pieces字段的SHA1杂凑值乱码(暂有疑问);

参考:

Torrent文件结构解析

BEncode编码方式以及torrent文件的一些内容

Torrent 文件图文解析

torrent文件编码

如果觉得《学习笔记——torrent文件解析》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。