This commit is contained in:
Daniil Gentili 2020-07-12 01:27:26 +02:00
parent 45067af046
commit a6fdf813c4
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
11 changed files with 33 additions and 24 deletions

View File

@ -479,6 +479,12 @@ class DataCenterConnection implements JsonSerializable
$count = \count($backup);
$this->API->logger->logger("Restoring {$count} messages to DC {$this->datacenter}");
foreach ($backup as $message) {
if (isset($message['seqno'])) {
unset($message['seqno']);
}
if (isset($message['msg_id'])) {
unset($message['msg_id']);
}
if (isset($message['body'])) {
Tools::callFork($this->getConnection()->sendMessage($message, false));
}

View File

@ -21,13 +21,10 @@ namespace danog\MadelineProto\Ipc;
use Amp\Deferred;
use Amp\Ipc\Sync\ChannelledSocket;
use danog\MadelineProto\API;
use danog\MadelineProto\Async\AsyncConstruct;
use danog\MadelineProto\Exception;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Tools;
use function Amp\Ipc\connect;
/**
* IPC client.
*/

View File

@ -35,7 +35,7 @@ final class ExitFailure
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->trace = flattenThrowableBacktrace($exception);
if (method_exists($exception, 'getTLTrace')) {
if (\method_exists($exception, 'getTLTrace')) {
$this->tlTrace = $exception->getTLTrace();
}

View File

@ -2,10 +2,6 @@
namespace danog\MadelineProto\Ipc\Runner;
use Amp\Process\Process as BaseProcess;
use Amp\Promise;
use danog\MadelineProto\Magic;
final class ProcessRunner extends RunnerAbstract
{
/** @var string|null Cached path to located PHP binary. */
@ -41,7 +37,7 @@ final class ProcessRunner extends RunnerAbstract
\escapeshellarg($session),
'&>/dev/null &'
]);
shell_exec($command);
\shell_exec($command);
}
private static function locateBinary(): string
{

View File

@ -2,8 +2,6 @@
namespace danog\MadelineProto\Ipc\Runner;
use Amp\Promise;
abstract class RunnerAbstract
{
const SCRIPT_PATH = __DIR__."/entry.php";

View File

@ -4,7 +4,6 @@ namespace danog\MadelineProto\Ipc\Runner;
use Amp\ByteStream\ResourceOutputStream;
use Amp\Parallel\Context\ContextException;
use Amp\Promise;
use danog\MadelineProto\Magic;
final class WebRunner extends RunnerAbstract
@ -95,7 +94,7 @@ final class WebRunner extends RunnerAbstract
// We don't care for results or timeouts here, PHP doesn't count IOwait time as execution time anyway
// Technically should use amphp/socket, but I guess it's OK to not introduce another dependency just for a socket that will be used once.
fwrite($res = \fsockopen($address, $port), $payload);
fclose($res);
\fwrite($res = \fsockopen($address, $port), $payload);
\fclose($res);
}
}

View File

@ -32,11 +32,11 @@ use danog\MadelineProto\Tools;
class Server extends SignalLoop
{
/**
* Session not initialized, should initialize
* Session not initialized, should initialize.
*/
const NOT_INITED = 'not inited';
/**
* Session uses event handler, should start from main event handler file
* Session uses event handler, should start from main event handler file.
*/
const EVENT_HANDLER = 'event';
/**
@ -99,9 +99,10 @@ class Server extends SignalLoop
$id = 0;
try {
while ($payload = yield $socket->receive()) {
Tools::callFork($this->clientRequest($socket, $id++, $payload));
Tools::callFork($this->clientRequest($socket, $id++, $payload));
}
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
}
/**
* Handle client request.

View File

@ -50,8 +50,8 @@ trait CallHandler
foreach ($message_ids as $message_id) {
if (isset($this->outgoing_messages[$message_id]['body'])) {
if ($datacenter) {
unset($this->outgoing_messages[$message_id]['msg_id']);
unset($this->outgoing_messages[$message_id]['seqno']);
unset($this->outgoing_messages[$message_id]['msg_id'], $this->outgoing_messages[$message_id]['seqno']);
Tools::call($this->API->datacenter->waitGetConnection($datacenter))->onResolve(function ($e, $r) use ($message_id) {
Tools::callFork($r->sendMessage($this->outgoing_messages[$message_id], false));
});

View File

@ -112,6 +112,14 @@ abstract class Session
$this->session_in_seq_no = 0;
$this->session_out_seq_no = 0;
$this->msgIdHandler = MsgIdHandler::createInstance($this);
foreach ($this->outgoing_messages as &$msg) {
if (isset($msg['msg_id'])) {
unset($msg['msg_id']);
}
if (isset($msg['seqno'])) {
unset($msg['seqno']);
}
}
}
/**
* Create MTProto session if needed.

View File

@ -275,7 +275,9 @@ class Magic
}
self::$initedLight = true;
if ($light) {
if (!\defined(\AMP_WORKER::class)) \define(\AMP_WORKER::class, true);
if (!\defined(\AMP_WORKER::class)) {
\define(\AMP_WORKER::class, true);
}
return;
}
}
@ -327,7 +329,9 @@ class Magic
if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') && !(\class_exists(\Phar::class) && \Phar::running())) {
try {
$back = \debug_backtrace(0);
if (!defined('AMP_WORKER')) \define('AMP_WORKER', 1);
if (!\defined('AMP_WORKER')) {
\define('AMP_WORKER', 1);
}
$promise = \Amp\File\get(\end($back)['file']);
do {
try {

View File

@ -61,7 +61,7 @@ class RPCErrorException extends \Exception
return $result;
}
/**
* Get localized error name
* Get localized error name.
*
* @return string
*/
@ -71,7 +71,7 @@ class RPCErrorException extends \Exception
return $this->localized;
}
/**
* Set localized error name
* Set localized error name.
*
* @param string $localization
* @return void