Skip to content

Instantly share code, notes, and snippets.

@clarkf
Created February 5, 2012 19:44
Show Gist options
  • Save clarkf/1747668 to your computer and use it in GitHub Desktop.
Save clarkf/1747668 to your computer and use it in GitHub Desktop.
//I copied the hash value exactly from a tracker -- this is a hex
//representation of the sha1sum of the info dictionary
var bigint = require('bigint'),
hash = new Buffer('8ac3731ad4b039c05393b5404afa6e7397810b41', 'hex'),
connection_id = new bigint('4497486125440'),
buffer = new Buffer(36);
/* ( http://www.bittorrent.org/beps/bep_0015.html )
All values are send [sic] in network byte order (big endian).
...
scrape request (according to the BitTorrent BEP)
Offset Size Name Value
0 64-bit integer connection_id
8 32-bit integer action 2 // scrape
12 32-bit integer transaction_id
16 + 20 * n 20-byte string info_hash
16 + 20 * N
*/
console.log(hash.length); // = 20
connection_id = connection_id.toBuffer({
endian: 'big',
size: 8
});
connection_id.copy(buffer, 0, 8);
buffer.writeInt32BE(2 , 8);
buffer.writeInt32BE(12345 , 12);
hash.copy(buffer, 16, 0 , 20);
//[Connect and transmit the message]
//The problem here is that no matter the tracker, no matter the torrent,
//no matter the hash, I always end up getting a response that's telling
//me that nobody's available for that torrent, which I know is false,
//since I've opened the torrent up through Transmission and verified
//that it's scraping at least some peers from the UDP tracker. What's
//the deal?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment