Handshake.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * This is the source code of tgnet library v. 1.1
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2015-2018.
  7. */
  8. #ifndef HANDSHAKE_H
  9. #define HANDSHAKE_H
  10. #include <stdint.h>
  11. #include "Defines.h"
  12. class Datacenter;
  13. class ByteArray;
  14. class TLObject;
  15. class TL_future_salt;
  16. class Connection;
  17. class Handshake {
  18. public:
  19. Handshake(Datacenter *datacenter, HandshakeType type, HandshakeDelegate *handshakeDelegate);
  20. ~Handshake();
  21. void beginHandshake(bool reconnect);
  22. void cleanupHandshake();
  23. void processHandshakeResponse(TLObject *message, int64_t messageId);
  24. void onHandshakeConnectionConnected();
  25. void onHandshakeConnectionClosed();
  26. static void cleanupServerKeys();
  27. HandshakeType getType();
  28. ByteArray *getPendingAuthKey();
  29. int64_t getPendingAuthKeyId();
  30. TLObject *getCurrentHandshakeRequest();
  31. private:
  32. Datacenter *currentDatacenter;
  33. HandshakeType handshakeType;
  34. HandshakeDelegate *delegate;
  35. uint8_t handshakeState = 0;
  36. TLObject *handshakeRequest = nullptr;
  37. ByteArray *authNonce = nullptr;
  38. ByteArray *authServerNonce = nullptr;
  39. ByteArray *authNewNonce = nullptr;
  40. ByteArray *handshakeAuthKey = nullptr;
  41. TL_future_salt *handshakeServerSalt = nullptr;
  42. int32_t timeDifference = 0;
  43. ByteArray *authKeyTempPending = nullptr;
  44. int64_t authKeyTempPendingId = 0;
  45. int32_t authKeyPendingRequestId = 0;
  46. int64_t authKeyPendingMessageId = 0;
  47. bool needResendData = false;
  48. void sendRequestData(TLObject *object, bool important);
  49. void sendAckRequest(int64_t messageId);
  50. static void saveCdnConfig(Datacenter *datacenter);
  51. static void saveCdnConfigInternal(NativeByteBuffer *buffer);
  52. static void loadCdnConfig(Datacenter *datacenter);
  53. inline Connection *getConnection();
  54. };
  55. #endif