图片来源:Easy Diffusion,参数 在 bittorrent 中, tracker 是组织或个人提供的一个中心化的服务,tracker 服务器 URL 包含在种子文件(.torrent)的 announce 或 announce-list 字段中,bittorrent 客户端通过 HTTP GET 请求向服务端发送本地信息,并从服务器获取其他客户端的信息。 Tracker 请求 以下是 HTTP GET 请求 URL 中的参数: 参数 必要 含义 info_hash 是 种子文件中 info 字段值(bencode编码的字典)的 SHA1 校验和(20字节),种子文件结构查看 这里 peer_id 是 20字节 ,用以识别客户端的唯一 ID,可以是任意值(可见字符或二进制数据),应当在客户端启动时生成 port 是 客户端监听端口号,通常是6881-6889(如果客户端无法在该端口范围内监听,应当主动放弃) event 否 值必须为 started、stopped 或 completed。客户端对 tracker 的第一次请求中应当包含 event=stared ;客户端正常关闭时应当向 tracker 发送 event=stopped ;客户端完成下载时应当向 tracker 发送 event=completed (不要重复发送 event=completed ,tracker 使用该信息统计完成的客户端数量) uploaded 是 使用 ASCII 码表示的十进制数字,表示 event=stared 发送后上传的字节数(官方没标单位,但通常为字节) downloaded 是 使用 ASCII 码表示的十进制数字,表示 event=stared 发送后下载的字节数(官方没标单位,但通常为字节) left 是 使用 ASCII 码表示的十进制数字,未下载的字节数 compact 是 值为 1 时,服务器响应使用更加紧凑的节点格式(6字节 IPv4 地址或 16字节 IPv6 地址,后2字节为端口,均使用网络序)。注意,官方建议 tracker 默认使用 compact 格式,并且该参数对 tracker 服务器来说只是个建议,即使发送 compact=0,tracker 服务器也可以忽略或拒绝响应 no_peer_id 否 指示服务器响应中的 peers 字典不必包含 peer id ,使用 compact=1 时自动忽略该选项 ip 否 客户端所在机器的真实 IP 地址,客户端通过代理与 tracker 服务器连接时需要该参数提供真实 […]
Monthly Archives: November 2023
图片来源:https://www.pixiv.net/artworks/113139569 整个 .torrent 文件实际上就是一个包含了约定字段的 bencode 编码字典, bencode 编码规则见 https://blog.geekgo.tech/programming/bencode/ 顶层字段 字段(含空格) 类型 必要 含义 info Dictionary 是 包含文件信息的字典,详细结构见下文 announce String 否 tracker 的 URL announce-list List 否 额外 tracker,列表的每个元素都是一个字符串列表,每个字符串都是一个 tracker 的 URL (另外官方文档里对这些 tracker 的处理顺序有一些要求,详情见 这里) creation date Integer 否 种子创建时间(Unix 时间戳) comment String 否 没有格式要求的文本备注 created by String 否 创建种子的程序名称和版本(实际也可以填任意其他内容) encoding String 否 未在官方文档中找到定义,似乎是字符串编码,值多为 UTF-8,但 The BitTorrent Protocol Specification 已经明确了 “All strings in a .torrent file that contains text must be UTF-8 encoded.”。这里 的解释是 “the string encoding format used to generate the pieces part of the info dictionary in the .torrent metafile ” httpseeds List 否 每个元素是一个 URL,通过在 URL 后添加参数可以直接从这些网站下载需要的 torrent 数据,详见 这里 info 字典结构 info 的结构分为单文件和多文件两种情况 单文件 字段(含空格) 类型 必要 含义 name String 是 文件名 length Integer 是 […]
图片来源:https://www.pixiv.net/artworks/103204899 类型 描述 bencode 原始值 String 以字符串长度为前缀,后跟冒号和字符串 4:spam spam Integer 以 i 为前缀,后跟十进制数字,以 e 为后缀 i3ei-3ei0e 3-30 List 以 l 为前缀,后跟使用 bencode 编码过的元素,以 e 为后缀 l4:spam4:eggse ['spam', 'eggs'] Dictionary 以 d 为前缀,后跟使用 bencode 编码过的元素,每两个元素为一组 key:value,以 e 为后缀( key 必须为 String 并按原始字符串的字典顺序排列) d3:cow3:moo4:spam4:eggse d4:spaml1:a1:bee {'cow': 'moo', 'spam': 'eggs'} {'spam': ['a', 'b']} 参考: