Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Use an actual DNS resolver #31

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/websockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
* 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,
],

/*
Expand Down
21 changes: 20 additions & 1 deletion src/Console/StartWebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
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;
Expand Down Expand Up @@ -47,7 +50,7 @@ public function handle()
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',
Expand Down Expand Up @@ -123,4 +126,20 @@ protected function startWebSocketServer()
->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
);
}
}