Improvements

This commit is contained in:
Daniil Gentili 2019-05-12 21:23:25 +02:00
parent 56bce59cdb
commit 6e390a92bb
3 changed files with 10 additions and 7 deletions

View File

@ -69,6 +69,8 @@ class Connection
public $new_outgoing = []; public $new_outgoing = [];
public $pending_outgoing = []; public $pending_outgoing = [];
public $pending_outgoing_key = 0; public $pending_outgoing_key = 0;
public $pending_outgoing_unencrypted = [];
public $pending_outgoing_unencrypted_key = 0;
public $max_incoming_id; public $max_incoming_id;
public $max_outgoing_id; public $max_outgoing_id;
public $authorized = false; public $authorized = false;
@ -134,7 +136,7 @@ class Connection
if ($this->outgoing_messages[$message_id]['unencrypted']) { if ($this->outgoing_messages[$message_id]['unencrypted']) {
$promise = $this->outgoing_messages[$message_id]['promise']; $promise = $this->outgoing_messages[$message_id]['promise'];
\Amp\Loop::defer(function () use ($promise) { \Amp\Loop::defer(function () use ($promise) {
$promise->fail(new Exception('Restart')); $promise->fail(new Exception('Restart because we were reconnected'));
}); });
unset($this->new_outgoing[$message_id]); unset($this->new_outgoing[$message_id]);
unset($this->outgoing_messages[$message_id]); unset($this->outgoing_messages[$message_id]);

View File

@ -71,13 +71,13 @@ class ReadLoop extends SignalLoop
if ($error === -404) { if ($error === -404) {
if ($connection->temp_auth_key !== null) { if ($connection->temp_auth_key !== null) {
yield $connection->reconnect();
$API->logger->logger("WARNING: Resetting auth key in DC {$datacenter}...", \danog\MadelineProto\Logger::WARNING); $API->logger->logger("WARNING: Resetting auth key in DC {$datacenter}...", \danog\MadelineProto\Logger::WARNING);
$connection->temp_auth_key = null; $connection->temp_auth_key = null;
$connection->session_id = null; $connection->session_id = null;
foreach ($connection->new_outgoing as $message_id) { foreach ($connection->new_outgoing as $message_id) {
$connection->outgoing_messages[$message_id]['sent'] = 0; $connection->outgoing_messages[$message_id]['sent'] = 0;
} }
yield $connection->reconnect();
yield $API->init_authorization_async(); yield $API->init_authorization_async();
} else { } else {
yield $connection->reconnect(); yield $connection->reconnect();

View File

@ -44,9 +44,10 @@ class WriteLoop extends ResumableSignalLoop
$this->startedLoop(); $this->startedLoop();
$API->logger->logger("Entered write loop in DC {$datacenter}", Logger::ULTRA_VERBOSE); $API->logger->logger("Entered write loop in DC {$datacenter}", Logger::ULTRA_VERBOSE);
$please_wait = false;
while (true) { while (true) {
if (empty($connection->pending_outgoing)) { if (empty($connection->pending_outgoing) || $please_wait) {
if (yield $this->waitSignal($this->pause())) { if (yield $this->waitSignal($this->pause())) {
$API->logger->logger("Exiting write loop in DC $datacenter"); $API->logger->logger("Exiting write loop in DC $datacenter");
$this->exitedLoop(); $this->exitedLoop();
@ -62,7 +63,7 @@ class WriteLoop extends ResumableSignalLoop
} else { } else {
$res = $this->encryptedWriteLoopAsync(); $res = $this->encryptedWriteLoopAsync();
} }
yield $res; $please_wait = yield $res;
} finally { } finally {
$this->exitedLoop(); $this->exitedLoop();
} }
@ -120,7 +121,7 @@ class WriteLoop extends ResumableSignalLoop
unset($message['send_promise']); unset($message['send_promise']);
} }
if ($skipped_all) { if ($skipped_all) {
break; return true;
} }
} }
} }
@ -271,7 +272,7 @@ class WriteLoop extends ResumableSignalLoop
} else { } else {
$API->logger->logger("NO MESSAGE SENT in DC $datacenter", \danog\MadelineProto\Logger::WARNING); $API->logger->logger("NO MESSAGE SENT in DC $datacenter", \danog\MadelineProto\Logger::WARNING);
return; return true;
} }
unset($messages); unset($messages);