From cfa546d7f7d94575ee539ab1ddbbc823cdb2ee92 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 10 Dec 2024 17:55:48 +0000 Subject: [PATCH] Cleanup --- src/Connection.php | 4 +++- src/Loop/Connection/ReadLoop.php | 4 +--- src/MTProto/MTProtoIncomingMessage.php | 1 + src/MTProtoSession/ResponseHandler.php | 3 --- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 9849fee8a..078c3ec14 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -31,6 +31,7 @@ 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; use danog\MadelineProto\MTProto\MTProtoOutgoingMessage; use danog\MadelineProto\MTProtoSession\Session; use danog\MadelineProto\Stream\BufferedStreamInterface; @@ -307,8 +308,9 @@ final class Connection EventLoop::queue($lock->release(...)); } } - public function wakeupHandler(): void + public function wakeupHandler(MTProtoIncomingMessage $message): void { + $this->new_incoming->enqueue($message); \assert($this->handler !== null); Assert::true($this->handler->resume() || $this->handler->isRunning(), "Could not resume handler!"); } diff --git a/src/Loop/Connection/ReadLoop.php b/src/Loop/Connection/ReadLoop.php index daa444f0b..855c5ac45 100644 --- a/src/Loop/Connection/ReadLoop.php +++ b/src/Loop/Connection/ReadLoop.php @@ -120,7 +120,6 @@ final class ReadLoop extends Loop return self::STOP; } $this->connection->httpReceived(); - $this->connection->wakeupHandler(); return self::CONTINUE; } public function readMessage(): ?int @@ -251,8 +250,7 @@ final class ReadLoop extends Loop $message->setSeqNo($seq_no); } - $this->connection->new_incoming->enqueue($message); - $this->connection->incoming_messages[$message_id] = $message; + $this->connection->wakeupHandler($message); $this->connection->incomingCtr?->inc(); } finally { $this->connection->reading(false); diff --git a/src/MTProto/MTProtoIncomingMessage.php b/src/MTProto/MTProtoIncomingMessage.php index 015559344..1bd4f76ea 100644 --- a/src/MTProto/MTProtoIncomingMessage.php +++ b/src/MTProto/MTProtoIncomingMessage.php @@ -147,6 +147,7 @@ final class MTProtoIncomingMessage extends MTProtoMessage */ public function read(): array { + $this->ack(); $this->state |= self::STATE_READ; $content = $this->content; $this->content = ['_' => $content['_']]; diff --git a/src/MTProtoSession/ResponseHandler.php b/src/MTProtoSession/ResponseHandler.php index a89344cfb..39dec0046 100644 --- a/src/MTProtoSession/ResponseHandler.php +++ b/src/MTProtoSession/ResponseHandler.php @@ -135,7 +135,6 @@ trait ResponseHandler } private function handleNewSession(MTProtoIncomingMessage $message): void { - $message->ack(); $this->shared->getTempAuthKey()->setServerSalt($message->read()['server_salt']); if ($this->API->authorized === \danog\MadelineProto\API::LOGGED_IN && isset($this->API->updaters[UpdateLoop::GENERIC]) @@ -162,7 +161,6 @@ trait ResponseHandler } private function handleMsgCopy(MTProtoIncomingMessage $message): void { - $message->ack(); $content = $message->read(); $referencedMsgId = $content['msg_id']; if (isset($this->incoming_messages[$referencedMsgId])) { @@ -187,7 +185,6 @@ trait ResponseHandler if ($message->unencrypted) { throw new SecurityException("Can't accept unencrypted result!"); } - $message->ack(); $response = $response['result']; } if (!isset($this->outgoing_messages[$requestId])) {