| 6 |
| * Copyright Nikolai Kudashov, 2015-2018. |
| 7 | */ |
| 8 |
| 9 | #ifndef HANDSHAKE_H |
| 10 | #define HANDSHAKE_H |
| 11 |
| 12 | #include <stdint.h> |
| 13 | #include "Defines.h" |
| 14 |
| 15 | class Datacenter; |
| 16 | class ByteArray; |
| 17 | class TLObject; |
| 18 | class TL_future_salt; |
| 19 | class Connection; |
| 20 |
| 21 | class Handshake { |
| 22 |
| 23 | public: |
| 24 |
| 25 | Handshake(Datacenter *datacenter, HandshakeType type, HandshakeDelegate *handshakeDelegate); |
| 26 | ~Handshake(); |
| 27 | void beginHandshake(bool reconnect); |
| 28 | void cleanupHandshake(); |
| 29 | void processHandshakeResponse(TLObject *message, int64_t messageId); |
| 30 | void onHandshakeConnectionConnected(); |
| 31 | void onHandshakeConnectionClosed(); |
| 32 | HandshakeType getType(); |
| 33 | ByteArray *getAuthKeyTempPending(); |
| 34 | int64_t getAuthKeyTempPendingId(); |
| 35 | TLObject *getCurrentHandshakeRequest(); |
| 36 |
| 37 | private: |
| 38 |
| 39 | Datacenter *currentDatacenter; |
| 40 | HandshakeType handshakeType; |
| 41 | HandshakeDelegate *delegate; |
| 42 |
| 43 | uint8_t handshakeState = 0; |
| 44 | TLObject *handshakeRequest = nullptr; |
| 45 | ByteArray *authNonce = nullptr; |
| 46 | ByteArray *authServerNonce = nullptr; |
| 47 | ByteArray *authNewNonce = nullptr; |
| 48 | ByteArray *handshakeAuthKey = nullptr; |
| 49 | TL_future_salt *handshakeServerSalt = nullptr; |
| 50 | int32_t timeDifference = 0; |
| 51 | ByteArray *authKeyTempPending = nullptr; |
| 52 | int64_t authKeyTempPendingId = 0; |
| 53 | int32_t authKeyPendingRequestId = 0; |
| 54 | int64_t authKeyPendingMessageId = 0; |
| 55 | bool needResendData = false; |
| 56 |
| 57 | void sendRequestData(TLObject *object, bool important); |
| 58 | void sendAckRequest(int64_t messageId); |
| 59 |
| 60 | static void saveCdnConfig(Datacenter *datacenter); |
| 61 | static void saveCdnConfigInternal(NativeByteBuffer *buffer); |
| 62 | static void loadCdnConfig(Datacenter *datacenter); |
| 63 |
| 64 | inline Connection *getConnection(); |
| 65 | }; |
| 66 |
| 67 | #endif |
| 68 |