ZaStoGram_desktop/Telegram/SourceFiles/mtproto/session/private/session_private.h
loop-uh 0e40e4b8a9 Merge upstream tdesktop a8de5f928b (v7.3.4 + 51: Update brotli to 1.2.1)
Ручное слияние для Windows-клиента: оригинал в dev не попадал с v7.3.1, так как
синхронизация v7.3.2-v7.3.4 встала на конфликте lib_ui. Таймер upstream-sync на
время слияния остановлен.

- lib_ui: форк 7e5d8bc (слияние с оригиналом 1ff7be7).
- Версия 7.3.4 без бета-признака: BetaChannel 0, AppBetaVersion false.
- mtproto: «плохая конфигурация прокси» теперь учитывает прокси (колбэк рантайма,
  делегат сессии, соединение); правки session_private перенесены в
  mtproto/session/private/* (лимиты длины, пустые RPC-ответы, DEBUG_LOG дампов).
- update_checker: ограничение размера ответа и отключение HTTP/2 оригинала поверх
  гонки зеркал форка.
- thanos_effect_renderer: версия оригинала (R32F вместо RGBA32F); проверка
  возможностей — по compute.
- download_manager_mtproto: проверка слишком большой части оригинала.
- prepare.py: патчи qtsvg и Windows 7 оригинала вместе с patches_extra форка.
- Файлы .agents/.claude/.github, удалённые форком, остаются удалёнными.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 16:07:40 -05:00

196 lines
5.4 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "mtproto/details/mtproto_received_ids_manager.h"
#include "mtproto/protocol/mtproto_serialized_request.h"
#include "mtproto/auth/mtproto_auth_key.h"
#include "mtproto/session/private/auth_factory.h"
#include "mtproto/session/private/connection_factory.h"
#include "mtproto/session/private/message_handler.h"
#include "mtproto/session/private/transport.h"
#include "mtproto/session/session_delegate.h"
#include "mtproto/session/session_role.h"
#include "mtproto/session/session_state.h"
namespace MTP {
class Instance;
class RuntimeEnvironment;
enum class ProxyDiagnosticsPhase;
enum class ProxyDiagnosticsSeverity;
namespace details {
class AbstractConnection;
class SessionData;
class SessionDelegate;
class RSAPublicKey;
struct SessionOptions;
class SessionPrivate final : public QObject {
public:
SessionPrivate(
not_null<Instance*> instance,
not_null<SessionDelegate*> delegate,
not_null<QThread*> thread,
std::shared_ptr<SessionData> data,
ShiftedDcId shiftedDcId,
SessionRole role,
uint64 proxyGeneration = 0,
not_null<SessionConnectionFactory*> connectionFactory
= &DefaultSessionConnectionFactory(),
not_null<SessionAuthKeyFactory*> authKeyFactory
= &DefaultSessionAuthKeyFactory());
~SessionPrivate();
void dcOptionsChanged();
void cdnConfigChanged();
[[nodiscard]] int32 getState() const;
[[nodiscard]] QString transport() const;
void updateAuthKey();
void restartNow();
void migrateProxy(uint64 generation);
void sendPingForce();
void tryToSend();
private:
friend class SessionTransport;
friend class SessionMessageHandler;
static constexpr auto kUpdateStateAlways = 666;
struct SentContainer {
crl::time sent = 0;
std::vector<mtpMsgId> messages;
};
void connectToServer(bool afterConfig = false);
void doDisconnect();
void restart();
void onSentSome(uint64 size);
void onReceivedSome();
void handleReceived();
void sendPingByTimer();
void setConnectionNotice(ConnectionNotice notice);
void reportPingTime(crl::time time);
void logMtprotoEvent(
ProxyDiagnosticsPhase phase,
ProxyDiagnosticsSeverity severity,
const QString &message) const;
[[nodiscard]] QString mtprotoLogDc() const;
[[nodiscard]] int16 getProtocolDcId() const;
void checkSentRequests();
mtpMsgId placeToContainer(
SerializedRequest &toSendRequest,
mtpMsgId &bigMsgId,
bool forceNewMsgId,
SerializedRequest &req);
mtpMsgId prepareToSend(
SerializedRequest &request,
mtpMsgId currentLastId,
bool forceNewMsgId);
mtpMsgId replaceMsgId(
SerializedRequest &request,
mtpMsgId newId);
mtpMsgId RegisterSentRequest(
base::flat_map<mtpMsgId, SerializedRequest> &haveSent,
SerializedRequest &request,
mtpMsgId msgId);
bool sendSecureRequest(
SerializedRequest &&request,
bool needAnyResponse);
mtpRequestId wasSent(mtpMsgId msgId) const;
bool setState(int state, int ifState = kUpdateStateAlways);
[[nodiscard]] DcType tryAcquireKeyCreation();
void resetSession();
void checkAuthKey();
void authKeyChecked();
void destroyTemporaryKey();
void clearUnboundKeyCreator();
void releaseKeyCreationOnFail();
void applyAuthKey(AuthKeyPtr &&encryptionKey);
[[nodiscard]] bool noMediaKeyWithExistingRegularKey() const;
void dropMismatchedTemporaryKey();
void dropForgottenTemporaryKey();
bool destroyOldEnoughPersistentKey();
void setCurrentKeyId(uint64 newKeyId);
void changeSessionId();
[[nodiscard]] bool markSessionAsStarted();
[[nodiscard]] uint32 nextRequestSeqNumber(bool needAck);
[[nodiscard]] bool realDcTypeChanged();
[[nodiscard]] MTPVector<MTPJSONObjectValue> prepareInitParams();
struct RequestState {
mtpPingId pingId = 0;
mtpPingId pingIdToSend = 0;
crl::time pingSendAt = 0;
crl::time pingSentTime = 0;
mtpMsgId pingMsgId = 0;
QVector<MTPlong> ackData;
QVector<MTPlong> resendData;
base::flat_set<mtpMsgId> stateData;
ReceivedIdsManager receivedIds;
base::flat_map<mtpMsgId, mtpRequestId> resendingIds;
base::flat_map<mtpMsgId, mtpRequestId> ackedIds;
base::flat_map<mtpMsgId, SerializedRequest> stateAndResendRequests;
base::flat_map<mtpMsgId, SentContainer> sentContainers;
};
struct SessionState {
explicit SessionState(std::shared_ptr<SessionData> data);
std::shared_ptr<SessionData> data;
std::unique_ptr<SessionOptions> options;
AuthKeyPtr encryptionKey;
uint64 keyId = 0;
uint64 sessionId = 0;
uint64 sessionSalt = 0;
uint32 messagesCounter = 0;
bool markedAsStarted = false;
bool needReset = false;
};
struct AuthState {
std::unique_ptr<SessionBoundKeyCreator> keyCreator;
mtpMsgId bindMsgId = 0;
crl::time bindMessageSent = 0;
};
const not_null<Instance*> _instance;
const not_null<SessionDelegate*> _delegate;
const not_null<RuntimeEnvironment*> _runtime;
const not_null<SessionConnectionFactory*> _connectionFactory;
const not_null<SessionAuthKeyFactory*> _authKeyFactory;
const ShiftedDcId _shiftedDcId = 0;
const SessionRole _role = SessionRole::Auxiliary;
DcType _realDcType = DcType();
DcType _currentDcType = DcType();
mutable QReadWriteLock _stateMutex;
int _state = DisconnectedState;
SessionTransport _transport;
SessionMessageHandler _messageHandler;
RequestState _requestState;
SessionState _sessionState;
AuthState _authState;
};
} // namespace details
} // namespace MTP