Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.0

Bug #3970 Problems with decoding
Submitted: 2005-03-27 14:30 UTC
From: gaggge at gmail dot com Assigned: tacker
Status: Closed Package: File_Bittorrent
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-03-27 14:30 UTC] gaggge at gmail dot com
Description: ------------ I'm having some problems with decoding a torrent and generating an info_hash. (You can get the info_hash like this: pack("H*", sha1($info)) where $info is the bencoded info key) First i decode a torrent to $torrent, then encode $torrent['info'], now the 'length' key should be an integer, but it's a string, however that's not a problem, can be fixed easily with settype(). A bigger problem is that the length of 'pieces' always is incorrect. Maybe you could do an info_hash function? Again, pack("H*", sha1($torrent['info'])) to get the info_hash Reproduce code: --------------- <?php require("decode.php"); require("encode.php"); $bdecode = new File_Bittorrent_Decode; $bencode = new File_Bittorrent_Encode; $torrent = $bdecode->decodeFile("file.torrent"); $info = $bencode->encode($torrent['info']); $infohash = pack("H*", sha1($info)); ?> Expected result: ---------------- 'length' in 'files' should be int, is string strlen of 'pieces' is incorrect

Comments

 [2005-03-27 14:33 UTC] gaggge at gmail dot com
A little note: 'piece length' should be an int too.
 [2005-03-27 14:57 UTC] tacker
Thanks for the report. I've had problems on my own creating the info_hash. Your example is correct by definition but I didn't manage to create a working one, i.e. for querying a tracker what is supposed to be an essential part of this package. According to the bittorrent definition the info_hash is just "The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file.". I tried it with several torrents but the create hash was not recognized by the tracker. So I would apreciate a working info_hash example with a .torrent file and tracker, if you can provide one. This feature is really high on my wishlist as it is essential for queriying trackers and scrape pages. Any help would be great.
 [2005-03-27 17:13 UTC] gaggge at gmail dot com
I think the problem is that strlen doesn't work correct on the pieces stuff, I've made a working but pretty nasty function for getting the info_hash, I'm not sure if it works all the time, it depends on the number of e's at the end of the torrent. <?php $filesrc = @file_get_contents("file.torrent"); $start = @strpos($filesrc, 'd5:files'); $match = @substr($filesrc, $start, (@strlen($filesrc)-$start-1)); $file_info['info_hash'] = @urlencode(@pack("H*", sha1($match))); ?> It generates the hash for the text between d5:files and the second last e in the torrent. 4:info -> d5:files ... e <- e Try doing a strlen on the info key and you'll see that it probably returns a different value than what's in the torrent. Hope you manage to get this working, i'll try myself to do a 100% working solution. Sorry for my bad english :-)
 [2005-03-27 22:14 UTC] gaggge at gmail dot com
Maybe I should add some stuff, don't query a tracker with a info_hash in the query string through your browser if that's what you've been trying, won't work for me. Build a torrent, BitComet works fine, and set the announce url to whatever.php. Add file_put_contents(print_r($_GET, true)); (or something like that) to whatever.php. (Will get bad data from tracker, don't mind that) Check if you can get the same info_hash with your script as your client sends to the announce url.
 [2005-06-20 12:04 UTC] tacker
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. I have fixed the integer decoding. Please submit a new feature request for the info_hash.
 [2005-06-20 21:10 UTC] tacker
About the info_hash stuff: Please checkout http://m.tacker.org/projects/File_Bittorrent/trunk/infohash.phps See these results: $ php infohash.php -t freebsd.torrent Info Hash ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This: 0791235cefbd8bd48e5b2993383e13148d5ac06b btshowmetainfo: 631a927ff9408c13f433e9abadf1263fce809864 gagge: da8941a450a75e7b8861d9266ecf8f9c7a94d277 Wierd.