Question

From i got the peerlist and i get up a tcp connection to peer, i tries to a handshake message to them, but they dont seem to respond.

This is my message in code:

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

self.getInfoHash(torrentCont) is the raw hash from the torrent file

this is actual what i am sending out:

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

any suggestion on what I am doing wrong?

Was it helpful?

Solution

You are confusing bytes and characters. What the specification says is that you should send eight null bytes, not eight times the character "0" (which is chr(48)):

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top