gpt4 book ai didi

bittorrent - 围绕 Bitfield Torrent 的困惑

转载 作者:行者123 更新时间:2023-12-04 02:04:51 24 4
gpt4 key购买 nike

我对 bittorrent 中的位域消息有点困惑.我注意到下面问题形式的困惑。

  1. 可选与必需

Bitfield to be sent immediately after the handshaking sequence is completed

我假设这是强制性的,即在握手之后必须跟随一个位域消息。正确吗?

  1. 什么时候需要位域?

The bitfield message may only be sent immediately after the handshaking sequence is completed, and before any other messages are sent

假设我清楚地阅读了这条消息,尽管它是可选消息。 peer 仍然可以在任何消息之前广播位域消息(如请求、choke、uncoke 等)。对吗?

  1. 第一个字节的高位对应片索引0

如果我是正确的,位域代表状态,即对等方是否有给定的部分。

假设我的位域是 [1,1,1,1,1,1,1,1,1,1 ..]。我确定了一个事实,即对等方缺少第 10 block ,如果位域看起来像这样 [1,1,0,1,1,1,1,1,1,1 ..] 对等方缺少第 3 件。那么第一个字节的高位对应 block 索引0是什么意思。

  1. 备用位

Spare bits at the end are set to zero

这是什么意思?我的意思是,如果末尾有一点为 0,这并不意味着同行将其视为缺失的部分。为什么要使用备用位。

  1. 最重要的是位域的用途。

我对此的直觉是,位域可以更轻松地为一个知道对等点可用的片段找到合适的对等点,但我对此是否正确?

@Encombe

这里是我的位域负载的样子

\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE

最佳答案

I'm assuming this is compulsory i.e after handshake there must follow a bitfield message. Correct?

不,位域消息是可选的,但如果客户端发送它,它必须是握手后的第一条消息。

此外,在任何一方开始发送任何类型的常规消息(包括位域消息)之前,双方都必须发送完整的握手(即握手序列已完成)。

assuming I read this clear although be optional message. peer can still broadcast the bitfield message prior to any message (like request, choke, uncoke etc). correct ?

是的,见上文。如果客户端向其他任何地方发送位域消息,则必须关闭连接。

Assuming that my bitfield is [1,1,1,1,1,1,1,1,1,1 ..]. I establish the fact that the peer has 10th piece missing

没有。我不清楚您的数字是位 (0b1111111111) 还是字节 (0x01010101010101010101)。

如果是位(0b11111111): 表示有0到9个

如果是bytes(0x01010101010101010101):表示有第7、15、23、31、39、47、55、63、71、79 block

if the bitfield look like this [1,1,0,1,1,1,1,1,1,1 ..] the peer has a 3rd piece missing.

不,片段是零索引的。 0b1101111111:表示第 2 block 缺失。

Then what is the high bit in the first byte corresponds to piece index 0 means.

表示索引为0的片由最左边的位表示。 (bigendian 中的最高有效位。)
。八位 = 一个字节
。 0b10000000 = 0x80
。 ^ 高位设置意味着客户端有 block 0

。 0b00000001 = 0x01
。 ^ 低位设置意味着客户端有第 7 block

why is the spare bit used

如果torrent中的 block 数不能被8整除;在位域的最后一个字节中会有一些位,不代表任何部分。这些位必须设置为零。

可以这样计算位域的大小(以字节为单位):
size_bitfield = math.ceil(number_of_pieces/8)
备用位数为:
spare_bits = 8 * size_bitfield - number_of_pieces

what is the purpose of the bitfield

目的是告诉客户端有哪些片段,以便其他节点知道它可以请求哪些片段。

关于bittorrent - 围绕 Bitfield Torrent 的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44308457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com