Clean up unused stuff

This commit is contained in:
Daniil Gentili 2019-05-10 14:07:15 +02:00
parent 8d7b910058
commit 8dedb13b5e
6 changed files with 65 additions and 157 deletions

3
.gitignore vendored
View File

@ -111,4 +111,5 @@ madeline.phar
madeline.phar.version
big
*.phar
madeline.php
madeline.php
.phpunit.result.cache

View File

@ -69,11 +69,6 @@ class DataCenter
}
}
public function dc_connect($dc_number)
{
return $this->wait($this->dc_connect_async($dc_number));
}
public function dc_connect_async($dc_number): \Generator
{
if (isset($this->sockets[$dc_number]) && !isset($this->sockets[$dc_number]->old)) {

View File

@ -1,68 +0,0 @@
<?php
/**
* SocketHandler module.
*
* 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-2018 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
*
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\Threads;
/**
* Manages packing and unpacking of messages, and the list of sent and received messages.
*/
class SocketHandler extends \Threaded implements \Collectable
{
public function __construct(&$me, $current, $error)
{
$this->API = $me;
$this->current = $current;
$this->error = $error;
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
public function run()
{
require __DIR__.'/../../../../vendor/autoload.php';
if ($this->error !== true) {
if ($this->error === -404) {
if ($this->API->datacenter->sockets[$this->current]->temp_auth_key !== null) {
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['resetting_auth_key'], \danog\MadelineProto\Logger::WARNING);
$this->API->datacenter->sockets[$this->current]->temp_auth_key = null;
$this->API->init_authorization();
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['recreate_temp_auth_key']);
}
}
throw new \danog\MadelineProto\RPCErrorException($this->error, $this->error);
}
$this->API->handle_messages($this->current);
$this->setGarbage();
}
protected $garbage = false;
public function setGarbage()
{
$this->garbage = true;
}
public function isGarbage()
{
return $this->garbage;
}
}

View File

@ -1,83 +0,0 @@
<?php
/**
* SocketReader module.
*
* 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-2018 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
*
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\Threads;
/**
* Manages packing and unpacking of messages, and the list of sent and received messages.
*/
class SocketReader extends \Threaded implements \Collectable
{
public $ready = false;
public function __construct($me, $current)
{
$this->API = $me;
$this->current = $current;
}
public function __sleep()
{
return ['current', 'API', 'garbage'];
}
public function __destruct()
{
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['shutting_down_reader_pool'].$this->current, \danog\MadelineProto\Logger::NOTICE);
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
public function run()
{
require __DIR__.'/../../../../vendor/autoload.php';
$handler_pool = new \Pool($this->API->settings['threading']['handler_workers']);
$this->ready = true;
while ($this->API->run_workers) {
try {
$this->API->datacenter->sockets[$this->current]->reading = true;
//$this->logger->logger('RECEIVING');
$error = $this->API->recv_message($this->current);
$this->logger->logger('NOW HANDLE');
$handler_pool->submit(new SocketHandler($this->API, $this->current, $error));
$this->logger->logger('SUBMITTED');
$this->API->datacenter->sockets[$this->current]->reading = false;
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
//$this->logger->logger('Nothing in the socket for dc '.$this->current, \danog\MadelineProto\Logger::VERBOSE);
}
}
while ($number = $handler_pool->collect()) {
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['shutting_down_handler_pool'], $this->current, $number), \danog\MadelineProto\Logger::NOTICE);
}
$this->setGarbage();
}
public $garbage = false;
public function setGarbage()
{
$this->garbage = true;
}
public function isGarbage()
{
return $this->garbage;
}
}

View File

@ -0,0 +1,56 @@
<?php
use PHPUnit\Framework\TestCase;
final class APITest extends TestCase
{
/**
* @dataProvider protocolProvider
*
* @return void
*/
public function testCanUseProtocol($transport, $obfuscated, $protocol, $test_mode, $ipv6): void
{
$ping = ['ping_id' => random_int(PHP_INT_MIN, PHP_INT_MAX)];
$MadelineProto = new \danog\MadelineProto\API(
[
'app_info' => [
'api_id' => 25628,
'api_hash' => '1fe17cda7d355166cdaa71f04122873c'
],
'connection_settings' => [
'all' => [
'ipv6' => $ipv6,
'test_mode' => $test_mode,
'protocol' => $protocol,
'obfuscated' => $obfuscated,
'transport' => $transport,
],
],
]
);
$pong = $MadelineProto->ping($ping);
$this->assertContainsEquals('_', $pong, 'pong');
$this->assertContainsEquals('ping_id', $pong, $ping['ping_id']);
}
public function protocolProvider(): \Generator
{
foreach ([false, true] as $test_mode) {
foreach ([false, true] as $ipv6) {
foreach (['tcp', 'ws', 'wss'] as $transport) {
foreach ([true, false] as $obfuscated) {
if ($transport !== 'tcp' && !$obfuscated) {
continue;
}
foreach (['tcp_abridged', 'tcp_intermediate', 'tcp_intermediate_padded', 'tcp_full'] as $protocol) {
if ($protocol === 'tcp_full' && $obfuscated) continue;
yield [$transport, $obfuscated, $protocol, $test_mode, $ipv6];
}
}
}
yield ['tcp', false, 'http', $test_mode, $ipv6];
yield ['tcp', false, 'https', $test_mode, $ipv6];
}
}
}
}

7
tests/phpunit.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.1/phpunit.xsd">
<php>
<const name="MADELINEPROTO_TEST" value="pony"/>
</php>
</phpunit>