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?

Était-ce utile?

La 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top