Option to resolve DNS for the statistics endpoint (#31)
This commit is contained in:
parent
efbeb18995
commit
db6d794fd5
|
|
@ -65,6 +65,12 @@ return [
|
|||
* the number of days specified here will be deleted.
|
||||
*/
|
||||
'delete_statistics_older_than_days' => 60,
|
||||
|
||||
/*
|
||||
* Use an DNS resolver to make the requests to the statistics logger
|
||||
* default is to resolve everything to 127.0.0.1.
|
||||
*/
|
||||
'perform_dns_lookup' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ namespace BeyondCode\LaravelWebSockets\Console;
|
|||
use React\Socket\Connector;
|
||||
use Clue\React\Buzz\Browser;
|
||||
use Illuminate\Console\Command;
|
||||
use React\Dns\Config\Config as DnsConfig;
|
||||
use React\EventLoop\Factory as LoopFactory;
|
||||
use React\Dns\Resolver\Factory as DnsFactory;
|
||||
use React\Dns\Resolver\Resolver as ReactDnsResolver;
|
||||
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
||||
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
|
||||
|
|
@ -47,7 +50,7 @@ class StartWebSocketServer extends Command
|
|||
protected function configureStatisticsLogger()
|
||||
{
|
||||
$connector = new Connector($this->loop, [
|
||||
'dns' => new DnsResolver(),
|
||||
'dns' => $this->getDnsResolver(),
|
||||
'tls' => [
|
||||
'verify_peer' => config('app.env') === 'production',
|
||||
'verify_peer_name' => config('app.env') === 'production',
|
||||
|
|
@ -123,4 +126,20 @@ class StartWebSocketServer extends Command
|
|||
->createServer()
|
||||
->run();
|
||||
}
|
||||
|
||||
protected function getDnsResolver(): ReactDnsResolver
|
||||
{
|
||||
if (! config('websockets.statistics.perform_dns_lookup')) {
|
||||
return new DnsResolver;
|
||||
}
|
||||
|
||||
$dnsConfig = DnsConfig::loadSystemConfigBlocking();
|
||||
|
||||
return (new DnsFactory)->createCached(
|
||||
$dnsConfig->nameservers
|
||||
? reset($dnsConfig->nameservers)
|
||||
: '1.1.1.1',
|
||||
$this->loop
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue