Remove useless promise wrapper
This commit is contained in:
parent
5f5556aacc
commit
6b0aaca08c
@ -46,9 +46,9 @@ class ADNLStream implements BufferedStreamInterface, MTProtoBufferInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = (yield $ctx->getStream($header));
|
||||
$this->stream = yield from $ctx->getStream($header);
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -30,7 +30,6 @@ use Amp\Promise;
|
||||
*/
|
||||
trait BufferedStream
|
||||
{
|
||||
use Stream;
|
||||
/**
|
||||
* Get read buffer asynchronously.
|
||||
*
|
||||
|
@ -30,7 +30,6 @@ use Amp\Promise;
|
||||
*/
|
||||
trait RawStream
|
||||
{
|
||||
use Stream;
|
||||
public function read(): Promise
|
||||
{
|
||||
return \danog\MadelineProto\Tools::call($this->readGenerator());
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generic stream helper trait.
|
||||
*
|
||||
* This file is part of MadelineProto.
|
||||
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Affero General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Daniil Gentili <daniil@daniil.it>
|
||||
* @copyright 2016-2019 Daniil Gentili <daniil@daniil.it>
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
||||
*
|
||||
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\Stream\Async;
|
||||
|
||||
use Amp\Promise;
|
||||
use danog\MadelineProto\Stream\ConnectionContext;
|
||||
|
||||
/**
|
||||
* Generic stream helper trait.
|
||||
*
|
||||
* Wraps the asynchronous generator methods with asynchronous promise-based methods
|
||||
*
|
||||
* @author Daniil Gentili <daniil@daniil.it>
|
||||
*/
|
||||
trait Stream
|
||||
{
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): Promise
|
||||
{
|
||||
return \danog\MadelineProto\Tools::call($this->connectGenerator($ctx, $header));
|
||||
}
|
||||
}
|
@ -49,9 +49,9 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = (yield $ctx->getStream($header));
|
||||
$this->stream = yield from $ctx->getStream($header);
|
||||
$this->memory_stream = \fopen('php://memory', 'r+');
|
||||
return true;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->encrypt = new \tgseclib\Crypt\AES('ctr');
|
||||
$this->encrypt->enableContinuousBuffer();
|
||||
@ -65,7 +65,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
|
||||
$this->decrypt->enableContinuousBuffer();
|
||||
$this->decrypt->setKey($this->extra['decrypt']['key']);
|
||||
$this->decrypt->setIV($this->extra['decrypt']['iv']);
|
||||
$this->stream = (yield $ctx->getStream($header));
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -189,7 +189,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->write_hash = null;
|
||||
$this->write_check_after = 0;
|
||||
@ -197,7 +197,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
|
||||
$this->read_hash = null;
|
||||
$this->read_check_after = 0;
|
||||
$this->read_check_pos = 0;
|
||||
$this->stream = (yield $ctx->getStream($header));
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -421,7 +421,7 @@ class ConnectionContext
|
||||
if ($obj instanceof ProxyStreamInterface) {
|
||||
$obj->setExtra($extra);
|
||||
}
|
||||
yield $obj->connect($this, $buffer);
|
||||
yield from $obj->connect($this, $buffer);
|
||||
return $obj;
|
||||
}
|
||||
/**
|
||||
|
@ -43,9 +43,9 @@ class AbridgedStream implements BufferedStreamInterface, MTProtoBufferInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = (yield $ctx->getStream(\chr(239) . $header));
|
||||
$this->stream = (yield from $ctx->getStream(\chr(239) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -53,10 +53,10 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->ctx = $ctx->getCtx();
|
||||
$this->stream = (yield $ctx->getStream($header));
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
$this->uri = $ctx->getUri();
|
||||
}
|
||||
/**
|
||||
@ -147,7 +147,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
|
||||
}
|
||||
if ($close) {
|
||||
$this->disconnect();
|
||||
yield $this->connect($this->ctx);
|
||||
yield from $this->connect($this->ctx);
|
||||
}
|
||||
\danog\MadelineProto\Logger::log($read);
|
||||
$this->code = \danog\MadelineProto\Tools::packSignedInt(-$code);
|
||||
|
@ -37,9 +37,9 @@ class HttpsStream extends HttpStream implements MTProtoBufferInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
return parent::connectGenerator($ctx->getCtx()->secure(true), $header);
|
||||
return parent::connect($ctx->getCtx()->secure(true), $header);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -45,9 +45,9 @@ class IntermediatePaddedStream implements BufferedStreamInterface, MTProtoBuffer
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = (yield $ctx->getStream(\str_repeat(\chr(221), 4) . $header));
|
||||
$this->stream = (yield from $ctx->getStream(\str_repeat(\chr(221), 4) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -45,9 +45,9 @@ class IntermediateStream implements BufferedStreamInterface, MTProtoBufferInterf
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = (yield $ctx->getStream(\str_repeat(\chr(238), 4) . $header));
|
||||
$this->stream = (yield from $ctx->getStream(\str_repeat(\chr(238), 4) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -43,7 +43,7 @@ class ObfuscatedStream extends CtrStream implements BufferedProxyStreamInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
if (isset($this->extra['address'])) {
|
||||
$ctx = $ctx->getCtx();
|
||||
@ -67,7 +67,7 @@ class ObfuscatedStream extends CtrStream implements BufferedProxyStreamInterface
|
||||
$iv = \substr($random, 40, 16);
|
||||
$ivRev = \substr($reversed, 40, 16);
|
||||
parent::setExtra(['encrypt' => ['key' => $key, 'iv' => $iv], 'decrypt' => ['key' => $keyRev, 'iv' => $ivRev]]);
|
||||
yield parent::connectGenerator($ctx);
|
||||
yield from parent::connect($ctx);
|
||||
$random = \substr_replace($random, \substr(@$this->getEncryptor()->encrypt($random), 56, 8), 56, 8);
|
||||
yield $this->getStream()->write($random);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$ctx = $ctx->getCtx();
|
||||
$uri = $ctx->getUri();
|
||||
@ -53,7 +53,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
|
||||
$ctx->setSocketContext($ctx->getSocketContext()->withTlsContext(new ClientTlsContext($uri->getHost())));
|
||||
}
|
||||
$ctx->setUri('tcp://' . $this->extra['address'] . ':' . $this->extra['port'])->secure(false);
|
||||
$this->stream = (yield $ctx->getStream());
|
||||
$this->stream = (yield from $ctx->getStream());
|
||||
$address = $uri->getHost();
|
||||
$port = $uri->getPort();
|
||||
try {
|
||||
|
@ -45,7 +45,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$ctx = $ctx->getCtx();
|
||||
$uri = $ctx->getUri();
|
||||
@ -58,7 +58,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
|
||||
if (isset($this->extra['username']) && isset($this->extra['password'])) {
|
||||
$methods .= \chr(2);
|
||||
}
|
||||
$this->stream = (yield $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods));
|
||||
$this->stream = (yield from $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods));
|
||||
$l = 2;
|
||||
$buffer = yield $this->stream->getReadBuffer($l);
|
||||
$version = \ord(yield $buffer->bufferRead(1));
|
||||
|
@ -35,9 +35,9 @@ interface StreamInterface
|
||||
*
|
||||
* @param ConnectionContext $ctx The connection context
|
||||
*
|
||||
* @return Promise
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): Promise;
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator;
|
||||
/**
|
||||
* Disconnect from the server.
|
||||
*
|
||||
|
@ -60,7 +60,7 @@ class DefaultStream implements RawStreamInterface, ProxyStreamInterface
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
public function connectGenerator(\danog\MadelineProto\Stream\ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(\danog\MadelineProto\Stream\ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$ctx = $ctx->getCtx();
|
||||
$uri = $ctx->getUri();
|
||||
|
@ -50,7 +50,7 @@ class PremadeStream implements RawStreamInterface, ProxyStreamInterface
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
if ($header !== '') {
|
||||
yield $this->stream->write($header);
|
||||
|
@ -62,7 +62,7 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
if (!\class_exists(Connector::class)) {
|
||||
throw new \danog\MadelineProto\Exception('Please install amphp/websocket-client by running "composer require amphp/websocket-client:dev-master"');
|
||||
|
@ -35,9 +35,9 @@ class WssStream extends WsStream
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
public function connect(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
return parent::connectGenerator($ctx->getCtx()->secure(true), $header);
|
||||
return parent::connect($ctx->getCtx()->secure(true), $header);
|
||||
}
|
||||
public static function getName(): string
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user