1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-10 20:48:20 +01:00
This commit is contained in:
Daniil Gentili 2024-12-10 18:08:48 +00:00
parent 96080c9467
commit 7bfd04dce3
5 changed files with 12 additions and 85 deletions

View File

@ -28,7 +28,6 @@ use AssertionError;
use danog\DialogId\DialogId; use danog\DialogId\DialogId;
use danog\Loop\GenericLoop; use danog\Loop\GenericLoop;
use danog\MadelineProto\Loop\Connection\CleanupLoop; use danog\MadelineProto\Loop\Connection\CleanupLoop;
use danog\MadelineProto\Loop\Connection\HttpWaitLoop;
use danog\MadelineProto\Loop\Connection\ReadLoop; use danog\MadelineProto\Loop\Connection\ReadLoop;
use danog\MadelineProto\Loop\Connection\WriteLoop; use danog\MadelineProto\Loop\Connection\WriteLoop;
use danog\MadelineProto\MTProto\MTProtoIncomingMessage; use danog\MadelineProto\MTProto\MTProtoIncomingMessage;
@ -71,11 +70,6 @@ final class Connection
* *
*/ */
protected ?ReadLoop $reader = null; protected ?ReadLoop $reader = null;
/**
* Waiter loop.
*
*/
protected ?HttpWaitLoop $waiter = null;
/** /**
* Cleanup loop. * Cleanup loop.
* *

View File

@ -1,66 +0,0 @@
<?php
declare(strict_types=1);
/**
* HttpWait loop.
*
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
* @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 <daniil@daniil.it>
*/
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}";
}
}

View File

@ -265,7 +265,6 @@ final class WriteLoop extends Loop
$has_state = false; $has_state = false;
$has_resend = false; $has_resend = false;
$has_http_wait = false;
foreach ($this->connection->pendingOutgoing as $k => $message) { foreach ($this->connection->pendingOutgoing as $k => $message) {
if ($message->unencrypted) { if ($message->unencrypted) {
continue; continue;
@ -282,14 +281,11 @@ final class WriteLoop extends Loop
continue; continue;
} }
$constructor = $message->constructor; $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"); $this->API->logger("Skipping $message due to unbound keys in DC $this->datacenter");
$skipped = true; $skipped = true;
continue; continue;
} }
if ($constructor === 'http_wait') {
$has_http_wait = true;
}
if ($constructor === 'msgs_state_req') { if ($constructor === 'msgs_state_req') {
if ($has_state) { if ($has_state) {
$this->API->logger("Already have a state request queued for the current container in DC {$this->datacenter}"); $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(), 'body' => $message->getSerializedBody(),
'seqno' => $message->getSeqNo() ?? $this->connection->generateOutSeqNo($message->contentRelated), '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 (!$this->shared->getTempAuthKey()->isInited()) {
if ($constructor === 'help.getConfig' || $constructor === 'upload.getCdnFile') { if ($constructor === 'help.getConfig' || $constructor === 'upload.getCdnFile') {
$this->API->logger(sprintf('Writing client info (also executing %s)...', $constructor), Logger::NOTICE); $this->API->logger(sprintf('Writing client info (also executing %s)...', $constructor), Logger::NOTICE);
@ -417,7 +413,7 @@ final class WriteLoop extends Loop
$count++; $count++;
unset($acks, $body); unset($acks, $body);
} }
if ($this->connection->isHttp() && !$has_http_wait) { if ($this->connection->isHttp()) {
$this->API->logger('Adding http_wait', Logger::ULTRA_VERBOSE); $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'); $body = $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait');
$messages []= [ $messages []= [

View File

@ -182,7 +182,7 @@ class MTProtoOutgoingMessage extends MTProtoMessage
} }
$this->state |= self::STATE_SENT; $this->state |= self::STATE_SENT;
$this->sent = hrtime(true); $this->sent = hrtime(true);
if (!$this instanceof Container) { if ($this->contentRelated) {
$this->checkTimer = EventLoop::delay( $this->checkTimer = EventLoop::delay(
$this->connection->API->getSettings()->getConnection()->getTimeout(), $this->connection->API->getSettings()->getConnection()->getTimeout(),
$this->check(...) $this->check(...)
@ -287,6 +287,9 @@ class MTProtoOutgoingMessage extends MTProtoMessage
public function ack(): void public function ack(): void
{ {
$this->state |= self::STATE_ACKED; $this->state |= self::STATE_ACKED;
if (!$this->resultDeferred) {
$this->reply(null);
}
} }
/** /**
* Get state of message. * Get state of message.