Esempio n. 1
0
if (isset($_GET['numwant'])) {
    $numwant = 0 + $_GET['numwant'];
}
//Find out if we are seeding or not. Assume not if unknown.
$is_seed = isset($_GET['left']) && $_GET['left'] == 0 ? true : false;
//Get IP
$ip = $_SERVER['REMOTE_ADDR'];
if (ip2long($ip)) {
    $ip4 = $ip;
} else {
    $ip6 = $ip;
}
//Did the client stop the torrent?
//We dont care about other events
if (isset($_GET['event']) && $_GET['event'] === 'stopped') {
    $r->srem($info_hash, $peer_id);
    die(track(array()));
    //The RFC says its OK to return whatever we want when the client stops downloading,
    //however, some clients will complain about the tracker not working, hence we return
    //an empty bencoded peer list
}
//Update information of this peer and get all the other peers downloading the same file.
$map = $info_hash . ':' . $peer_id;
$r->sadd('torrents', $info_hash);
$r->sadd($info_hash, $peer_id);
$pid_list = $r->smembers($info_hash);
if (isset($ip4)) {
    $r->hmset($map, 'ip4', $ip4, 'port', $port, 'seed', $is_seed);
} else {
    $r->hmset($map, 'ip6', $ip6, 'port', $port, 'seed', $is_seed);
}
Esempio n. 2
0
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of sets
 *
 * @author changdi
 */
require "../shared.php";
$predis = new Predis\Client($single_server);
var_dump($predis->sadd('set-key', 'a', 'b', 'c'));
var_dump($predis->srem('set-key', 'c', 'd'));
var_dump($predis->srem('set-key', 'c', 'd'));
var_dump($predis->scard('set-key'));
var_dump($predis->smembers('set-key'));
var_dump($predis->smove('set-key', 'set-key2', 'a'));
var_dump($predis->smove('set-key', 'set-key2', 'c'));
var_dump($predis->smembers('set-key'));