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

Commit

Permalink
Merge 875cb2b into 564642a
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Dec 6, 2018
2 parents 564642a + 875cb2b commit 18d6255
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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
20 changes: 19 additions & 1 deletion src/Console/StartWebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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 BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
Expand Down Expand Up @@ -47,7 +49,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 +125,20 @@ protected function startWebSocketServer()
->createServer()
->run();
}

protected function getDnsResolver()
{
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
);
}
}

0 comments on commit 18d6255

Please sign in to comment.