diff --git a/announce.php b/announce.php index 0c68e56..317f75e 100644 --- a/announce.php +++ b/announce.php @@ -68,16 +68,19 @@ $stmt = $conn->prepare("SELECT * FROM `trackers`"); $stmt->execute(); $trackers = $stmt->fetchAll(PDO::FETCH_CLASS, Tracker::class); foreach($trackers as $tracker) { - $remotePeers = $tracker->announce($hash, - $clientPeer->getIp(), $clientPeer->getPort(), - isset($_GET["peer_id"]) ? $_GET["peer_id"] : null, - isset($_GET["uploaded"]) ? $_GET["uploaded"] : 0, - isset($_GET["downloaded"]) ? $_GET["downloaded"] : 0, - isset($_GET["left"]) ? $_GET["left"] : 0 - ); + try { + $remotePeers = $tracker->announce($hash, + $clientPeer->getIp(), $clientPeer->getPort(), + isset($_GET["peer_id"]) ? $_GET["peer_id"] : null, + isset($_GET["uploaded"]) ? $_GET["uploaded"] : 0, + isset($_GET["downloaded"]) ? $_GET["downloaded"] : 0, + isset($_GET["left"]) ? $_GET["left"] : 0 + ); - if ($remotePeers != false) { - $peers = array_merge($peers, $remotePeers); + if ($remotePeers != false) { + $peers = array_merge($peers, $remotePeers); + } + } catch (Exception $e) { } } diff --git a/tracker.php b/tracker.php index 178ec99..e943096 100644 --- a/tracker.php +++ b/tracker.php @@ -26,6 +26,14 @@ class Tracker { return $this->proto . "://" . $this->host . $this->path; } + public function getPasskeyName() { + if (!is_null($this->passkey)) { + return explode(' ', $this->passkey)[0]; + } + + return false; + } + public function doHttpAnnounce($infoHash, $peerIp, $peerPort, $peerId = null, $uploaded = 0, $downloaded = 0, $left = 0) { $peers = array(); @@ -44,6 +52,7 @@ class Tracker { curl_setopt($ch, CURLOPT_URL, $this->getHttpUrl() . "?" . $passkey . $params); curl_setopt($ch, CURLOPT_PORT, intval($this->port)); curl_setopt($ch, CURLOPT_USERAGENT, self::ANN_USERAGENT); + curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (!is_null($this->proxy)) { curl_setopt($ch, CURLOPT_PROXY, $this->proxy); @@ -57,7 +66,7 @@ class Tracker { } $response = bdecode($result); - if (array_key_exists($response, "failure reason")) { + if (!array_key_exists("peers", $response)) { return false; }