From 0d1ef0aebec58c46700c148f0236f5adfb904247 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 7 Oct 2020 17:19:46 +0200 Subject: [PATCH] Allow binding to specific address and port --- src/danog/MadelineProto/DataCenter.php | 2 +- .../MadelineProto/Settings/Connection.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 3d2a6656..39f0010f 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -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 = [ diff --git a/src/danog/MadelineProto/Settings/Connection.php b/src/danog/MadelineProto/Settings/Connection.php index 8b831512..f0d16722 100644 --- a/src/danog/MadelineProto/Settings/Connection.php +++ b/src/danog/MadelineProto/Settings/Connection.php @@ -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; + } }