From 49b671f5234aa7bb31433477fe6f51e8af5ad133 Mon Sep 17 00:00:00 2001
From: Rom Walton
Date: Sat, 14 Nov 2015 22:49:04 -0500
Subject: [PATCH] Moved source code into a separate repo.
See: https://github.com/BOINC/boinc-bittorrent
---
html/bt/INSTALL | 25 ------
html/bt/README | 47 -----------
html/bt/announce.php | 100 ----------------------
html/bt/config.php.example | 81 ------------------
html/bt/database/bittorrent_files.sql | 9 --
html/bt/database/bittorrent_ipbans.sql | 5 --
html/bt/database/bittorrent_peers.sql | 13 ---
html/bt/filters/allfilesfilefilter.php | 16 ----
html/bt/filters/filefilter.php | 13 ---
html/bt/inc/bdictionary.php | 53 ------------
html/bt/inc/belement.php | 29 -------
html/bt/inc/binteger.php | 35 --------
html/bt/inc/blist.php | 102 -----------------------
html/bt/inc/bstring.php | 36 --------
html/bt/inc/checks.php | 31 -------
html/bt/inc/illegalargumentexception.php | 9 --
html/bt/inc/torrent.php | 89 --------------------
html/bt/index.php | 78 -----------------
html/bt/scrape.php | 47 -----------
html/bt/torrent_cache.php | 71 ----------------
20 files changed, 889 deletions(-)
delete mode 100644 html/bt/INSTALL
delete mode 100644 html/bt/README
delete mode 100644 html/bt/announce.php
delete mode 100644 html/bt/config.php.example
delete mode 100644 html/bt/database/bittorrent_files.sql
delete mode 100644 html/bt/database/bittorrent_ipbans.sql
delete mode 100644 html/bt/database/bittorrent_peers.sql
delete mode 100644 html/bt/filters/allfilesfilefilter.php
delete mode 100644 html/bt/filters/filefilter.php
delete mode 100644 html/bt/inc/bdictionary.php
delete mode 100644 html/bt/inc/belement.php
delete mode 100644 html/bt/inc/binteger.php
delete mode 100644 html/bt/inc/blist.php
delete mode 100644 html/bt/inc/bstring.php
delete mode 100644 html/bt/inc/checks.php
delete mode 100644 html/bt/inc/illegalargumentexception.php
delete mode 100644 html/bt/inc/torrent.php
delete mode 100644 html/bt/index.php
delete mode 100644 html/bt/scrape.php
delete mode 100644 html/bt/torrent_cache.php
diff --git a/html/bt/INSTALL b/html/bt/INSTALL
deleted file mode 100644
index 6d3db1147c..0000000000
--- a/html/bt/INSTALL
+++ /dev/null
@@ -1,25 +0,0 @@
------------------
-Setting it all up
------------------
-The .torrent cache will need to know where to look for the files that are going
-to be sent to the clients. Usually this will be the project download directory.
-
-
-
-Also, you need to run the database scripts in the /database/-directory in order
-to set up your database for bittorrent tracking.
-
-------------------
-How to enable this
-------------------
-By default Bittorrent support is turned off on both server and client. You must
-enable bittorrent in your server configuration files by doing this:
-
-
-
-You must also convince your users that enabling Bittorrent support on their clients
-is a useful way to help the project. It is a good idea to let them know that
-setting the "Maximum upload rate" under general preferences enables them to
-control just how much of their outgoing bandwidth is ever used. A setting of 70%
-or less of their actual bandwidth is recommended to avoid creating latency issues
-on their connection.
diff --git a/html/bt/README b/html/bt/README
deleted file mode 100644
index 3d49a4d1e3..0000000000
--- a/html/bt/README
+++ /dev/null
@@ -1,47 +0,0 @@
-NOTE: THE CODE IN THIS DIRECTORY DOESN'T CURRENTLY WORK,
-AND IS NOT BEING MAINTAINED.
-IT'S HERE IN CASE SOMEONE WANTS TO REVIVE IT.
-
------------------------------------
-Bittorrent file distribution system
------------------------------------
-When several workunits require the same file (for instance any particularly big
-application file) it is really a waste to use a central server to distribute this
-file. First of all a central server requires lots of bandwidth - which may be
-quite expensive. Secondly getting 10'000 requests for the same multi-megabyte
-file may be too much for even the largest of servers.
-
-The solution is to harness the power of peer-to-peer computing in the domain of
-volunteer and desktop grid computing by allowing the clients to share pieces of the
-files they are downloading.
-
-How it works
-------------
-Since noone can be trusted, "Bob" (a client) will need some way of knowing if "Eve"
-(another client) sent him a valid piece of the original file. To enable him to do
-so Bob has downloaded a .torrent from the project servers. The .torrent describes
-the file he is downloading; it contains hash values for each piece so that he can
-check whether "Eve" is trying to cheat him.
-
-If "Alice" also wants to download the same file as "Bob" they can each fetch a
-different piece from the project servers and then share the pieces. Seen from
-"Bob" and "Alice"'s perspective this potentially doubles the download rate (if you
-see it from the project perspective it cuts the required network bandwidth in half).
-As more people join the synergetic effect increases dramatically.
-
-Isn't Bittorrent illegal?
--------------------------
-Bittorrent is a protocol for sharing files across the internet. As such it cannot
-be illegal in itself - it is what you do with it that matters.
-If you take a look at all the filesharing protocols out there Bittorrent seems to
-be the one that has been taken into widespread use in the whitehat part of the
-internet. Several major companies, including the movie industry, have adopted the
-technology because of its unique ability to distribute load. To name a few uses:
-- Bittorrent.com (Works with the movie industry, sells movies and shows)
-- Blizzard Entertainment (Uses BT to distribute data patches for their World of
- Warcraft game)
-- EletricSheep screensaver (Uses BT to distribute computed "dreams")
-
-How do I enable this?
----------------------
-Have a look at the INSTALL file located in the same directory as this file.
diff --git a/html/bt/announce.php b/html/bt/announce.php
deleted file mode 100644
index c01955ecd0..0000000000
--- a/html/bt/announce.php
+++ /dev/null
@@ -1,100 +0,0 @@
-$error));
- exit;
-}
-
-$info_hash = rawurldecode($_GET["info_hash"]);
-if (strlen($info_hash)!=20) throw new IllegalArgumentException("Malformed infohash key (length ".strlen($info_hash).")");
-$peer_id = $_GET["peer_id"];
-if (strlen($peer_id)!=20) throw new IllegalArgumentException("Malformed peer ID (".strlen($peer_id).")");
-$port = $_GET["port"];
-if (!is_numeric($port)) throw new IllegalArgumentException("Non-numeric port supplied");
-$event = $_GET["event"];
-$ip = $_GET["ip"];
-$uploaded = $_GET["uploaded"];
-if (!$uploaded) $uploaded = 0;
-if (!is_numeric($uploaded)) throw new IllegalArgumentException("Non-numeric upload amount specified");
-$downloaded = $_GET["downloaded"]; if (!$downloaded) $downloaded = 0;
-if (!is_numeric($downloaded)) throw new IllegalArgumentException("Non-numeric download amount specified");
-
-if (!$ip){
- $ip = $_SERVER["REMOTE_ADDR"];
-}
-
-// Is the IP banned?
-db_init();
-if (isIPBanned($ip)){
- trackerError("Banned IP: ".$ip);
-}
-
-// Check that the info_hash is one that we allow:
-$queryHandle = mysql_query("SELECT * from bittorrent_files where info_hash=\"".process_user_text($info_hash)."\""); echo mysql_error();
-if (!mysql_num_rows($queryHandle)){
- trackerError("The tracker does not allow tracking of this file:".$info_hash . " [] ".$_GET["info_hash"]);
-}
-$infoHashObject = mysql_fetch_object($queryHandle);
-
-// If the peer is actively doing something let's update the DB
-if ($event=="started" || $event=="stopped" || $event=="completed"){
- mysql_query("REPLACE into bittorrent_peers SET fileid=".$infoHashObject->id.", peerid=\"".process_user_text($peer_id)."\", ip=\"".process_user_text($ip)."\", port=\"".process_user_text($port)."\", status=\"".$event."\", uploaded=".process_user_text($uploaded).", downloaded=".process_user_text($downloaded).", timestamp=".time());
- echo mysql_error();
-} else {
- mysql_query("REPLACE delayed into bittorrent_peers SET fileid=".$infoHashObject->id.", peerid=\"".process_user_text($peer_id)."\", ip=\"".process_user_text($ip)."\", port=\"".process_user_text($port)."\", uploaded=".process_user_text($uploaded).", downloaded=".process_user_text($downloaded).", timestamp=".time());
- echo mysql_error();
-}
-
-// Always send back a random selection of peers who are downloading a file with the same info_hash
-$queryHandle = mysql_query("SELECT * from bittorrent_peers WHERE fileid = ".$infoHashObject->id." order by RAND() limit ".MAX_INFO_HASH_PEERS); echo mysql_error();
-$peerList = array();
-while ($dbPeer = mysql_fetch_object($queryHandle)){
- $peer = array("peer id"=>$dbPeer->peerid, "ip"=>$dbPeer->ip, "port"=>intval($dbPeer->port));
- $peerList[] = new BElement(BDictionary::toEncoded($peer));
-}
-
-// Get some statistical counts
-$queryHandle = mysql_query("SELECT count(fileid) as complete from bittorrent_peers where fileid = '".$infoHashObject->id."' and status='completed'");
-$data = mysql_fetch_object($queryHandle);
-$complete = intval($data->complete);
-$queryHandle = mysql_query("SELECT count(fileid) as incomplete from bittorrent_peers where fileid = '".$infoHashObject->id."' and status!='completed'");
-$data = mysql_fetch_object($queryHandle);
-$incomplete = intval($data->incomplete);
-
-
-$peersElement = new BElement(BList::toEncoded($peerList));
-$out = BDictionary::toEncoded(array("interval"=>DEFAULT_CONNECTION_INTERVAL, "complete"=>$complete, "incomplete"=>$incomplete, "peers"=>$peersElement));
-
-// Echo the answer to stdout
-echo $out;
-$fh = fopen(TRACKER_LOGFILE, "a");
-fputs($fh, date(DATE_ATOM, time())." ".$_SERVER["REMOTE_ADDR"]." - ".$event."\n");
-fclose($fh);
-
-// ------------------------------------------------------
-// Check if the database needs cleaning
-$cache_args = "tracker_timer";
-$cacheddata=get_cached_data(DB_CLEAN_TTL,$cache_args);
-if ($cacheddata){ //If we have got the timer in cache
- // Do nothing
-} else { //if not do queries etc to clean DB
- // TODO: update the bittorrent_statistics table here before deleting entries
- mysql_query("DELETE from bittorrent_files where timestamp<".(time()-TORRENT_TTL)); echo mysql_error();
- mysql_query("DELETE from bittorrent_peers where timestamp<".(time()-PEER_TTL)); echo mysql_error();
- mysql_query("DELETE from bittorrent_ipbans where timestamp<".time()); echo mysql_error();
- // And reset the timer in the cache
- set_cache_data(serialize(time()),$cache_args); //save data in cache
-};
-
-?>
\ No newline at end of file
diff --git a/html/bt/config.php.example b/html/bt/config.php.example
deleted file mode 100644
index 2bf76c7947..0000000000
--- a/html/bt/config.php.example
+++ /dev/null
@@ -1,81 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/database/bittorrent_files.sql b/html/bt/database/bittorrent_files.sql
deleted file mode 100644
index eaabd2cc0e..0000000000
--- a/html/bt/database/bittorrent_files.sql
+++ /dev/null
@@ -1,9 +0,0 @@
-CREATE TABLE `bittorrent_files` (
- `id` int(11) NOT NULL auto_increment,
- `filename` varchar(256) default NULL,
- `info_hash` varbinary(22) default NULL,
- `timestamp` int(14) NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `filename` (`filename`),
- KEY `info_hash` (`info_hash`)
-) ENGINE=MEMORY;
\ No newline at end of file
diff --git a/html/bt/database/bittorrent_ipbans.sql b/html/bt/database/bittorrent_ipbans.sql
deleted file mode 100644
index 016953474e..0000000000
--- a/html/bt/database/bittorrent_ipbans.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-CREATE TABLE `bittorrent_ipbans` (
- `ip` varbinary(256) NOT NULL default '',
- `timestamp` int(14) NOT NULL,
- PRIMARY KEY (`ip`)
-) ENGINE=MEMORY COMMENT='Banned IPs and when they can be unbanned (reset when SQL-server restarts)';
\ No newline at end of file
diff --git a/html/bt/database/bittorrent_peers.sql b/html/bt/database/bittorrent_peers.sql
deleted file mode 100644
index 4801144a83..0000000000
--- a/html/bt/database/bittorrent_peers.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE TABLE `bittorrent_peers` (
- `fileid` int(11) NOT NULL default '0',
- `peerid` varbinary(20) NOT NULL,
- `ip` varbinary(50) default NULL,
- `port` int(11) NOT NULL,
- `status` enum('started','stopped','completed') NOT NULL,
- `uploaded` int(11) NOT NULL,
- `downloaded` int(11) NOT NULL,
- `timestamp` int(14) NOT NULL,
- PRIMARY KEY (`fileid`,`peerid`),
- KEY `timestamp` (`timestamp`)
-) ENGINE=MEMORY;
-
\ No newline at end of file
diff --git a/html/bt/filters/allfilesfilefilter.php b/html/bt/filters/allfilesfilefilter.php
deleted file mode 100644
index c9d46f5b30..0000000000
--- a/html/bt/filters/allfilesfilefilter.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/filters/filefilter.php b/html/bt/filters/filefilter.php
deleted file mode 100644
index 4cde924a51..0000000000
--- a/html/bt/filters/filefilter.php
+++ /dev/null
@@ -1,13 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/inc/bdictionary.php b/html/bt/inc/bdictionary.php
deleted file mode 100644
index 9c8b8b0845..0000000000
--- a/html/bt/inc/bdictionary.php
+++ /dev/null
@@ -1,53 +0,0 @@
- "moo", "spam" => "eggs" }
- */
-
-$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
-
-class BDictionary {
- private function __construct(){
- }
-
- /**
- * Returns the decoded array from $str
- * @throws an IllegalArgumentException in the case
- * that the string is malformed.
- */
- public static function toArray($str){
- if (substr($str, 0, 1)!="d" || substr($str, -1, 1)!="e") throw new IllegalArgumentException("BEncoded dictionary does not start with d or end with e.");
- // An array is simply two lists encoded in an alternating list
- $arrays = BList::toList("l".substr($str, 1));
-
- $i=0;
- for ($i=0;$i $value){
- $list[] = $key;
- $list[] = $value;
- }
-
- return "d".substr(BList::toEncoded($list), 1);
- }
-}
-
-
-?>
\ No newline at end of file
diff --git a/html/bt/inc/belement.php b/html/bt/inc/belement.php
deleted file mode 100644
index 560981046d..0000000000
--- a/html/bt/inc/belement.php
+++ /dev/null
@@ -1,29 +0,0 @@
-encodedText = $bEncoding;
- }
-
- /**
- * Returns a BEncoded value
- */
- public function toEncoded(){
- return $this->encodedText;
- }
-}
-
-
-?>
\ No newline at end of file
diff --git a/html/bt/inc/binteger.php b/html/bt/inc/binteger.php
deleted file mode 100644
index e93970146f..0000000000
--- a/html/bt/inc/binteger.php
+++ /dev/null
@@ -1,35 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/inc/blist.php b/html/bt/inc/blist.php
deleted file mode 100644
index 86f45b3cdf..0000000000
--- a/html/bt/inc/blist.php
+++ /dev/null
@@ -1,102 +0,0 @@
-toEncoded();
- }
- }
- $text.= "e";
- return $text;
- }
-}
-
-
-?>
\ No newline at end of file
diff --git a/html/bt/inc/bstring.php b/html/bt/inc/bstring.php
deleted file mode 100644
index 3109ef4273..0000000000
--- a/html/bt/inc/bstring.php
+++ /dev/null
@@ -1,36 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/inc/checks.php b/html/bt/inc/checks.php
deleted file mode 100644
index 9db9c943ce..0000000000
--- a/html/bt/inc/checks.php
+++ /dev/null
@@ -1,31 +0,0 @@
- ".time()); echo mysql_error();
- if (mysql_num_rows($queryHandle)){
- return true;
- } else {
- return false;
- }
-}
-
-if (get_magic_quotes_gpc()) {
- function stripslashes_deep($value) {
- $value = is_array($value) ?
- array_map('stripslashes_deep', $value) :
- stripslashes($value);
- return $value;
- }
-
- $_POST = array_map('stripslashes_deep', $_POST);
- $_GET = array_map('stripslashes_deep', $_GET);
- $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
- $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
-}
-?>
\ No newline at end of file
diff --git a/html/bt/inc/illegalargumentexception.php b/html/bt/inc/illegalargumentexception.php
deleted file mode 100644
index 995f3093ba..0000000000
--- a/html/bt/inc/illegalargumentexception.php
+++ /dev/null
@@ -1,9 +0,0 @@
-
\ No newline at end of file
diff --git a/html/bt/inc/torrent.php b/html/bt/inc/torrent.php
deleted file mode 100644
index 8e058a7dce..0000000000
--- a/html/bt/inc/torrent.php
+++ /dev/null
@@ -1,89 +0,0 @@
-filename = $filename;
- $this->trackerURL = $trackerURL;
- $this->webseeds = $webseeds;
- $this->name = basename($filename);
- }
-
- /**
- * Scans the entire file generating SHA1 hashes for each piece
- */
- public function ensureSHA1Loaded(){
- if (!$this->concattedSHA1 || ($this->pieceLength!=$this->generatedPieceLength)){
- $fh = fopen($this->filename, "rb");
- if (!$fh) throw new Exception("No filehandle");
- $fsize = filesize($this->filename);
- $this->concattedSHA1 = "";
- for ($i = 0; $ipieceLength); $i++){
- fseek($fh, $i*$this->pieceLength);
- $this->concattedSHA1 .= sha1(fread($fh,$this->pieceLength), true);
- }
- $this->generatedPieceLength = $this->pieceLength;
- fclose($fh);
- if (!$this->concattedSHA1) throw new Exception("No SHA gotten");
- }
-
- }
-
- /**
- * Fetches all relevant information from the file and generates a
- * .torrent
- */
- public function toEncoded(){
- $infoArray["name"] = $this->name;
- $infoArray["piece length"] = $this->pieceLength;
- $infoArray["length"] = filesize($this->filename);
- $this->ensureSHA1Loaded();
- $infoArray["pieces"] = $this->concattedSHA1;
- $infoDictionary = new BElement(BDictionary::toEncoded($infoArray));
- $this->infoHash = sha1($infoDictionary->toEncoded(), true);
- $metainfoArray = array("announce"=>$this->trackerURL, "info"=>$infoDictionary);
- $metainfoArray["url-list"] = new BElement(BList::toEncoded($this->webseeds));
- $metainfoDictionary = BDictionary::toEncoded($metainfoArray);
-
- return $metainfoDictionary;
- }
-
- /**
- * Registers this torrent in the database
- */
- public function register(){
- $this->toEncoded();
- // Check if exists:
- $queryHandle = mysql_query("SELECT id from bittorrent_files where filename=\"".process_user_text($this->filename)."\"");
- if ($queryHandle && $data = mysql_fetch_object($queryHandle)){
- $extra = "id=".$data->id.", ";
- } else {
- $extra = "";
- }
- mysql_query("REPLACE into bittorrent_files set ".$extra."filename=\"".process_user_text($this->filename)."\", info_hash=\"".process_user_text($this->infoHash)."\", timestamp=".time());
- }
-}
\ No newline at end of file
diff --git a/html/bt/index.php b/html/bt/index.php
deleted file mode 100644
index 9e0a511335..0000000000
--- a/html/bt/index.php
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
-
- BOINC Bittorrent
-
- BOINC Bittorrent
-
- This page helps you identify whether the BOINC Bittorrent system has succesfully been installed
- on the server. If all of the bellow checks are green and all of the settings seem to match your
- setup then everything should be perfectly fine.
- If, for some reason, the entire page (including the text at the bottom, bellow the table of checks)
- isn't displayed, you should have a look at the error-log for your server. Similarly, if one of the
- checks fail you may find additional information on the page or in your server logs.
-
-
-
- Check | Status |
-
-".$check." | ";
- if ($status){
- echo "OK";
- } else {
- echo "Hm...";
- }
- echo " | ";
- if (!$status) echo $comment;
- echo " | ";
-}
- showCheck("Linking to config.php", file_exists("./config.php"), "config.php is missing - did you remember to copy from the sample?");
- require_once("./config.php");
- showCheck("Linking to BOINC serverside framework", file_exists("../inc/util.inc"), "Cannot find the BOINC framework - did you install the BT system in the html/-directory of your BOINC installation?");
- require_once("../inc/util.inc");
- showCheck("Database link", (db_init()||true), "");
- showCheck("bittorrent_files table", mysql_query("select * from bittorrent_files"), "Table inaccessible");
- showCheck("bittorrent_ipbans table", mysql_query("select * from bittorrent_ipbans"), "Table inaccessible");
- showCheck("bittorrent_peers table", mysql_query("select * from bittorrent_peers"), "Table inaccessible");
- showCheck("bittorrent_statistics table", mysql_query("select * from bittorrent_statistics"), "Table inaccessible");
- showCheck("Linking to download dir (".$fileDirectory.")", file_exists($fileDirectory), "Directory not accessible or present");
- showCheck("Tracker present (".$trackerURL.")", fopen($trackerURL, "r"), "Either this webserver doesn't support URL-fopen-wrappers or the tracker is not available. In the first case you may safely ignore this warning.");
- showCheck("Webseeds defined", (sizeof($webseeds)>0), "No webseeds defined");
- foreach ($webseeds as $webseed){
- showCheck("Seed present (".$webseed.")", fopen($webseed, "r"), "Either this webserver doesn't support URL-fopen-wrappers or the webseed is not present. If the first is the case this warning may safely be ignored.");
- }
- showCheck("Linking to logfile (".TRACKER_LOGFILE.")", file_exists(TRACKER_LOGFILE), "The logfile doesn't exist - this may be because the system hasn't been run yet or because the file couldn't be created.");
-?>
-
-
- Files used in this distribution:
-
- ".$cvs_version_tracker[$i]."\n";
- }
- ?>
-
-
-
- For more information check the documentation delivered within the bt directory.
-
-
-