Some checks failed
ZaStoGram source guards / guards (push) Failing after 26s
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 1m59s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 2m5s
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 2m9s
logs (11): ни один из 48 стикеров DC1 не догрузился. Загрузки стартовали до отключения релея с частями 32–128 КБ, которые через туннель не проходят никогда, а соединение туннеля пересоздавалось посреди такого ответа и слало его заново по кругу; зависания на них отключили туннель. Сеть сообщает Java, когда медиа-DC уходит в туннель, и идущие загрузки этого DC продолжают с уже скачанного частями по 8 КБ. Туннель пересоздаётся только между пакетами, а зависание посреди слишком большого ответа не засчитывается туннелю.
134 lines
3.8 KiB
C++
134 lines
3.8 KiB
C++
/*
|
|
* This is the source code of tgnet library v. 1.1
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
*
|
|
* Copyright Nikolai Kudashov, 2015-2018.
|
|
*/
|
|
|
|
#ifndef CONNECTION_H
|
|
#define CONNECTION_H
|
|
|
|
#include <pthread.h>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <openssl/aes.h>
|
|
#include "ConnectionSession.h"
|
|
#include "ConnectionSocket.h"
|
|
#include "Defines.h"
|
|
|
|
class Datacenter;
|
|
class Timer;
|
|
class ByteStream;
|
|
class ByteArray;
|
|
|
|
class Connection : public ConnectionSession, public ConnectionSocket {
|
|
|
|
public:
|
|
|
|
Connection(Datacenter *datacenter, ConnectionType type, int8_t num);
|
|
~Connection();
|
|
|
|
void connect();
|
|
void suspendConnection();
|
|
void suspendConnection(bool idle);
|
|
bool sendData(NativeByteBuffer *buffer, bool reportAck, bool encrypted);
|
|
bool canSendRequestData(const char *reason);
|
|
bool isMtProxyRouteActive() const;
|
|
bool isMtProxyReconnectPacingActive() const;
|
|
bool hasUsefullData();
|
|
void setHasUsefullData();
|
|
bool allowsCustomPadding();
|
|
uint32_t getConnectionToken();
|
|
ConnectionType getConnectionType();
|
|
int8_t getConnectionNum();
|
|
Datacenter *getDatacenter();
|
|
bool isSuspended();
|
|
static bool isMediaConnectionType(ConnectionType type);
|
|
|
|
protected:
|
|
|
|
void onReceivedData(NativeByteBuffer *buffer) override;
|
|
void onDisconnected(int32_t reason, int32_t error) override;
|
|
void onConnected() override;
|
|
bool hasPendingRequests() override;
|
|
bool hasPartialIncomingPacket() override;
|
|
std::string proxyConnectionStageOrigin() override;
|
|
std::string proxyConnectionStageSocketRole() override;
|
|
void reconnect();
|
|
|
|
private:
|
|
|
|
enum TcpConnectionState {
|
|
TcpConnectionStageIdle,
|
|
TcpConnectionStageConnecting,
|
|
TcpConnectionStageReconnecting,
|
|
TcpConnectionStageConnected,
|
|
TcpConnectionStageSuspended
|
|
};
|
|
|
|
enum ProtocolType {
|
|
ProtocolTypeEF,
|
|
ProtocolTypeEE,
|
|
ProtocolTypeDD,
|
|
ProtocolTypeTLS
|
|
};
|
|
|
|
inline void encryptKeyWithSecret(uint8_t *array, uint8_t secretType);
|
|
inline std::string *getCurrentSecret(uint8_t secretType);
|
|
void notifyConnectionClosedOnce(int32_t reason, const char *source);
|
|
void onDisconnectedInternal(int32_t reason, int32_t error);
|
|
|
|
ProtocolType currentProtocolType = ProtocolTypeEE;
|
|
|
|
TcpConnectionState connectionState = TcpConnectionStageIdle;
|
|
uint32_t connectionToken = 0;
|
|
std::string hostAddress;
|
|
std::string secret;
|
|
uint16_t hostPort;
|
|
uint16_t failedConnectionCount;
|
|
Datacenter *currentDatacenter;
|
|
uint32_t currentAddressFlags;
|
|
ConnectionType connectionType;
|
|
int8_t connectionNum;
|
|
bool firstPacketSent = false;
|
|
NativeByteBuffer *restOfTheData = nullptr;
|
|
uint32_t lastPacketLength = 0;
|
|
bool hasSomeDataSinceLastConnect = false;
|
|
bool isTryingNextPort = false;
|
|
bool wasConnected = false;
|
|
uint32_t willRetryConnectCount = 5;
|
|
Timer *reconnectTimer;
|
|
bool usefullData = false;
|
|
bool forceNextPort = false;
|
|
bool isMediaConnection = false;
|
|
bool waitForReconnectTimer = false;
|
|
bool connectionInProcess = false;
|
|
bool connectionCloseNotified = false;
|
|
uint32_t lastReconnectTimeout = 100;
|
|
uint32_t mtProxyReconnectBackoffMs = 0;
|
|
int64_t mtProxyReconnectHoldUntil = 0;
|
|
int64_t usefullDataReceiveTime;
|
|
uint32_t currentTimeout = 4;
|
|
uint32_t receivedDataAmount = 0;
|
|
uint32_t generation = 0;
|
|
// -404s seen on a WEB proxy stream since a reply last decrypted, see
|
|
// WEB_PROXY_KEY_NOT_FOUND_STRIKES.
|
|
uint32_t webProxyKeyNotFoundStrikes = 0;
|
|
|
|
uint8_t temp[64];
|
|
|
|
AES_KEY encryptKey;
|
|
uint8_t encryptIv[16];
|
|
uint32_t encryptNum;
|
|
uint8_t encryptCount[16];
|
|
|
|
AES_KEY decryptKey;
|
|
uint8_t decryptIv[16];
|
|
uint32_t decryptNum;
|
|
uint8_t decryptCount[16];
|
|
|
|
friend class ConnectionsManager;
|
|
};
|
|
|
|
#endif
|