You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Torrent客户端向节点请求时,收到的Piece长度不足9字节的原因

BitTorrent Piece请求与响应问题

发送的Piece请求

b'\x00\x00\x00\r\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'

收到的响应

b'\x00\x00\x00\x00\x00\x00\x00\x00R'

Piece消息规范定义

piece: <len=0009+X><id=7>
Piece消息为可变长度,其中X为block的长度。负载包含以下信息:
index:指定从零开始的Piece索引的整数
begin:指定Piece内从零开始的字节偏移量的整数
block:数据块,是index指定的Piece的子集。

我的Piece消息处理逻辑

elif message_id == 7:
    if len(payload) >= 9:
        piece_index, begin = struct.unpack('!II', payload[:8])
        block = payload[8:]

        if piece_index not in self.received_pieces:
            self.received_pieces[piece_index] = {}

        self.received_pieces[piece_index][begin] = block

我已尝试调整消息处理方式,但因完全未收到有效数据,暂无更多可行操作。若需要更多信息请告知。

内容的提问来源于stack exchange,提问作者user26753351

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:14:52