【问题标题】:BitTorrent protocol implementation: Not receiving "Piece" messagesBitTorrent 协议实现:未收到“Piece”消息
【发布时间】:2013-02-03 01:44:31
【问题描述】:

我已经用 Java 实现了大部分 BitTorrent 协议。问题是,由于某种原因,没有一个同行向我发送我要求的任何作品。 (3小时后我只收到2条消息)

我的握手如下:

send 19
send "BitTorrent protocol"
send 8 zero'd reserved bytes
send info_hash (20 bytes)
send peer_id (20 bytes)

read 19
read "BitTorrent protocol"
read 8 reserved bytes
read info_hash. Compare with own info_hash
read peer_id

send unchoke

start listening for messages

我在另一个线程中监听消息如下:

while(true)
    read length (4 bytes)
    read id (1 byte)
    if length == 0: continue //keep-alive message
    if id == 1: Stop all requests to this peer
    if id == 2: Continue all requests to this peer
    if id == 4: Read index from have-message and request piece if we don't have it
    if id == 5: If we have not already received bitfield. Read and store it. Request any pieces that we don't have yet
    if id == 7: Read index, begin and length. Read and store piece. Send have-message if a piece was fully downloaded

您能看出这种方法有什么问题吗?我尝试过每分钟定期发送保持活动消息,但这无济于事。奇怪的是,我收到了大量的位域消息并保持 30 多个活动连接。

【问题讨论】:

    标签: protocols bittorrent


    【解决方案1】:

    这个答案很晚,但我已经链接到它,所以也许这仍然有用。

    我认为你的身份混淆了。 0 是“阻塞”,1 是“不阻塞”(不是 1 和 2)。此外,您可能还需要确保您在不被阻塞时触发请求,以防在此之前收到“有”消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多