Misc bugfixes

This commit is contained in:
Daniil Gentili 2020-03-08 17:24:31 +01:00
parent ec2719db4e
commit 0a467beb53
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
32 changed files with 61 additions and 94 deletions

View File

@ -1,37 +0,0 @@
<?php
if (!\class_exists('ReflectionGenerator')) {
class ReflectionGenerator
{
private $generator;
public function __construct(Generator $generator)
{
$this->generator = $generator;
}
public function getExecutingFile(): string
{
return '';
}
public function getExecutingGenerator(): Generator
{
return $this->generator;
}
public function getExecutingLine(): int
{
return 0;
}
public function getFunction(): ReflectionFunctionAbstract
{
return new ReflectionFunction(function () {
});
}
public function getThis(): object
{
return $this;
}
public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array
{
return [];
}
}
}

View File

@ -19,6 +19,7 @@
namespace danog\MadelineProto\Async;
use Amp\Promise;
use danog\MadelineProto\Tools;
/**

View File

@ -102,9 +102,6 @@ class CombinedAPI
}
public function __destruct()
{
if (\danog\MadelineProto\Magic::$has_thread && \is_object(\Thread::getCurrentThread()) || Magic::isFork()) {
return;
}
$this->serialize();
}
public function serialize($filename = '')

View File

@ -30,6 +30,7 @@ use danog\MadelineProto\MTProtoSession\Session;
use danog\MadelineProto\Stream\ConnectionContext;
use danog\MadelineProto\Stream\MTProtoTransport\HttpsStream;
use danog\MadelineProto\Stream\MTProtoTransport\HttpStream;
use danog\MadelineProto\Stream\StreamInterface;
use danog\MadelineProto\Stream\Transport\WssStream;
use danog\MadelineProto\Stream\Transport\WsStream;
@ -77,7 +78,7 @@ class Connection extends Session
/**
* The actual socket.
*
* @var Stream
* @var StreamInterface
*/
public $stream;
/**

View File

@ -29,7 +29,8 @@ use Amp\Http\Client\Connection\UnlimitedConnectionPool;
use Amp\Http\Client\Cookie\CookieInterceptor;
use Amp\Http\Client\Cookie\CookieJar;
use Amp\Http\Client\Cookie\InMemoryCookieJar;
use Amp\Http\Client\DelegateHttpClient;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Socket\ConnectContext;
@ -94,7 +95,7 @@ class DataCenter
/**
* HTTP client.
*
* @var \Amp\Http\Client\DelegateHttpClient
* @var \Amp\Http\Client\HttpClient
*/
private $HTTPClient;
/**
@ -506,9 +507,9 @@ class DataCenter
/**
* Get async HTTP client.
*
* @return \Amp\Http\Client\DelegateHttpClient
* @return \Amp\Http\Client\HttpClient
*/
public function getHTTPClient(): DelegateHttpClient
public function getHTTPClient(): HttpClient
{
return $this->HTTPClient;
}

View File

@ -4210,9 +4210,9 @@ class InternalDoc extends APIFactory
/**
* Get async HTTP client.
*
* @return \Amp\Http\Client\DelegateHttpClient
* @return \Amp\Http\Client\HttpClient
*/
public function getHTTPClient(): \Amp\Http\Client\DelegateHttpClient
public function getHTTPClient(): \Amp\Http\Client\HttpClient
{
return $this->API->getHTTPClient();
}

View File

@ -58,7 +58,7 @@ abstract class ResumableSignalLoop extends SignalLoop implements ResumableLoopIn
}
return $this->resume->promise();
}
public function resume($watcherId = null, $expected = 0)
public function resume($watcherId = null, $expected = 0): void
{
if ($this->resumeWatcher) {
$storedWatcherId = $this->resumeWatcher;

View File

@ -41,5 +41,5 @@ interface ResumableLoopInterface extends LoopInterface
*
* @return void
*/
public function resume();
public function resume(): void;
}

View File

@ -39,9 +39,9 @@ interface SignalLoopInterface extends LoopInterface
/**
* Send a signal to the the loop.
*
* @param Exception|any $data Signal to send
* @param \Throwable|any $data Signal to send
*
* @return void
*/
public function signal($data);
public function signal($data): void;
}

View File

@ -21,7 +21,7 @@ namespace danog\MadelineProto;
use Amp\Dns\Resolver;
use Amp\File\StatCache;
use Amp\Http\Client\DelegateHttpClient;
use Amp\Http\Client\HttpClient;
use Amp\Loop;
use danog\MadelineProto\Async\AsyncConstruct;
use danog\MadelineProto\Loop\Generic\PeriodicLoop;
@ -346,31 +346,31 @@ class MTProto extends AsyncConstruct implements TLCallback
/**
* TOS check loop.
*
* @var \danog\MadelineProto\Loop\Update\PeriodicLoop
* @var PeriodicLoop
*/
public $checkTosLoop;
/**
* Phone config loop.
*
* @var \danog\MadelineProto\Loop\Update\PeriodicLoop
* @var PeriodicLoop
*/
public $phoneConfigLoop;
/**
* Config loop.
*
* @var \danog\MadelineProto\Loop\Update\PeriodicLoop
* @var PeriodicLoop
*/
public $configLoop;
/**
* Call checker loop.
*
* @var \danog\MadelineProto\Loop\Update\PeriodicLoop
* @var PeriodicLoop
*/
private $callCheckerLoop;
/**
* Autoserialization loop.
*
* @var \danog\MadelineProto\Loop\Update\PeriodicLoop
* @var PeriodicLoop
*/
private $serializeLoop;
/**
@ -610,9 +610,9 @@ class MTProto extends AsyncConstruct implements TLCallback
/**
* Get async HTTP client.
*
* @return \Amp\Http\Client\DelegateHttpClient
* @return \Amp\Http\Client\HttpClient
*/
public function getHTTPClient(): DelegateHttpClient
public function getHTTPClient(): HttpClient
{
return $this->datacenter->getHTTPClient();
}

View File

@ -40,7 +40,7 @@ abstract class Session
/**
* Message ID handler.
*
* @var MsgIdHandlerAbstract
* @var MsgIdHandler
*/
public $msgIdHandler;
/**

View File

@ -900,7 +900,7 @@ trait Files
\header("$key: $subValue", false);
}
} else {
\header("$key: $subValue");
\header("$key: $value");
}
}
\http_response_code($result['code']);

View File

@ -64,7 +64,7 @@ class ADNLStream implements BufferedStreamInterface, MTProtoBufferInterface
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -81,7 +81,7 @@ class ADNLStream implements BufferedStreamInterface, MTProtoBufferInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -84,7 +84,7 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw
/**
* Async close.
*
* @return Generator
* @return \Generator
*/
public function disconnect()
{

View File

@ -81,7 +81,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -97,7 +97,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{
@ -111,7 +111,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
*
* @throws PendingReadError Thrown if another read operation is still pending.
*
* @return Generator That resolves with a string when the provided promise is resolved and the data is decrypted
* @return \Generator That resolves with a string when the provided promise is resolved and the data is decrypted
*/
public function bufferReadGenerator(int $length): \Generator
{

View File

@ -142,7 +142,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
*
* @throws PendingReadError Thrown if another read operation is still pending.
*
* @return Generator That resolves with a string when the provided promise is resolved and the data is added to the hashing context
* @return \Generator That resolves with a string when the provided promise is resolved and the data is added to the hashing context
*/
public function bufferReadGenerator(int $length): \Generator
{
@ -213,7 +213,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{
@ -228,7 +228,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{

View File

@ -100,7 +100,7 @@ class ConnectionContext
/**
* An array of arrays containing an array with the stream name and the extra parameter to pass to it.
*
* @var array<array<string, any>>
* @var array<array<string, mixed>>
*/
private $nextStreams = [];
/**
@ -344,7 +344,7 @@ class ConnectionContext
* Add a stream to the stream chain.
*
* @param string $streamName
* @param any $extra
* @param mixed $extra
*
* @return self
*/
@ -357,11 +357,11 @@ class ConnectionContext
/**
* Set read callback, called every time the socket reads at least a byte.
*
* @param callback $callable Read callback
* @param callable $callable Read callback
*
* @return void
*/
public function setReadCallback($callable)
public function setReadCallback(callable $callable)
{
$this->readCallback = $callable;
}
@ -379,7 +379,7 @@ class ConnectionContext
*
* @return callable
*/
public function getReadCallback()
public function getReadCallback(): callable
{
return $this->readCallback;
}

View File

@ -80,7 +80,7 @@ class AbridgedStream implements BufferedStreamInterface, MTProtoBufferInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -70,7 +70,7 @@ class FullStream implements BufferedStreamInterface, MTProtoBufferInterface
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -86,7 +86,7 @@ class FullStream implements BufferedStreamInterface, MTProtoBufferInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -85,7 +85,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -99,7 +99,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -63,7 +63,7 @@ class IntermediatePaddedStream implements BufferedStreamInterface, MTProtoBuffer
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -77,7 +77,7 @@ class IntermediatePaddedStream implements BufferedStreamInterface, MTProtoBuffer
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -63,7 +63,7 @@ class IntermediateStream implements BufferedStreamInterface, MTProtoBufferInterf
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBufferGenerator(int $length, string $append = ''): \Generator
{
@ -76,7 +76,7 @@ class IntermediateStream implements BufferedStreamInterface, MTProtoBufferInterf
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBufferGenerator(&$length): \Generator
{

View File

@ -141,7 +141,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBuffer(int $length, string $append = ''): Promise
{
@ -152,7 +152,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBuffer(&$length): Promise
{

View File

@ -148,7 +148,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
*
* @param int $length Length of data that is going to be written to the write buffer
*
* @return Generator
* @return \Generator
*/
public function getWriteBuffer(int $length, string $append = ''): Promise
{
@ -159,7 +159,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
*
* @param int $length Length of payload, as detected by this layer
*
* @return Generator
* @return \Generator
*/
public function getReadBuffer(&$length): Promise
{

View File

@ -23,6 +23,7 @@ use Amp\ByteStream\ClosedException;
use Amp\CancellationToken;
use Amp\Promise;
use Amp\Socket\ClientTlsContext;
use Amp\Socket\Connector;
use Amp\Socket\EncryptableSocket;
use Amp\Socket\Socket;
use danog\MadelineProto\Stream\Async\RawStream;

View File

@ -82,7 +82,7 @@ class PremadeStream implements RawStreamInterface, ProxyStreamInterface
/**
* Async close.
*
* @return Generator
* @return \Generator
*/
public function disconnect()
{

View File

@ -21,8 +21,10 @@ namespace danog\MadelineProto\Stream\Transport;
use Amp\Promise;
use Amp\Socket\EncryptableSocket;
use Amp\Websocket\Client\Connection;
use Amp\Websocket\Client\Connector;
use Amp\Websocket\Client\Handshake;
use Amp\Websocket\Message;
use danog\MadelineProto\Stream\Async\RawStream;
use danog\MadelineProto\Stream\ConnectionContext;
use danog\MadelineProto\Stream\ProxyStreamInterface;

View File

@ -85,7 +85,7 @@ trait BotAPIFiles
$this->logger("Got file ID with version {$fileId->getVersion()}.{$fileId->getSubVersion()}");
if (!\in_array($fileId->getVersion(), [2, 4])) {
throw new Exception("Invalid bot API file ID version {$version}");
throw new Exception("Invalid bot API file ID version {$fileId->getVersion()}");
}
$photoSize = $fileId->hasPhotoSizeSource() ? $fileId->getPhotoSizeSource() : null;

View File

@ -58,7 +58,7 @@ trait TD
*/
public function tdToMTProto(array $params): \Generator
{
$newparams = ['_' => self::REVERSE[$params['_']]];
$newparams = ['_' => self::TD_REVERSE[$params['_']]];
foreach (self::TD_PARAMS_CONVERSION[$newparams['_']] as $td => $mtproto) {
if (\is_array($mtproto)) {
switch (\end($mtproto)) {

View File

@ -28,6 +28,7 @@ use danog\MadelineProto\Stream\Common\BufferedRawStream;
use danog\MadelineProto\Stream\Common\CtrStream;
use danog\MadelineProto\Stream\Common\HashedBufferedStream;
use danog\MadelineProto\Stream\ConnectionContext;
use danog\MadelineProto\Stream\StreamInterface;
use danog\MadelineProto\Stream\Transport\DefaultStream;
use danog\MadelineProto\TL\TL;
use danog\MadelineProto\Tools;

View File

@ -177,12 +177,12 @@ trait AuthKeyHandler
$res = (yield from $this->methodCallAsyncRead('phone.confirmCall', ['key_fingerprint' => \substr(\sha1($key, true), -8), 'peer' => ['id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputPhoneCall'], 'g_a' => $this->calls[$params['id']]->storage['g_a'], 'protocol' => ['_' => 'phoneCallProtocol', 'udp_reflector' => true, 'min_layer' => 65, 'max_layer' => \danog\MadelineProto\VoIP::getConnectionMaxLayer()]], ['datacenter' => $this->datacenter->curdc]))['phone_call'];
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'CALL_ALREADY_ACCEPTED') {
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_already_accepted'], $call['id']));
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_already_accepted'], $params['id']));
return true;
}
if ($e->rpc === 'CALL_ALREADY_DECLINED') {
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['call_already_declined']);
yield from $this->discardCall($call['id'], ['_' => 'phoneCallDiscardReasonHangup']);
yield from $this->discardCall($params['id'], ['_' => 'phoneCallDiscardReasonHangup']);
return false;
}
throw $e;

View File

@ -61,7 +61,7 @@ trait Loop
return false;
}
$this->logger->logger('Starting event loop');
if (!\is_callable($this->loop_callback) || \is_array($this->loop_callback) && $this->loop_callback[1] === 'onLoop' && !\method_exists(...$this->loop_callback)) {
if (!\is_callable($this->loop_callback)) {
$this->loop_callback = null;
}
static $inited = false;