From 4d3543b49b569a1b8326a3f293c1cae4b6e6d067 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 29 Dec 2019 13:20:18 +0100 Subject: [PATCH] Proxy bugfixes --- src/danog/MadelineProto/ContextConnector.php | 2 +- src/danog/MadelineProto/DataCenter.php | 13 ++++++----- .../MadelineProto/DataCenterConnection.php | 2 +- .../Stream/Transport/DefaultStream.php | 4 ++-- tests/makephar.sh | 23 +++++++++++++++---- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/danog/MadelineProto/ContextConnector.php b/src/danog/MadelineProto/ContextConnector.php index 58b4570c..c9bea431 100644 --- a/src/danog/MadelineProto/ContextConnector.php +++ b/src/danog/MadelineProto/ContextConnector.php @@ -34,7 +34,7 @@ class ContextConnector implements Connector public function __construct(DataCenter $dataCenter, bool $fromDns = false) { $this->dataCenter = $dataCenter; - $this->fromDns = false; + $this->fromDns = $fromDns; $this->logger = $dataCenter->getAPI()->getLogger(); } diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 75bc0ddc..aa09ce53 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -175,11 +175,11 @@ class DataCenter /** * Constructor function. * - * @param MTProto $API Main MTProto instance - * @param array $dclist DC IP list - * @param array $settings Settings - * @param boolean $reconnectAll Whether to reconnect to all DCs or just to changed ones - * @param CookieJar $jar Cookie jar + * @param MTProto $API Main MTProto instance + * @param array $dclist DC IP list + * @param array $settings Settings + * @param boolean $reconnectAll Whether to reconnect to all DCs or just to changed ones + * @param CookieJar $jar Cookie jar * * @return void */ @@ -207,6 +207,7 @@ class DataCenter if ($socket instanceof DataCenterConnection && !\strpos($key, '_bk')) { //$this->API->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['dc_con_stop'], $key), \danog\MadelineProto\Logger::VERBOSE); if ($reconnectAll || isset($changed[$id])) { + $this->API->logger->logger("Disconnecting all before reconnect!"); $socket->needReconnect(true); $socket->setExtra($this->API); $socket->disconnect(); @@ -583,7 +584,7 @@ class DataCenter */ public function getNonProxiedDNSClient(): Resolver { - return $this->DoHClient; + return $this->nonProxiedDoHClient; } /** diff --git a/src/danog/MadelineProto/DataCenterConnection.php b/src/danog/MadelineProto/DataCenterConnection.php index 7e7510e5..e73db346 100644 --- a/src/danog/MadelineProto/DataCenterConnection.php +++ b/src/danog/MadelineProto/DataCenterConnection.php @@ -372,7 +372,7 @@ class DataCenterConnection implements JsonSerializable $this->decRead = $media ? self::READ_WEIGHT_MEDIA : self::READ_WEIGHT; $this->decWrite = self::WRITE_WEIGHT; - if ($id === -1) { + if ($id === -1 || !isset($this->connections[$id])) { if ($this->connections) { $this->API->logger("Already connected!", Logger::WARNING); return; diff --git a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php index 68487131..d98c540d 100644 --- a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php +++ b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php @@ -78,9 +78,9 @@ class DefaultStream implements ) ); } - + $this->stream = yield ($this->connector ?? connector())->connect((string) $uri, $ctx->getSocketContext(), $ctx->getCancellationToken()); - if ($ctx->isSecure()) { + if ($secure) { yield $this->stream->setupTls(); } yield $this->stream->write($header); diff --git a/tests/makephar.sh b/tests/makephar.sh index 5d1121f0..dfb2921f 100755 --- a/tests/makephar.sh +++ b/tests/makephar.sh @@ -106,16 +106,12 @@ find phar5 -type f -exec sed 's/\w* \.\.\./.../' -i {} + branch="-$TRAVIS_BRANCH" cd $madelinePath -export TRAVIS_PHAR="madeline$php$branch.phar" export TEST_SECRET_CHAT=test export TEST_USERNAME=danogentili export TEST_DESTINATION_GROUPS='["@danogentili"]' export MTPROTO_SETTINGS='{"logger":{"logger_level":5}}' -php tools/makephar.php $HOME/phar5 "$TRAVIS_PHAR" $TRAVIS_COMMIT - -curl -s https://api.telegram.org/bot$BOT_TOKEN/sendDocument -F chat_id=101374607 -F document="@$TRAVIS_PHAR" - +php tools/makephar.php $HOME/phar5 "madeline$php$branch.phar" $TRAVIS_COMMIT tests/testing.php < madeline_rsa