1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-10 19:48:16 +01:00

Lighten up

This commit is contained in:
Daniil Gentili 2024-12-10 18:02:50 +00:00
parent d79fca4bed
commit 96080c9467
5 changed files with 11 additions and 43 deletions

View File

@ -136,7 +136,6 @@ final class MTProtoIncomingMessage extends MTProtoMessage
*/ */
public function ack(): void public function ack(): void
{ {
unset($this->connection->incoming_messages[$this->msgId]);
$this->state |= self::STATE_ACKED; $this->state |= self::STATE_ACKED;
if ($this->contentRelated) { if ($this->contentRelated) {
// I let the server know that I received its message // I let the server know that I received its message
@ -155,14 +154,6 @@ final class MTProtoIncomingMessage extends MTProtoMessage
return $content; return $content;
} }
/**
* Check if this message can be garbage collected.
*/
public function canGarbageCollect(): bool
{
return (bool) ($this->state & self::STATE_READ);
}
/** /**
* Get ID of message to which this message replies. * Get ID of message to which this message replies.
*/ */

View File

@ -128,9 +128,4 @@ abstract class MTProtoMessage
return $this; return $this;
} }
/**
* Check whether this message can be garbage collected.
*/
abstract public function canGarbageCollect(): bool;
} }

View File

@ -36,11 +36,11 @@ trait Reliable
*/ */
public function onNewMsgDetailedInfo(array $content): void public function onNewMsgDetailedInfo(array $content): void
{ {
if (isset($this->incoming_messages[$content['answer_msg_id']])) { /*if (isset($this->incoming_messages[$content['answer_msg_id']])) {
$this->incoming_messages[$content['answer_msg_id']]->ack(); $this->incoming_messages[$content['answer_msg_id']]->ack();
} else { } else {
EventLoop::queue($this->objectCall(...), 'msg_resend_req', ['msg_ids' => [$content['answer_msg_id']]]); EventLoop::queue($this->objectCall(...), 'msg_resend_req', ['msg_ids' => [$content['answer_msg_id']]]);
} }*/
} }
/** /**
* Called when receiving a msg_detailed_info. * Called when receiving a msg_detailed_info.
@ -58,7 +58,7 @@ trait Reliable
{ {
$ok = true; $ok = true;
foreach ($content['msg_ids'] as $msg_id) { foreach ($content['msg_ids'] as $msg_id) {
if (!isset($this->outgoing_messages[$msg_id]) || isset($this->incoming_messages[$msg_id])) { if (!isset($this->outgoing_messages[$msg_id])) {
$ok = false; $ok = false;
} }
} }
@ -104,7 +104,7 @@ trait Reliable
*/ */
public function sendMsgsStateInfo(array $msg_ids, int $req_msg_id): void public function sendMsgsStateInfo(array $msg_ids, int $req_msg_id): void
{ {
$this->API->logger('Sending state info for '.\count($msg_ids).' message IDs'); /*$this->API->logger('Sending state info for '.\count($msg_ids).' message IDs');
$info = ''; $info = '';
foreach ($msg_ids as $msg_id) { foreach ($msg_ids as $msg_id) {
$cur_info = 0; $cur_info = 0;
@ -126,6 +126,6 @@ trait Reliable
} }
$info .= \chr($cur_info); $info .= \chr($cur_info);
} }
EventLoop::queue($this->objectCall(...), 'msgs_state_info', ['req_msg_id' => $req_msg_id, 'info' => $info]); EventLoop::queue($this->objectCall(...), 'msgs_state_info', ['req_msg_id' => $req_msg_id, 'info' => $info]);*/
} }
} }

View File

@ -154,7 +154,7 @@ trait ResponseHandler
$newMessage->setSeqNo(null); $newMessage->setSeqNo(null);
$tmp->enqueue($newMessage); $tmp->enqueue($newMessage);
$this->incomingCtr?->inc(); $this->incomingCtr?->inc();
$this->incoming_messages[$msg['msg_id']] = $newMessage; //$this->incoming_messages[$msg['msg_id']] = $newMessage;
} }
$this->checkInSeqNo($message); $this->checkInSeqNo($message);
$this->handleMessages($tmp); $this->handleMessages($tmp);
@ -163,15 +163,15 @@ trait ResponseHandler
{ {
$content = $message->read(); $content = $message->read();
$referencedMsgId = $content['msg_id']; $referencedMsgId = $content['msg_id'];
if (isset($this->incoming_messages[$referencedMsgId])) { /*if (isset($this->incoming_messages[$referencedMsgId])) {
$this->incoming_messages[$referencedMsgId]->ack(); $this->incoming_messages[$referencedMsgId]->ack();
} else { } else {*/
$this->msgIdHandler->checkIncomingMessageId($referencedMsgId, true); $this->msgIdHandler->checkIncomingMessageId($referencedMsgId, true);
$message = new MTProtoIncomingMessage($this, $content['orig_message'], $referencedMsgId, $message->unencrypted); $message = new MTProtoIncomingMessage($this, $content['orig_message'], $referencedMsgId, $message->unencrypted);
$this->incomingCtr?->inc(); $this->incomingCtr?->inc();
$this->incoming_messages[$referencedMsgId] = $message; //$this->incoming_messages[$referencedMsgId] = $message;
$this->handleMessages([$message]); $this->handleMessages([$message]);
} //}
} }
/** /**

View File

@ -57,7 +57,7 @@ trait Session
* *
* @var array<MTProtoIncomingMessage> * @var array<MTProtoIncomingMessage>
*/ */
public array $incoming_messages = []; //public array $incoming_messages = [];
/** /**
* Outgoing message array. * Outgoing message array.
* *
@ -155,24 +155,6 @@ trait Session
*/ */
public function cleanupSession(): void public function cleanupSession(): void
{ {
$count = 0;
$incoming = [];
foreach ($this->incoming_messages as $key => $message) {
if ($message->canGarbageCollect()) {
$this->API->logger("Collecting incoming $message in DC {$this->datacenter}", Logger::VERBOSE);
$count++;
} else {
$this->API->logger("Can't garbage collect $message in DC {$this->datacenter}, not handled yet!", Logger::VERBOSE);
$incoming[$key] = $message;
}
}
$this->incoming_messages = $incoming;
$total = \count($this->incoming_messages);
if ($count+$total) {
$this->API->logger("Garbage collected $count incoming messages in DC {$this->datacenter}, $total left", Logger::VERBOSE);
}
$count = 0; $count = 0;
$outgoing = []; $outgoing = [];
foreach ($this->outgoing_messages as $key => $message) { foreach ($this->outgoing_messages as $key => $message) {