diff --git a/config.php.dist b/config.php.dist index 926fa2a..2874d0b 100644 --- a/config.php.dist +++ b/config.php.dist @@ -16,6 +16,7 @@ $options = [ 'bob_port' => '2827', 'bob_options' => 'inbound.quantity=5 outbound.quantity=5 inbound.length=1 outbound.length=1 i2cp.leaseSetType=3', 'bob_nick' => 'hostchecker', + 'check_tries' => 1, 'http_proxy' => 'tcp://127.0.0.1:4444', // this is HTTP proxy, which must be specified as tcp protocol because we using stream context /* Service settings */ diff --git a/lib/bob.php b/lib/bob.php index 89737c0..7b2811d 100644 --- a/lib/bob.php +++ b/lib/bob.php @@ -136,6 +136,19 @@ class BOB { return false; } + public function lookuplocal(string $address): bool + { + $command = "lookuplocal " . $address . "\n"; + socket_write($this->sock, $command, strlen($command)); + + $response = socket_read($this->sock, 1024, PHP_NORMAL_READ); + + if(preg_match('/^OK/', $response)) + return true; + + return false; + } + public function stop() { $command = "stop\n"; diff --git a/lib/checker.php b/lib/checker.php index 43009cf..fb6ffea 100644 --- a/lib/checker.php +++ b/lib/checker.php @@ -27,9 +27,19 @@ class Checker implements Task public function run(Environment $environment) { $bob = new BOB($this->options); - $bob->getnick(); - $result = $bob->lookup($this->base32 . ".b32.i2p"); + + $result = false; + for ($i = 0, $tries = $this->options['check_tries']; $i < $tries; ++$i) { + $result = $bob->lookuplocal($this->base32 . ".b32.i2p"); + if(!$result) { + $result = $bob->lookup($this->base32 . ".b32.i2p"); + } + + if ($result) { + break; + } + } $bob = null; echo "Processed " . $this->base32 . ": " . ($result ? "online" : "offline") . PHP_EOL;