mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: delay for dns resolution
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
COMPOSE_PROJECT_NAME="iplist"
|
COMPOSE_PROJECT_NAME="iplist"
|
||||||
STORAGE_SAVE_INTERVAL="120"
|
STORAGE_SAVE_INTERVAL="120"
|
||||||
SYS_MEMORY_LIMIT="512M"
|
SYS_DNS_RESOLVE_DELAY="1000"
|
||||||
|
SYS_MEMORY_LIMIT="1024M"
|
||||||
SYS_TIMEZONE="Europe/Moscow"
|
SYS_TIMEZONE="Europe/Moscow"
|
||||||
DEBUG="true"
|
DEBUG="true"
|
@@ -4,17 +4,23 @@ namespace OpenCCK\Domain\Helper;
|
|||||||
|
|
||||||
use Amp\Dns\DnsConfig;
|
use Amp\Dns\DnsConfig;
|
||||||
use Amp\Dns\DnsConfigLoader;
|
use Amp\Dns\DnsConfigLoader;
|
||||||
use Amp\Dns\DnsException;
|
|
||||||
use Amp\Dns\DnsRecord;
|
use Amp\Dns\DnsRecord;
|
||||||
use Amp\Dns\HostLoader;
|
use Amp\Dns\HostLoader;
|
||||||
use Amp\Dns\Rfc1035StubDnsResolver;
|
use Amp\Dns\Rfc1035StubDnsResolver;
|
||||||
|
|
||||||
use OpenCCK\Infrastructure\API\App;
|
use OpenCCK\Infrastructure\API\App;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
use function Amp\delay;
|
||||||
use function Amp\Dns\dnsResolver;
|
use function Amp\Dns\dnsResolver;
|
||||||
use function Amp\Dns\resolve;
|
use function Amp\Dns\resolve;
|
||||||
|
|
||||||
readonly class DNSHelper {
|
class DNSHelper {
|
||||||
|
private float $resolveDelay;
|
||||||
|
|
||||||
public function __construct(private array $dnsServers = []) {
|
public function __construct(private array $dnsServers = []) {
|
||||||
|
$this->resolveDelay = (\OpenCCK\getEnv('SYS_DNS_RESOLVE_DELAY') ?? 500) / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,23 +51,27 @@ readonly class DNSHelper {
|
|||||||
$ipv4 = [];
|
$ipv4 = [];
|
||||||
$ipv6 = [];
|
$ipv6 = [];
|
||||||
foreach ($this->dnsServers as $server) {
|
foreach ($this->dnsServers as $server) {
|
||||||
$this->setResolver([$server]);
|
|
||||||
try {
|
try {
|
||||||
|
$this->setResolver([$server]);
|
||||||
$ipv4 = array_merge(
|
$ipv4 = array_merge(
|
||||||
$ipv4,
|
$ipv4,
|
||||||
array_map(fn(DnsRecord $record) => $record->getValue(), resolve($domain, DnsRecord::A))
|
array_map(fn(DnsRecord $record) => $record->getValue(), resolve($domain, DnsRecord::A))
|
||||||
);
|
);
|
||||||
} catch (DnsException $e) {
|
} catch (Throwable $e) {
|
||||||
App::getLogger()->error($e->getMessage(), [$server]);
|
App::getLogger()->error($e->getMessage(), [$server]);
|
||||||
}
|
}
|
||||||
|
delay($this->resolveDelay);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$this->setResolver([$server]);
|
||||||
$ipv6 = array_merge(
|
$ipv6 = array_merge(
|
||||||
$ipv6,
|
$ipv6,
|
||||||
array_map(fn(DnsRecord $record) => $record->getValue(), resolve($domain, DnsRecord::AAAA))
|
array_map(fn(DnsRecord $record) => $record->getValue(), resolve($domain, DnsRecord::AAAA))
|
||||||
);
|
);
|
||||||
} catch (DnsException $e) {
|
} catch (Throwable $e) {
|
||||||
App::getLogger()->error($e->getMessage(), [$server]);
|
App::getLogger()->error($e->getMessage(), [$server]);
|
||||||
}
|
}
|
||||||
|
delay($this->resolveDelay);
|
||||||
}
|
}
|
||||||
App::getLogger()->debug('resolve: ' . $domain, [count($ipv4), count($ipv6)]);
|
App::getLogger()->debug('resolve: ' . $domain, [count($ipv4), count($ipv6)]);
|
||||||
return [$ipv4, $ipv6];
|
return [$ipv4, $ipv6];
|
||||||
|
Reference in New Issue
Block a user