Add DoH setting

This commit is contained in:
Daniil Gentili 2020-10-07 17:15:51 +02:00
parent 0a2e325229
commit d74efbfd08
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 40 additions and 9 deletions

View File

@ -60,7 +60,7 @@ class MyEventHandler extends EventHandler
*
* @param array $update Update
*
* @return void
* @return \Generator
*/
public function onUpdateNewChannelMessage(array $update): \Generator
{

View File

@ -98,13 +98,13 @@ class DataCenter
/**
* DNS over HTTPS client.
*
* @var \Amp\DoH\Rfc8484StubResolver
* @var Rfc8484StubResolver|Rfc1035StubResolver
*/
private $DoHClient;
/**
* Non-proxied DNS over HTTPS client.
*
* @var \Amp\DoH\Rfc8484StubResolver
* @var Rfc8484StubResolver|Rfc1035StubResolver
*/
private $nonProxiedDoHClient;
/**
@ -233,14 +233,16 @@ class DataCenter
$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 ? new Rfc1035StubResolver() : new Rfc8484StubResolver($DoHConfig);
$this->nonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($nonProxiedDoHConfig);
$this->DoHClient = Magic::$altervista || Magic::$zerowebhost || !$settings->getUseDoH()
? new Rfc1035StubResolver()
: new Rfc8484StubResolver($DoHConfig);
$this->nonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost || !$settings->getUseDoH()
? new Rfc1035StubResolver()
: new Rfc8484StubResolver($nonProxiedDoHConfig);
$this->dnsConnector = new DnsConnector(new Rfc1035StubResolver());
if (\class_exists(Rfc6455Connector::class)) {
$this->webSocketConnector = new Rfc6455Connector($this->HTTPClient);
}
}
$this->settings->applyChanges();
}
/**

View File

@ -82,7 +82,7 @@ class Logger
/**
* Default logger instance.
*
* @var ?self
* @var self
*/
public static $default;
/**

View File

@ -86,6 +86,11 @@ class Connection extends SettingsAbstract
*/
protected bool $retry = true;
/**
* Whether to use DNS over HTTPS.
*/
protected bool $useDoH = true;
/**
* Subdomains of web.telegram.org for https protocol.
*/
@ -594,4 +599,28 @@ class Connection extends SettingsAbstract
return $this;
}
/**
* Get whether to use DNS over HTTPS.
*
* @return bool
*/
public function getUseDoH(): bool
{
return $this->useDoH;
}
/**
* Set whether to use DNS over HTTPS.
*
* @param bool $useDoH Whether to use DNS over HTTPS
*
* @return self
*/
public function setUseDoH(bool $useDoH): self
{
$this->useDoH = $useDoH;
return $this;
}
}