From 52ecd9102d7dae7a7e0b9445135185d1076443e5 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 4 Jun 2022 16:56:59 +0200 Subject: [PATCH] More fixes --- .gitattributes | 1 + src/danog/MadelineProto/DataCenter.php | 30 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..2a0e9d261 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +tests/ export-ignore diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 8b0bdc1ff..932215e97 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -19,8 +19,12 @@ namespace danog\MadelineProto; +use Amp\Dns\Config; +use Amp\Dns\ConfigLoader; use Amp\Dns\Resolver; use Amp\Dns\Rfc1035StubResolver; +use Amp\Dns\UnixConfigLoader; +use Amp\Dns\WindowsConfigLoader; use Amp\DoH\DoHConfig; use Amp\DoH\Nameserver; use Amp\DoH\Rfc8484StubResolver; @@ -32,6 +36,7 @@ use Amp\Http\Client\Cookie\InMemoryCookieJar; use Amp\Http\Client\HttpClient; use Amp\Http\Client\HttpClientBuilder; use Amp\Http\Client\Request; +use Amp\Promise; use Amp\Socket\ConnectContext; use Amp\Socket\DnsConnector; use Amp\Websocket\Client\Handshake; @@ -229,19 +234,38 @@ class DataCenter } } if ($reconnectAll || $changedSettings || !$this->CookieJar) { + $configProvider = new class implements ConfigLoader { + private function loadConfigGenerator(): \Generator { + $loader = \stripos(PHP_OS, "win") === 0 ? new WindowsConfigLoader() : new UnixConfigLoader(); + try { + return yield $loader->loadConfig(); + } catch (\Throwable) { + return new Config([ + '1.1.1.1', + '1.0.0.1', + '[2606:4700:4700::1111]', + '[2606:4700:4700::1001]', + ]); + } + } + public function loadConfig(): Promise { + return Tools::call($this->loadConfigGenerator()); + } + }; + $this->CookieJar = $jar ?? new InMemoryCookieJar(); $this->HTTPClient = (new HttpClientBuilder())->interceptNetwork(new CookieInterceptor($this->CookieJar))->usingPool(new UnlimitedConnectionPool(new DefaultConnectionFactory(new ContextConnector($this))))->build(); $DoHHTTPClient = (new HttpClientBuilder())->interceptNetwork(new CookieInterceptor($this->CookieJar))->usingPool(new UnlimitedConnectionPool(new DefaultConnectionFactory(new ContextConnector($this, true))))->build(); $DoHConfig = new DoHConfig([new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'), new Nameserver('https://dns.google/resolve')], $DoHHTTPClient); $nonProxiedDoHConfig = new DoHConfig([new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'), new Nameserver('https://dns.google/resolve')]); $this->DoHClient = Magic::$altervista || Magic::$zerowebhost || !$settings->getUseDoH() - ? new Rfc1035StubResolver() + ? new Rfc1035StubResolver(null, $configProvider) : new Rfc8484StubResolver($DoHConfig); $this->nonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost || !$settings->getUseDoH() - ? new Rfc1035StubResolver() + ? new Rfc1035StubResolver(null, $configProvider) : new Rfc8484StubResolver($nonProxiedDoHConfig); - $this->dnsConnector = new DnsConnector(new Rfc1035StubResolver()); + $this->dnsConnector = new DnsConnector(new Rfc1035StubResolver(null, $configProvider)); $this->webSocketConnector = new Rfc6455Connector($this->HTTPClient); } $this->settings->applyChanges();