diff --git a/src/Connection.php b/src/Connection.php index 078c3ec14..03e34cde6 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -28,7 +28,6 @@ use AssertionError; use danog\DialogId\DialogId; use danog\Loop\GenericLoop; use danog\MadelineProto\Loop\Connection\CleanupLoop; -use danog\MadelineProto\Loop\Connection\HttpWaitLoop; use danog\MadelineProto\Loop\Connection\ReadLoop; use danog\MadelineProto\Loop\Connection\WriteLoop; use danog\MadelineProto\MTProto\MTProtoIncomingMessage; @@ -71,11 +70,6 @@ final class Connection * */ protected ?ReadLoop $reader = null; - /** - * Waiter loop. - * - */ - protected ?HttpWaitLoop $waiter = null; /** * Cleanup loop. * diff --git a/src/Loop/Connection/HttpWaitLoop.php b/src/Loop/Connection/HttpWaitLoop.php deleted file mode 100644 index 4cc2849ef..000000000 --- a/src/Loop/Connection/HttpWaitLoop.php +++ /dev/null @@ -1,66 +0,0 @@ -. - * - * @author Daniil Gentili - * @copyright 2016-2023 Daniil Gentili - * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 - * @link https://docs.madelineproto.xyz MadelineProto documentation - */ - -namespace danog\MadelineProto\Loop\Connection; - -use danog\Loop\Loop; - -/** - * HttpWait loop. - * - * @internal - * - * @author Daniil Gentili - */ -final class HttpWaitLoop extends Loop -{ - use Common; - /** - * Main loop. - */ - protected function loop(): ?float - { - if (!$this->connection->isHttp()) { - return self::STOP; - } - if (!$this->shared->hasTempAuthKey()) { - return self::PAUSE; - } - $this->API->logger("DC {$this->datacenter}: request {$this->connection->countHttpSent()}, response {$this->connection->countHttpReceived()}"); - if ($this->connection->countHttpSent() === $this->connection->countHttpReceived() - && ($this->connection->pendingOutgoing || $this->connection->new_outgoing) - && !$this->connection->hasPendingCalls() - ) { - $this->connection->objectCall( - 'http_wait', - ['max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], - ); - } - $this->API->logger("DC {$this->datacenter}: request {$this->connection->countHttpSent()}, response {$this->connection->countHttpReceived()}"); - return self::PAUSE; - } - /** - * Loop name. - */ - public function __toString(): string - { - return "HTTP wait loop in DC {$this->datacenter}"; - } -} diff --git a/src/Loop/Connection/WriteLoop.php b/src/Loop/Connection/WriteLoop.php index 17af53cfc..197132c8e 100644 --- a/src/Loop/Connection/WriteLoop.php +++ b/src/Loop/Connection/WriteLoop.php @@ -265,7 +265,6 @@ final class WriteLoop extends Loop $has_state = false; $has_resend = false; - $has_http_wait = false; foreach ($this->connection->pendingOutgoing as $k => $message) { if ($message->unencrypted) { continue; @@ -282,14 +281,11 @@ final class WriteLoop extends Loop continue; } $constructor = $message->constructor; - if ($this->shared->getGenericSettings()->getAuth()->getPfs() && !$this->shared->isBound() && !$this->connection->isCDN() && $message->isMethod && !\in_array($constructor, ['http_wait', 'auth.bindTempAuthKey'], true)) { + if ($this->shared->getGenericSettings()->getAuth()->getPfs() && !$this->shared->isBound() && !$this->connection->isCDN() && $message->isMethod && $constructor !== 'auth.bindTempAuthKey') { $this->API->logger("Skipping $message due to unbound keys in DC $this->datacenter"); $skipped = true; continue; } - if ($constructor === 'http_wait') { - $has_http_wait = true; - } if ($constructor === 'msgs_state_req') { if ($has_state) { $this->API->logger("Already have a state request queued for the current container in DC {$this->datacenter}"); @@ -322,7 +318,7 @@ final class WriteLoop extends Loop 'body' => $message->getSerializedBody(), 'seqno' => $message->getSeqNo() ?? $this->connection->generateOutSeqNo($message->contentRelated), ]; - if ($message->isMethod && $constructor !== 'http_wait' && $constructor !== 'ping_delay_disconnect' && $constructor !== 'auth.bindTempAuthKey') { + if ($message->isMethod && $constructor !== 'ping_delay_disconnect' && $constructor !== 'auth.bindTempAuthKey') { if (!$this->shared->getTempAuthKey()->isInited()) { if ($constructor === 'help.getConfig' || $constructor === 'upload.getCdnFile') { $this->API->logger(sprintf('Writing client info (also executing %s)...', $constructor), Logger::NOTICE); @@ -417,7 +413,7 @@ final class WriteLoop extends Loop $count++; unset($acks, $body); } - if ($this->connection->isHttp() && !$has_http_wait) { + if ($this->connection->isHttp()) { $this->API->logger('Adding http_wait', Logger::ULTRA_VERBOSE); $body = $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'); $messages []= [ diff --git a/src/MTProto/MTProtoOutgoingMessage.php b/src/MTProto/MTProtoOutgoingMessage.php index 1db23f786..37b45d4d3 100644 --- a/src/MTProto/MTProtoOutgoingMessage.php +++ b/src/MTProto/MTProtoOutgoingMessage.php @@ -182,7 +182,7 @@ class MTProtoOutgoingMessage extends MTProtoMessage } $this->state |= self::STATE_SENT; $this->sent = hrtime(true); - if (!$this instanceof Container) { + if ($this->contentRelated) { $this->checkTimer = EventLoop::delay( $this->connection->API->getSettings()->getConnection()->getTimeout(), $this->check(...) @@ -287,6 +287,9 @@ class MTProtoOutgoingMessage extends MTProtoMessage public function ack(): void { $this->state |= self::STATE_ACKED; + if (!$this->resultDeferred) { + $this->reply(null); + } } /** * Get state of message. diff --git a/src/MTProtoSession/ResponseHandler.php b/src/MTProtoSession/ResponseHandler.php index 6fb0a19e4..71f42766c 100644 --- a/src/MTProtoSession/ResponseHandler.php +++ b/src/MTProtoSession/ResponseHandler.php @@ -166,11 +166,11 @@ trait ResponseHandler /*if (isset($this->incoming_messages[$referencedMsgId])) { $this->incoming_messages[$referencedMsgId]->ack(); } else {*/ - $this->msgIdHandler->checkIncomingMessageId($referencedMsgId, true); - $message = new MTProtoIncomingMessage($this, $content['orig_message'], $referencedMsgId, $message->unencrypted); - $this->incomingCtr?->inc(); - //$this->incoming_messages[$referencedMsgId] = $message; - $this->handleMessages([$message]); + $this->msgIdHandler->checkIncomingMessageId($referencedMsgId, true); + $message = new MTProtoIncomingMessage($this, $content['orig_message'], $referencedMsgId, $message->unencrypted); + $this->incomingCtr?->inc(); + //$this->incoming_messages[$referencedMsgId] = $message; + $this->handleMessages([$message]); //} }