Browse Source

add BOB lookuplocal support, checker retries

Signed-off-by: r4sas <r4sas@i2pmail.org>
master
R4SAS 3 years ago
parent
commit
5166c2c57c
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 1
      config.php.dist
  2. 13
      lib/bob.php
  3. 14
      lib/checker.php

1
config.php.dist

@ -16,6 +16,7 @@ $options = [ @@ -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 */

13
lib/bob.php

@ -136,6 +136,19 @@ class BOB { @@ -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";

14
lib/checker.php

@ -27,9 +27,19 @@ class Checker implements Task @@ -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;

Loading…
Cancel
Save