Allow binding to specific address and port

This commit is contained in:
Daniil Gentili 2020-10-07 17:19:46 +02:00
parent d74efbfd08
commit 0d1ef0aebe
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 30 additions and 1 deletions

View File

@ -406,7 +406,7 @@ class DataCenter
$combos = \array_unique($combos, SORT_REGULAR);
}
/* @var $context \Amp\ConnectContext */
$context = $context ?? (new ConnectContext())->withMaxAttempts(1)->withConnectTimeout(1000 * $this->settings->getTimeout());
$context = $context ?? (new ConnectContext())->withMaxAttempts(1)->withConnectTimeout(1000 * $this->settings->getTimeout())->withBindTo($this->settings->getBindTo());
foreach ($combos as $combo) {
foreach ([true, false] as $useDoH) {
$ipv6Combos = [

View File

@ -91,6 +91,11 @@ class Connection extends SettingsAbstract
*/
protected bool $useDoH = true;
/**
* Bind on specific address and port.
*/
private ?string $bindTo = null;
/**
* Subdomains of web.telegram.org for https protocol.
*/
@ -623,4 +628,28 @@ class Connection extends SettingsAbstract
return $this;
}
/**
* Get bind on specific address and port.
*
* @return ?string
*/
public function getBindTo(): ?string
{
return $this->bindTo;
}
/**
* Set bind on specific address and port.
*
* @param ?string $bindTo Bind on specific address and port.
*
* @return self
*/
public function setBindTo(?string $bindTo): self
{
$this->bindTo = $bindTo;
return $this;
}
}