forked from nostriphant/transpher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.php
32 lines (24 loc) · 857 Bytes
/
agent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require_once __DIR__ . '/bootstrap.php';
use nostriphant\Transpher\Client;
use nostriphant\Transpher\Nostr\Key;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use function \Amp\trapSignal;
$log = new Logger('agent');
$log->pushHandler(new StreamHandler(__DIR__ . '/logs/agent.log', Level::Debug));
$log->pushHandler(new StreamHandler(STDOUT), Level::Info);
$relay_url = $_SERVER['RELAY_URL'];
$log->info('Client connecting to ' . $relay_url);
$agent = new nostriphant\Transpher\Agent(
new Client($relay_url),
Key::fromBech32($_SERVER['AGENT_NSEC']),
$_SERVER['RELAY_OWNER_NPUB']
);
$disconnect = $agent($log);
// Await SIGINT or SIGTERM to be received.
$signal = trapSignal([SIGINT, SIGTERM]);
$log->info(sprintf("Received signal %d, stopping Relay server", $signal));
$disconnect();
$log->info('Done');