1

BitTorrent プロトコルのほとんどを Java で実装しました。問題は、なんらかの理由で、どのピアも私が要求したピースを私に送信していないことです。(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 以上のアクティブな接続を維持していることです。

4

1 に答える 1

3

この回答はかなり遅れていますが、私はそれにリンクしているので、これはまだ役立つかもしれません.

IDが混じっていると思います。0 は「チョーク」、1 は「チョーク解除」です (1 と 2 ではありません)。また、その前に「have」メッセージが表示された場合に備えて、チョークが解除されたときにもリクエストをトリガーしていることを確認する必要がある場合があります。

于 2013-05-10T21:35:00.763 に答える