| private torrents and azureus,deluge,etc... [message #1996] |
Tue, 06 May 2008 20:19  |
Revan  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...
|
|
|
|
|
|
|
|
|