Repository navigation
Expand file tree
/
Copy pathannounce.php
More file actions
58 lines (50 loc) · 2.16 KB
/
Copy pathannounce.php
File metadata and controls
58 lines (50 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* Bitstorm 2 - A small and fast BitTorrent tracker
* Copyright 2011 Peter Caprioli
* Copyright 2015 Wilhelm Svenselius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require('_config.php');
require('_util.php');
require('_data.php');
header("Content-Type: text/plain");
dbConnect();
$peerId = validateFixedLengthString('peer_id');
$port = validateConstrainedInt('port', 1, 65535);
$infoHash = validateFixedLengthString('info_hash');
$key = validateString('key', true);
$downloaded = validateInt('downloaded', true);
$uploaded = validateInt('uploaded', true);
$left = validateInt('left', true);
$numWant = validateInt('numwant', true);
$noPeerId = isset($_GET['no_peer_id']);
if(__WHITELIST_ENABLED && !isWhitelisted($infoHash)) {
die(trackError('Torrent not allowed on this tracker'));
}
$peerPk = dbUpdatePeer($peerId, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR'], $key, $port);
$torrentPk = dbUpdateTorrent($infoHash);
$peerTorrentPk = dbUpdatePeerTorrent($peerPk, $uploaded, $downloaded, $left, $infoHash);
if(isset($_GET['event']) && $_GET['event'] === 'stopped') {
dbStoppedPeer($peerTorrentPk);
// The RFC says its OK to return an empty string when stopping a torrent however some clients will whine about it so we return an empty dictionary
die(trackPeers(array(), 0, 0, $noPeerId));
}
if($numWant <= 0 || $numWant > __MAX_PPR) {
$numWant = __MAX_PPR;
}
$reply = dbGetPeers($torrentPk, $peerPk, $numWant);
list($seeders, $leechers) = dbGetCounts($torrentPk);
die(trackPeers($reply, $seeders, $leechers, $noPeerId));