Domain registry project http://reg.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
1.9 KiB

<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config.php';
use App\BOB;
use App\DB;
use Amp\Loop;
use Amp\Parallel\Worker\DefaultPool;
/* Disable execution limit */
set_time_limit(0);
$pdo = (new DB($options))->pdo;
$results = [];
echo "[DB] Fetching hosts to check from database" . PHP_EOL;
if ((($options['fullhour'] >= 0) && ($options['fullhour'] <= 23)) && date('H') == $options['fullhour']) { // check all hosts at full check hour
$STH = $pdo->query("SELECT `host`, `base32` FROM `hosts`");
} else {
$STH = $pdo->query("SELECT `host`, `base32` FROM `hosts` WHERE `disabled` = '0'");
}
$hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR);
echo "[BOB] Starting session for checking" . PHP_EOL;
$bob = new BOB($options);
$bob->setnick();
$bob->options();
$bob->newkeys();
$bob->intun();
$bob->start();
/* Sleep 10 seconds awaitng tunnels get built */
echo "[BOB] Session started, awaiting 10 seconds for tunnels" . PHP_EOL;
sleep(10);
/* Start async checker tasks */
Loop::run(function () use (&$results, $hosts, $options) {
$pool = new DefaultPool(64);
$coroutines = [];
foreach ($hosts as $host => $base32) {
$coroutines[$host] = Amp\call(function () use ($pool, $base32, $options) {
$result = yield $pool->enqueue(new App\Checker($base32, $options));
return $result;
});
}
$results = yield Amp\Promise\all($coroutines);
return yield $pool->shutdown();
});
/* Stop BOB tunnel and terminate */
$bob->stop();
$bob->clear();
$bob = null;
/* Update last seen time in DB */
$i = 0;
$pdo->beginTransaction();
foreach ($results as $host => $result)
{
if($result)
{
$pdo->exec("UPDATE `hosts` SET `last_seen` = current_timestamp(), `disabled` = 0, `hidden` = 0 WHERE `host` = '" . $host . "'");
$i++;
}
}
$pdo->commit();
echo "Result: Total hosts: " . count($results) . ", Alive: " . $i . PHP_EOL;