mirror of https://github.com/PurpleI2P/regi2p.git
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.
71 lines
1.5 KiB
71 lines
1.5 KiB
4 years ago
|
<?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 = [];
|
||
|
|
||
|
$STH = $pdo->query("SELECT `host`, `base32` FROM `hosts`");
|
||
|
$hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR);
|
||
|
|
||
|
/* Start temporary BOB tunnel for checking */
|
||
|
$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() WHERE `host` = '" . $host . "'");
|
||
|
$i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$pdo->commit();
|
||
|
|
||
|
echo "Result: Total hosts: " . count($results) . ", Alive: " . $i . PHP_EOL;
|