chewmieser Posted April 7, 2009 Share Posted April 7, 2009 I'm fiddling around with the bittorrent protocol as a mere proof-of-concept and I'm stuck at a certain point. See, when you request peers to connect to with bittorrent, the tracker returns a "compact format" which consists of a large string of ips and ports. The IP is stored as 4 bytes and the port as 2. Basically i would need to break this string (it's needs to utilize multibyte functions) up by 6 bytes and then break it up into it's ip and port to use this information, but so far I'm not having any luck. Any ideas? I know I'm missing something here, but I can't seem to figure out just how to break up a string by bytes in php... I also threw together (haven't optimized the code, or made sure it worked properly) a quick function to convert the 32-bit ip address it returns into a real IP address I can use: function dec2dot($dec){ $bin=decbin($dec); while (strlen($bin)<32){$bin="0".$bin;} $chunks=chunk_split($bin,8,"|"); $chunksA=explode("|",$chunks); $final="";$first=true; foreach ($chunksA as $dd){ if ($dd!=""){ if ($first){$final=bindec($dd);$first=false;} else{$final.=".".bindec($dd);} } } return $final; } Again, It's not optimized, but it seems to do the trick... Thanks in advance for any help, and if you need more information just ask. The official specification for the compact lists is located here: http://www.bittorrent.org/beps/bep_0023.html Quote Link to comment https://forums.phpfreaks.com/topic/153051-solved-working-with-bytes-in-php/ Share on other sites More sharing options...
laffin Posted April 7, 2009 Share Posted April 7, 2009 U may learn a lot more if u already look at some php tracker projects. As they have to generate those compact codes, it's just a prime learning spot. I started learning php programming from one of them php trackers. The biggest support forum for a php tracker is for TBDev torrent trackers. TBDev Portal Just sign up, look around, and download the code. The code you will be interested in is in announce.php Good luck Quote Link to comment https://forums.phpfreaks.com/topic/153051-solved-working-with-bytes-in-php/#findComment-803845 Share on other sites More sharing options...
chewmieser Posted April 7, 2009 Author Share Posted April 7, 2009 You know it crossed my mind, but I never actually did it. Thanks for pointing out the file, I'll download it when I locate where I can download it (the site isn't working I guess). Edit: Hmm... That tracker doesn't support the compact format, which would have made it easy for me to obtain the info from them, but most popular trackers ONLY support compact. Quote Link to comment https://forums.phpfreaks.com/topic/153051-solved-working-with-bytes-in-php/#findComment-803850 Share on other sites More sharing options...
laffin Posted April 7, 2009 Share Posted April 7, 2009 Originally TBDev 06 Didnt have compact support TB, TB INST, and XTBDev Do have compact mode support. U can browse the svn on sourceforge TBDev.net Sourforge SVN Quote Link to comment https://forums.phpfreaks.com/topic/153051-solved-working-with-bytes-in-php/#findComment-803863 Share on other sites More sharing options...
chewmieser Posted April 7, 2009 Author Share Posted April 7, 2009 Thanks alot! I found another tracker, and I found out how to unpack the data. Now I support all I need to do is break it apart by 6 chrs, but I'll figure that out. I would call this solved for now at least, I can always bug later if I need more help =). Thanks again laffin. Quote Link to comment https://forums.phpfreaks.com/topic/153051-solved-working-with-bytes-in-php/#findComment-803884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.