【发布时间】: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