Esempio n. 1
0
 /**
  * Save announce for all the torrents in the database
  * so clients know where to connect.
  *
  * This method runs in infinite loop repeating
  * announcing every self::ANNOUNCE_INTERVAL seconds.
  *
  * @return void
  */
 protected function announce()
 {
     $persistence = $this->persistence;
     $iterations = 0;
     do {
         $all_torrents = $persistence->getAllInfoHash();
         foreach ($all_torrents as $torrent_info) {
             $persistence->saveAnnounce($torrent_info['info_hash'], $this->peer->getPeerId(), $this->peer->getExternalAddress(), $this->peer->getPort(), $torrent_info['length'], 0, 0, 'complete', self::ANNOUNCE_INTERVAL);
         }
         $this->logger->logMessage('Seeder server announced itself for ' . count($all_torrents) . " torrents at address {$this->peer->getExternalAddress()}:" . "{$this->peer->getPort()} (announces every " . self::ANNOUNCE_INTERVAL . 's).');
         sleep(self::ANNOUNCE_INTERVAL);
         // Memory leak prevention, see self::STOP_AFTER_ITERATIONS.
     } while (++$iterations < self::STOP_AFTER_ITERATIONS);
     $this->logger->logMessage('Announce process restarts to prevent memory leaks.');
     exit(0);
 }
 * @author  StealThisShow <*****@*****.**>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
 */
use StealThisShow\StealThisTracker\Persistence\Pdo;
use StealThisShow\StealThisTracker\Seeder\Peer;
use StealThisShow\StealThisTracker\Seeder\Server;
use StealThisShow\StealThisTracker\Logger\File;
// --------------------------------------
// This is how to start a seeding server.
// --------------------------------------
// [!] Run this file in CLI only!
// /usr/bin/php example_seeder.php
// Composer autoloader
require dirname(__FILE__) . '/../vendor/autoload.php';
// Persistence object implementing PersistenceInterface.
// We use Pdo here.
$persistence = new Pdo('sqlite:sqlite_example.db');
// Setting up seeder peer. This will listen to connections and serve files.
$peer = new Peer($persistence);
$peer->setInternalAddress('192.168.2.123')->setExternalAddress('192.168.2.123')->setPort(6881)->setPeerForks(10)->setSeedersStopSeeding(5)->setLogger(new File());
// We set up a seeding server which starts the seeding peer, and makes regular
// announcements to the database adding itself to the peer list for all
// active torrents.
$server = new Server($peer, $persistence);
// Initializing file logger with default file path (/var/log/stealthistracker.log).
$server->setLogger(new File());
// Starting "detached" means that process
// will unrelate from terminal and run as daemon.
// To run in terminal, you can use start().
// Detached running requires php-posix.
$server->startDetached();
Esempio n. 3
0
<?php

/**
 * Simple seed server implementation for system test.
 * @package StealThisTracker
 * @author  StealThisShow <*****@*****.**>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
 * @see     SeedServerTest
 */
// No tolerance for errors - it's a test.
set_error_handler(function ($errno, $errstr, $errfile = null, $errline = null) {
    throw new Exception("Error {$errno}: {$errstr} in {$errfile}:{$errline}");
});
require dirname(__FILE__) . '/../../vendor/autoload.php';
use StealThisShow\StealThisTracker\Persistence\Pdo;
use StealThisShow\StealThisTracker\Seeder\Peer;
use StealThisShow\StealThisTracker\Seeder\Server;
$ip = $argv[1];
$port = $argv[2];
fwrite(STDERR, "Starting seed server at {$ip}:{$port}");
$persistence = new Pdo('sqlite:' . sys_get_temp_dir() . '/sqlite_test.db');
$peer = new Peer($persistence);
$peer->setExternalAddress($ip)->setInternalAddress($ip)->setPort($port)->setPeerForks(5)->setSeedersStopSeeding(5);
$server = new Server($peer, $persistence);
$server->start();