Members   Search      Help    Register    Login    Home
Home » Support Forums for PMBT 1.X » Bug Reports » private torrents and azureus,deluge,etc...
private torrents and azureus,deluge,etc... [message #1996] Tue, 06 May 2008 20:19 Go to next message
Revan is currently offline Revan  Czech Republic
Messages: 125
Registered: April 2007
Super-Seeder
I already talked this through with Joe, but I'll post it here as well.

When uploading a torrent which then gets changed into private one lots of clients like Azureus, Deluge, BitTyrant and some others as well don't hash it correctly.
Solution is fairly easy - you need to place a private flag as the last thing in torrent. So to fix upload script just replace this line in upload/taketorrent.php:
$info->insert_before($private,$child);

and put this instead of it:
$info->append_child($private);


I also did a script which will fix already existing torrents, just save this as something .php and then open it once, it will open all torrents and change the position of the private flag in torrent (if it was there in the first place)
<?php
include ("header.php");
require_once("include/bdecoder.php");
require_once("include/bencoder.php");

$sql6 = "SELECT id FROM ".$db_prefix."_torrents";
$res6 = $db->sql_query($sql6);
while ($row6 = $db->sql_fetchrow($res6))
{
  $id = $row6["id"];
  $tmpname = $torrent_dir."/".$id.".torrent";
  $pagetorrent = "";
  $fp = @fopen($tmpname,"rb");
  while (!@feof($fp)) {
          $pagetorrent .= @fread($fp,1000);
  }
  @fclose($fp);

  $torrent = Bdecode($pagetorrent);
  unset($pagetorrent);
  $info = entry_get($torrent,"info");
  
  $priv_exists = entry_exists($torrent,"info/private(Integer)");
  if ($priv_exists)
  {
    $private = entry_get($torrent,"info/private");
    $info->remove_child($private);
    
    $private = $torrent->create_element("private");
    $private->set_attribute("type","Integer");
    $enable = $torrent->create_text_node("1");
    $private->append_child($enable);
    $info->append_child($private);
  }
  
  $infohash_hex = sha1(Benc($info));
  $infohash = pack("H*", $infohash_hex);
  unset($info);
  
  $torrentsql = "UPDATE ".$db_prefix."_torrents SET info_hash = '".addslashes($infohash)."' WHERE id = '".$id."';";
  $db->sql_query($torrentsql) or btsqlerror($torrentsql);
  
  
  
  $torrentpath = $torrent_dir."/".$id.".torrent";
  if (file_exists($torrentpath)) unlink($torrentpath);
  
  $fp = fopen($torrentpath,"wb");
  fwrite($fp,Bencode($torrent));
  fclose($fp);
}
include("footer.php");
?>

Careful, this script opens, decodes, encodes, saves and runs one sql query for every torrent!!! So don't run it if you don't really need it!!!
It's not really perfect, concerning the load it puts on server (opens and rehashes all torrents not just those that need it), but it does the job done...
Re: private torrents and azureus,deluge,etc... [message #2030 is a reply to message #1996] Tue, 13 May 2008 00:43 Go to previous messageGo to next message
lodp is currently offline lodp  Austria
Messages: 336
Registered: June 2006
Releaser
O-K, i don't know the code well enough here again -- can you put this into CVS, joe?
Re: private torrents and azureus,deluge,etc... [message #2045 is a reply to message #2030] Sat, 17 May 2008 20:36 Go to previous messageGo to next message
Revan is currently offline Revan  Czech Republic
Messages: 125
Registered: April 2007
Super-Seeder
lodp wrote on Mon, 12 May 2008 16:43

O-K, i don't know the code well enough here again -- can you put this into CVS, joe?

I maybe wrote it little bit confusing sorry about that.
The script isn't needed at all - it just changes all existing torrents which were already uploaded (for people who would like to make their already existing private torrents azureus compatible).

The only thing that is needed to change is line 242 in taketorrent.php (at least it is line 242 in taketorrent.php with revision 1.49 in cvs), the line is $info->insert_before($private,$child);

and you just replace it with $info->append_child($private);

That should be all Smile
Re: private torrents and azureus,deluge,etc... [message #2046 is a reply to message #1996] Sat, 17 May 2008 20:59 Go to previous messageGo to next message
lodp is currently offline lodp  Austria
Messages: 336
Registered: June 2006
Releaser
yeah, i got that about only taketorrent.php needing modification .. but i didn't feel confident about the change, that's why i was asking the big man to do it Smile
Re: private torrents and azureus,deluge,etc... [message #2048 is a reply to message #1996] Sat, 17 May 2008 22:09 Go to previous messageGo to next message
Revan is currently offline Revan  Czech Republic
Messages: 125
Registered: April 2007
Super-Seeder
sure Smile
i was just worried that i wrote it way too complicated
Re: private torrents and azureus,deluge,etc... [message #2400 is a reply to message #2048] Fri, 27 February 2009 06:50 Go to previous messageGo to next message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
this has been added to base code!

http://a.imageshack.us/img831/5562/mybikes.png
Re: private torrents and azureus,deluge,etc... [message #2457 is a reply to message #2400] Thu, 19 March 2009 08:37 Go to previous message
Revan is currently offline Revan  Czech Republic
Messages: 125
Registered: April 2007
Super-Seeder
great! thanks Smile
Previous Topic:[FIX]_remove the bug who add ;; ;; caracters in posts
Next Topic:Can't login
Goto Forum:
  


Current Time: Wed Feb 08 12:13:41 GMT 2012

Total time taken to generate the page: 0.00782 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software