1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 09:38:57 +01:00

Split side effects (fixes reference database issues)

This commit is contained in:
Daniil Gentili 2023-01-22 17:42:04 +01:00
parent c400bfb236
commit ae8e5308f4
6 changed files with 27 additions and 14 deletions

View File

@ -143,7 +143,7 @@ final class IncomingMessage extends Message
*/
public function __toString(): string
{
return $this->content['_'];
return "incoming message {$this->content['_']}";
}
/**

View File

@ -424,11 +424,17 @@ class OutgoingMessage extends Message
*/
public function __toString(): string
{
$state = match ($this->state) {
self::STATE_PENDING => 'pending',
self::STATE_SENT => "sent ".(\time() - $this->sent)." seconds ago",
self::STATE_ACKED => 'acked',
self::STATE_REPLIED => 'acked (by reply)',
};
if ($this->msgId) {
$msgId = MsgIdHandler::toString($this->msgId);
return "{$this->constructor} with message ID $msgId";
return "{$this->constructor} with message ID $msgId $state";
}
return $this->constructor;
return "{$this->constructor} $state";
}
/**

View File

@ -81,12 +81,11 @@ trait ResponseHandler
}
break;
case 'msg_container':
$side = $message->consumeSideEffects();
foreach ($message->read()['messages'] as $message) {
$this->msgIdHandler->checkMessageId($message['msg_id'], ['outgoing' => false, 'container' => true]);
$newMessage = new IncomingMessage($message['body'], $message['msg_id'], true);
$newMessage->setSeqNo($message['seqno']);
$newMessage->setSideEffects($side);
$newMessage->setSideEffects($message['sideEffects']);
$this->new_incoming[$message['msg_id']] = $this->incoming_messages[$message['msg_id']] = $newMessage;
}
unset($newMessage, $message);
@ -386,7 +385,7 @@ trait ResponseHandler
$this->logger->logger("Flood, waiting $seconds seconds before repeating async call of $request...", Logger::NOTICE);
$this->gotResponseForOutgoingMessage($request);
$msgId = $request->getMsgId();
$request->setSent(($request->getSent() ?? \time()) + $seconds);
$request->setSent(\time() + $seconds);
$request->setMsgId(null);
$request->setSeqNo(null);
EventLoop::delay((float) $seconds, fn () => $this->methodRecall(['message_id' => $msgId]));

View File

@ -143,7 +143,7 @@ trait Session
} else {
$ago = \time() - $message->getSent();
if ($ago > 2) {
$this->API->logger->logger("Can't garbage collect $message in DC {$this->datacenter} sent $ago seconds ago, no response has been received or it wasn't yet handled!", Logger::VERBOSE);
$this->API->logger->logger("Can't garbage collect $message in DC {$this->datacenter}, no response has been received or it wasn't yet handled!", Logger::VERBOSE);
}
$outgoing[$key] = $message;
}

View File

@ -212,7 +212,7 @@ final class ReferenceDatabase implements TLCallback
throw new Exception("Unknown origin type provided: {$type}");
}
$originContext = self::CONSTRUCTOR_CONTEXT[$type];
$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
//$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->cacheContexts[] = $originContext;
}
public function addOrigin(array $data = []): void
@ -301,7 +301,7 @@ final class ReferenceDatabase implements TLCallback
throw new Exception("Unknown origin type provided: {$type}");
}
$originContext = self::METHOD_CONTEXT[$type];
$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", Logger::ULTRA_VERBOSE);
//$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", Logger::ULTRA_VERBOSE);
$this->cacheContexts[] = $originContext;
}
public function addOriginMethod(OutgoingMessage $data, array $res): void

View File

@ -942,8 +942,16 @@ final class TL
$count = \unpack('V', \stream_get_contents($stream, 4))[1];
$result = [];
$type['type'] = $type['subtype'];
$splitSideEffects = isset($type['splitSideEffects']);
if ($splitSideEffects) {
unset($type['splitSideEffects']);
}
for ($i = 0; $i < $count; $i++) {
$result[] = $this->deserialize($stream, $type);
$v = $this->deserialize($stream, $type);
if ($splitSideEffects) {
$v['sideEffects'] = $this->getSideEffects();
}
$result[] = $v;
}
return $result;
}
@ -1019,11 +1027,9 @@ final class TL
}
if (\in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id'])) {
$arg['idstrlong'] = true;
}
if (\in_array($arg['name'], ['key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints', 'ping_id', 'exchange_id'])) {
} elseif (\in_array($arg['name'], ['key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints', 'ping_id', 'exchange_id'])) {
$arg['strlong'] = true;
}
if (\in_array($arg['name'], ['peer_tag', 'file_token', 'cdn_key', 'cdn_iv'])) {
} elseif (\in_array($arg['name'], ['peer_tag', 'file_token', 'cdn_key', 'cdn_iv'])) {
$arg['type'] = 'string';
}
if ($x['_'] === 'rpc_result' && $arg['name'] === 'result' && isset($type['connection']->outgoing_messages[$x['req_msg_id']])) {
@ -1035,6 +1041,8 @@ final class TL
if ($message->getType() && \stripos($message->getType(), '<') !== false) {
$arg['subtype'] = \str_replace(['Vector<', '>'], '', $message->getType());
}
} elseif ($x['_'] === 'msg_container' && $arg['name'] === 'messages') {
$arg['splitSideEffects'] = true;
}
if (isset($type['connection'])) {
$arg['connection'] = $type['connection'];