0

ピアリストを取得し、ピアへのtcp接続を確立したところ、メッセージをハンドシェイクしようとしましたが、応答しないようです。

これはコードでの私のメッセージです:

message = bytes(chr(19))+"BitTorrent protocol00000000"+self.getInfoHash(torrentCont)+self.peer_id

self.getInfoHash(torrentCont)は、トレントファイルからの生のハッシュです。

これは私が送信している実際のものです:

BitTorrent protocol00000000ŒïƒœÝtDØ´öÙÄ×àŠD³T4F11T6ZGBQK2Y5LB8I4

私が間違っていることについて何か提案はありますか?

4

1 に答える 1

5

あなたはバイトと文字を混乱させています。仕様によると、文字「0」(chr(48))の8倍ではなく、8つのnullバイトを送信する必要があります。

message = (chr(19) +
           "BitTorrent protocol" +
           8 * chr(0) +               # <--- here
           self.getInfoHash(torrentCont) +
           self.peer_id)

# in case of doubt...
assert len(self.getInfoHash(torrentCont)) == 20
assert len(self.peer_id) == 20
于 2012-12-10T00:31:22.620 に答える