Fix TL serializer bugs

This commit is contained in:
Daniil Gentili 2019-12-25 21:01:53 +01:00
parent d4d45b1dc9
commit b44e23cee8
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
7 changed files with 17 additions and 17 deletions

View File

@ -441,7 +441,7 @@ class Connection extends Session
if ($message['method']) {
$body = yield $this->API->getTL()->serializeMethod($message['_'], $body);
} else {
$body = yield $this->API->getTL()->serializeObject(['type' => $message['_']], $body, $message['_']);
$body = yield $this->API->getTL()->serializeObject(['type' => ''], $body, $message['_']);
}
if ($refreshNext) {
$this->API->referenceDatabase->refreshNext(false);

View File

@ -182,7 +182,7 @@ class WriteLoop extends ResumableSignalLoop
$temporary_keys = [];
if (\count($to_ack = $connection->ack_queue)) {
foreach (\array_chunk($connection->ack_queue, 8192) as $acks) {
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'msgs_ack', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => 'msgs_ack'], ['msg_ids' => $acks], 'msgs_ack'), 'contentRelated' => false, 'unencrypted' => false, 'method' => false];
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'msgs_ack', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'msgs_ack','msg_ids' => $acks], 'msgs_ack'), 'contentRelated' => false, 'unencrypted' => false, 'method' => false];
$temporary_keys[$connection->pending_outgoing_key] = true;
$API->logger->logger("Adding msgs_ack {$connection->pending_outgoing_key}", Logger::ULTRA_VERBOSE);
$connection->pending_outgoing_key++;
@ -280,7 +280,7 @@ class WriteLoop extends ResumableSignalLoop
// TODO
/* if ($API->settings['requests']['gzip_encode_if_gt'] !== -1 && ($l = strlen($MTmessage['body'])) > $API->settings['requests']['gzip_encode_if_gt']) {
if (($g = strlen($gzipped = gzencode($MTmessage['body']))) < $l) {
$MTmessage['body'] = yield $API->getTL()->serializeObject(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
$MTmessage['body'] = yield $API->getTL()->serializeObject(['type' => ''], ['_' => 'gzip_packed', 'packed_data' => $gzipped], 'gzipped data');
$API->logger->logger('Using GZIP compression for ' . $message['_'] . ', saved ' . ($l - $g) . ' bytes of data, reduced call size by ' . $g * 100 / $l . '%', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
}
unset($gzipped);

View File

@ -186,8 +186,8 @@ trait AuthKeyHandler
$q_bytes = $q->toBytes();
$new_nonce = \danog\MadelineProto\Tools::random(32);
$data_unserialized = ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, 'expires_in' => $expires_in, 'dc' => \preg_replace('|_.*|', '', $datacenter)];
$p_q_inner_data = yield $this->TL->serializeObject(['type' => 'p_q_inner_data'.($expires_in < 0 ? '' : '_temp')], $data_unserialized, 'p_q_inner_data');
$data_unserialized = ['_' => 'p_q_inner_data'.($expires_in < 0 ? '' : '_temp'), 'pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, 'expires_in' => $expires_in, 'dc' => \preg_replace('|_.*|', '', $datacenter)];
$p_q_inner_data = yield $this->TL->serializeObject(['type' => ''], $data_unserialized, 'p_q_inner_data');
/*
* ***********************************************************************
* Encrypt serialized object
@ -324,7 +324,7 @@ trait AuthKeyHandler
* string $g_b : g^b mod dh_prime
* ]
*/
$data = yield $this->TL->serializeObject(['type' => 'client_DH_inner_data'], ['nonce' => $nonce, 'server_nonce' => $server_nonce, 'retry_id' => $retry_id, 'g_b' => $g_b_str], 'client_DH_inner_data');
$data = yield $this->TL->serializeObject(['type' => ''], ['_' => 'client_DH_inner_data', 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'retry_id' => $retry_id, 'g_b' => $g_b_str], 'client_DH_inner_data');
/*
* ***********************************************************************
* encrypt client_DH_inner_data
@ -554,7 +554,7 @@ trait AuthKeyHandler
$temp_auth_key_id = $datacenterConnection->getTempAuthKey()->getID();
$perm_auth_key_id = $datacenterConnection->getPermAuthKey()->getID();
$temp_session_id = $connection->session_id;
$message_data = yield $this->TL->serializeObject(['type' => 'bind_auth_key_inner'], ['nonce' => $nonce, 'temp_auth_key_id' => $temp_auth_key_id, 'perm_auth_key_id' => $perm_auth_key_id, 'temp_session_id' => $temp_session_id, 'expires_at' => $expires_at], 'bindTempAuthKey_inner');
$message_data = yield $this->TL->serializeObject(['type' => ''], ['_' => 'bind_auth_key_inner','nonce' => $nonce, 'temp_auth_key_id' => $temp_auth_key_id, 'perm_auth_key_id' => $perm_auth_key_id, 'temp_session_id' => $temp_session_id, 'expires_at' => $expires_at], 'bindTempAuthKey_inner');
$message_id = $connection->generateMessageId();
$seq_no = 0;
$encrypted_data = \danog\MadelineProto\Tools::random(16).$message_id.\pack('VV', $seq_no, \strlen($message_data)).$message_data;

View File

@ -236,9 +236,9 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
public function getReadBufferGenerator(&$length): \Generator
{
//if ($this->read_hash) {
$this->read_buffer = yield $this->stream->getReadBuffer($length);
$this->read_buffer = yield $this->stream->getReadBuffer($length);
return $this;
return $this;
//}
//return yield $this->stream->getReadBuffer($length);
@ -254,9 +254,9 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
//if ($this->write_hash) {
$this->write_buffer = yield $this->stream->getWriteBuffer($length, $append);
$this->write_buffer = yield $this->stream->getWriteBuffer($length, $append);
return $this;
return $this;
//}
//return yield $this->stream->getWriteBuffer($length, $append);

View File

@ -23,7 +23,6 @@ use danog\MadelineProto\Stream\BufferedProxyStreamInterface;
use danog\MadelineProto\Stream\Common\CtrStream;
use danog\MadelineProto\Stream\ConnectionContext;
/**
* Obfuscated2 stream wrapper.
*

View File

@ -105,10 +105,11 @@ class Lite
}
}
public function methodCall(string $methodName, array $args = [], array $aargs = []) {
public function methodCall(string $methodName, array $args = [], array $aargs = [])
{
$data = yield $this->TL->serializeMethod($methodName, $args);
$data = yield $this->TL->serializeMethod('liteServer.query', ['data' => $data]);
return yield $this->connections[rand(0, count($this->connections) - 1)]->query($data);
return yield $this->connections[\rand(0, \count($this->connections) - 1)]->query($data);
}
/**
@ -134,9 +135,9 @@ class Lite
{
return $parameters;
}
/**
* Get TL method namespaces
* Get TL method namespaces.
*
* @return void
*/

View File

@ -17,6 +17,6 @@ $API->async(true);
$API->loop(
function () use ($API) {
yield $API->connect(__DIR__.'/ton-lite-client-test1.config.json');
var_dump(yield $API->liteServer->getTime());
\var_dump(yield $API->liteServer->getTime());
}
);