Correct way to determine the number of pieces in a torrent?
2011-10-01 17:46:31 GMT
I'm working on a BitTorrent implementation (https://github.com/robertseaton/slug) and right now I just have a naive piece scheduler that downloads each piece in order. Anyways, everything works fine until I finish downloading the first 1368 pieces out of 1371 pieces. Once I finish downloading piece #1367, suddenly, every seed sends me a choke message.
My thought is that maybe I've somehow incorrectly calculated the number of pieces from the torrent metadata and that piece #1367 is actually the last piece. Currently, to determine the number of pieces, I'm taking the length of the "pieces:" string from the .torrent, which is 27420, and then dividing by the length of the SHA1 hash (20), since I assume there is a 1:1 mapping between pieces and SHA1 hashes.
Is this the correct way to determine the number of pieces in a torrent? If so, what else would explain the behavior that I'm seeing?
_______________________________________________ BitTorrent mailing list BitTorrent <at> lists.ibiblio.org http://lists.ibiblio.org/mailman/listinfo/bittorrent