diff --git a/docs b/docs index 326dc6dee..821000468 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 326dc6dee0cc0303db36c4bd5e74a241f8f9ad57 +Subproject commit 821000468d14f943496b8bbc7183360c83630d6b diff --git a/schemas b/schemas index 8662116b0..86b054b6f 160000 --- a/schemas +++ b/schemas @@ -1 +1 @@ -Subproject commit 8662116b0ada741008f19cb073ea4a4a6c29f807 +Subproject commit 86b054b6f2790f42dfeeb033fa8f2288657ab3d9 diff --git a/src/DataCenterConnection.php b/src/DataCenterConnection.php index 97a431d86..564f2eb4c 100644 --- a/src/DataCenterConnection.php +++ b/src/DataCenterConnection.php @@ -394,10 +394,10 @@ final class DataCenterConnection implements JsonSerializable /** * Reset MTProto sessions. */ - public function resetSession(): void + public function resetSession(string $why): void { foreach ($this->connections as $socket) { - $socket->resetSession(); + $socket->resetSession($why); } } /** diff --git a/src/Loop/Connection/ReadLoop.php b/src/Loop/Connection/ReadLoop.php index c7d580aca..ad715d702 100644 --- a/src/Loop/Connection/ReadLoop.php +++ b/src/Loop/Connection/ReadLoop.php @@ -78,7 +78,7 @@ final class ReadLoop extends Loop }); return self::STOP; } catch (SecurityException $e) { - $this->connection->resetSession(); + $this->connection->resetSession("security exception {$e->getMessage()}"); $this->API->logger("Got security exception in DC {$this->datacenter}, reconnecting...", Logger::ERROR); $this->connection->reconnect(); throw $e; @@ -89,7 +89,7 @@ final class ReadLoop extends Loop if ($this->shared->hasTempAuthKey()) { $this->API->logger("WARNING: Resetting auth key in DC {$this->datacenter}...", Logger::WARNING); $this->shared->setTempAuthKey(null); - $this->shared->resetSession(); + $this->shared->resetSession("-404"); foreach ($this->connection->new_outgoing as $message) { $message->resetSent(); } @@ -201,7 +201,7 @@ final class ReadLoop extends Loop $session_id = substr($decrypted_data, 8, 8); if ($session_id !== $this->connection->session_id) { $this->API->logger('Session ID mismatch', Logger::FATAL_ERROR); - $this->connection->resetSession(); + $this->connection->resetSession("session ID mismatch"); throw new NothingInTheSocketException(); } $message_id = Tools::unpackSignedLong(substr($decrypted_data, 16, 8)); diff --git a/src/MTProto.php b/src/MTProto.php index 7d8ad2328..89dd7d27c 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -936,7 +936,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter } $this->settings->setSchema(new TLSchema); - $this->resetMTProtoSession(true, true); + $this->resetMTProtoSession("upgrading madelineproto", true, true); $this->config = ['expires' => -1]; $this->dh_config = ['version' => 0]; $this->initialize($this->settings); @@ -1013,7 +1013,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter Lang::$currentPercentage = 0; } // Reset MTProto session (not related to user session) - $this->resetMTProtoSession(); + $this->resetMTProtoSession("wakeup"); // Update settings from constructor $this->updateSettings($settings); // Update TL callbacks @@ -1250,14 +1250,14 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter * @param boolean $auth_key Whether to reset the auth key * @internal */ - public function resetMTProtoSession(bool $de = true, bool $auth_key = false): void + public function resetMTProtoSession(string $why, bool $de = true, bool $auth_key = false): void { if (!\is_object($this->datacenter)) { throw new Exception(Lang::$current_lang['session_corrupted']); } foreach ($this->datacenter->getDataCenterConnections() as $id => $socket) { if ($de) { - $socket->resetSession(); + $socket->resetSession("resetMTProtoSession: $why"); } if ($auth_key) { $socket->setTempAuthKey(null); diff --git a/src/MTProtoSession/ResponseHandler.php b/src/MTProtoSession/ResponseHandler.php index e60a8d89f..c94341efc 100644 --- a/src/MTProtoSession/ResponseHandler.php +++ b/src/MTProtoSession/ResponseHandler.php @@ -225,7 +225,7 @@ trait ResponseHandler case 17: $this->time_delta = ($message->getMsgId() >> 32) - time(); $this->API->logger('Set time delta to ' . $this->time_delta, Logger::WARNING); - $this->API->resetMTProtoSession(); + $this->API->resetMTProtoSession("time delta update"); $this->shared->setTempAuthKey(null); EventLoop::queue($this->shared->initAuthorization(...)); EventLoop::queue($this->methodRecall(...), $requestId); diff --git a/src/MTProtoSession/Session.php b/src/MTProtoSession/Session.php index a54f5481c..b07527656 100644 --- a/src/MTProtoSession/Session.php +++ b/src/MTProtoSession/Session.php @@ -99,9 +99,9 @@ trait Session /** * Reset MTProto session. */ - public function resetSession(): void + public function resetSession(string $why): void { - $this->API->logger("Resetting session in DC {$this->datacenterId}...", Logger::WARNING); + $this->API->logger("Resetting session in DC {$this->datacenterId} due to $why...", Logger::WARNING); $this->session_id = Tools::random(8); $this->session_in_seq_no = 0; $this->session_out_seq_no = 0; @@ -172,7 +172,7 @@ trait Session public function createSession(): void { if ($this->session_id === null) { - $this->resetSession(); + $this->resetSession("creating initial session"); } $this->abstractionQueueMutex ??= new LocalKeyedMutex; }