1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-12-02 14:57:48 +01:00

Fix shutdown loop, automatically inflate stripped photoSizes, improve composer reporter

This commit is contained in:
Daniil Gentili 2020-06-23 20:30:40 +02:00
parent 58e0985d33
commit bfd08f5744
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
10 changed files with 85 additions and 67 deletions

View File

@ -52,7 +52,8 @@
"danog/7to70": "^1", "danog/7to70": "^1",
"danog/7to5": "^1", "danog/7to5": "^1",
"vimeo/psalm": "dev-master", "vimeo/psalm": "dev-master",
"phpstan/phpstan": "^0.12.14" "phpstan/phpstan": "^0.12.14",
"friendsofphp/php-cs-fixer": "^2.16"
}, },
"suggest": { "suggest": {
"ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https://github.com/danog/php-libtgvoip)" "ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https://github.com/danog/php-libtgvoip)"

View File

@ -84,6 +84,7 @@ class MyEventHandler extends EventHandler
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') { if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {
yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]); yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]);
} }
yield $this->ping(['multiple' => true] + \array_map(fn ($v) => ['ping_id' => $v], \range(0, 1020)));
} }
} }
$settings = [ $settings = [

View File

@ -184,7 +184,7 @@ class API extends InternalDoc
$this->API->unreference(); $this->API->unreference();
} }
$this->destructing = true; $this->destructing = true;
Tools::wait($this->wrapper->serialize(), true); Tools::wait($this->wrapper->serialize());
} else { } else {
$this->logger->logger('Shutting down MadelineProto (old deserialized instance of API)'); $this->logger->logger('Shutting down MadelineProto (old deserialized instance of API)');
} }

View File

@ -137,7 +137,7 @@ class DocsBuilder
foreach (['string', 'bytes', 'int', 'int53', 'long', 'int128', 'int256', 'int512', 'double', 'Bool', 'DataJSON'] as $type) { foreach (['string', 'bytes', 'int', 'int53', 'long', 'int128', 'int256', 'int512', 'double', 'Bool', 'DataJSON'] as $type) {
\file_put_contents("types/$type.md", $this->templates[$type]); \file_put_contents("types/$type.md", $this->templates[$type]);
} }
foreach (['boolFalse', 'boolTrue', 'null'] as $constructor) { foreach (['boolFalse', 'boolTrue', 'null', 'photoStrippedSize'] as $constructor) {
\file_put_contents("constructors/$constructor.md", $this->templates[$constructor]); \file_put_contents("constructors/$constructor.md", $this->templates[$constructor]);
} }
\danog\MadelineProto\Logger::log('Done!', \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log('Done!', \danog\MadelineProto\Logger::NOTICE);

View File

@ -72,12 +72,16 @@ class CheckLoop extends ResumableSignalLoop
return; return;
} }
} }
if ($connection->hasPendingCalls()) { if (!$connection->hasPendingCalls()) {
if (yield $this->waitSignal($this->pause($timeout))) {
return;
}
continue;
}
$last_msgid = $connection->msgIdHandler->getMaxId(true); $last_msgid = $connection->msgIdHandler->getMaxId(true);
$last_chunk = $connection->getLastChunk(); $last_chunk = $connection->getLastChunk();
if ($shared->hasTempAuthKey()) { if ($shared->hasTempAuthKey()) {
$full_message_ids = $connection->getPendingCalls(); $full_message_ids = $connection->getPendingCalls();
//array_values($connection->new_outgoing);
foreach (\array_chunk($full_message_ids, 8192) as $message_ids) { foreach (\array_chunk($full_message_ids, 8192) as $message_ids) {
$deferred = new Deferred(); $deferred = new Deferred();
$deferred->promise()->onResolve(function ($e, $result) use ($message_ids, $API, $connection, $datacenter, $timeoutResend) { $deferred->promise()->onResolve(function ($e, $result) use ($message_ids, $API, $connection, $datacenter, $timeoutResend) {
@ -163,11 +167,6 @@ class CheckLoop extends ResumableSignalLoop
Tools::callForkDefer($connection->reconnect()); Tools::callForkDefer($connection->reconnect());
return; return;
} }
} else {
if (yield $this->waitSignal($this->pause($timeout))) {
return;
}
}
} }
} }
public function __toString(): string public function __toString(): string

View File

@ -223,7 +223,6 @@ class ReadLoop extends SignalLoop
$connection->incoming_messages[$message_id]['content'] = $deserialized; $connection->incoming_messages[$message_id]['content'] = $deserialized;
$connection->incoming_messages[$message_id]['response'] = -1; $connection->incoming_messages[$message_id]['response'] = -1;
$connection->new_incoming[$message_id] = $message_id; $connection->new_incoming[$message_id] = $message_id;
//$connection->last_http_wait = 0;
$API->logger->logger('Received payload from DC '.$datacenter, Logger::ULTRA_VERBOSE); $API->logger->logger('Received payload from DC '.$datacenter, Logger::ULTRA_VERBOSE);
} finally { } finally {
$connection->reading(false); $connection->reading(false);

View File

@ -1870,7 +1870,11 @@ class MTProto extends AsyncConstruct implements TLCallback
*/ */
public function getConstructorCallbacks(): array public function getConstructorCallbacks(): array
{ {
return \array_merge(\array_fill_keys(['chat', 'chatEmpty', 'chatForbidden', 'channel', 'channelEmpty', 'channelForbidden'], [[$this, 'addChat']]), \array_fill_keys(['user', 'userEmpty'], [[$this, 'addUser']]), ['help.support' => [[$this, 'addSupport']]]); return \array_merge(
\array_fill_keys(['chat', 'chatEmpty', 'chatForbidden', 'channel', 'channelEmpty', 'channelForbidden'], [[$this, 'addChat']]),
\array_fill_keys(['user', 'userEmpty'], [[$this, 'addUser']]),
['help.support' => [[$this, 'addSupport']]]
);
} }
/** /**
* Called right before deserialization of object. * Called right before deserialization of object.

View File

@ -82,6 +82,18 @@ abstract class Session
* @var array * @var array
*/ */
public $ack_queue = []; public $ack_queue = [];
/**
* State request queue.
*
* @var array
*/
public $state_queue = [];
/**
* Resend request queue.
*
* @var array
*/
public $resend_queue = [];
/** /**
* Message ID handler. * Message ID handler.
* *

View File

@ -995,6 +995,8 @@ class TL
default: default:
return $x['value']; return $x['value'];
} }
} elseif ($x['_'] === 'photoStrippedSize') {
$x['inflated'] = Tools::inflateStripped($x['bytes']);
} }
if (isset($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']])) { if (isset($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']])) {
foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) { foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) {

View File

@ -116,7 +116,7 @@ function ___install_madeline()
]; ];
} }
if (defined('HHVM_VERSION')) { if (\defined('HHVM_VERSION')) {
$phpVersion = 'HHVM ' . HHVM_VERSION; $phpVersion = 'HHVM ' . HHVM_VERSION;
} else { } else {
$phpVersion = 'PHP ' . PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION; $phpVersion = 'PHP ' . PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
@ -126,14 +126,14 @@ function ___install_madeline()
'method' => 'POST', 'method' => 'POST',
'header' => [ 'header' => [
'Content-Type: application/json', 'Content-Type: application/json',
sprintf( \sprintf(
'User-Agent: Composer/%s (%s; %s; %s; %s%s)', 'User-Agent: Composer/%s (%s; %s; %s; %s%s)',
'MadelineProto', 'MadelineProto',
function_exists('php_uname') ? @php_uname('s') : 'Unknown', \function_exists('php_uname') ? @\php_uname('s') : 'Unknown',
function_exists('php_uname') ? @php_uname('r') : 'Unknown', \function_exists('php_uname') ? @\php_uname('r') : 'Unknown',
$phpVersion, $phpVersion,
'streams', 'streams',
getenv('CI') ? '; CI' : '' \getenv('CI') ? '; CI' : ''
) )
], ],
'content' => \json_encode($postData), 'content' => \json_encode($postData),