2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-31 03:05:40 +01:00
|
|
|
#include "td/mtproto/Handshake.h"
|
|
|
|
#include "td/mtproto/HandshakeConnection.h"
|
|
|
|
#include "td/mtproto/RawConnection.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
namespace mtproto {
|
2018-09-27 03:19:03 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// Has Raw connection. Generates new auth key. And returns it and raw_connection. Or error...
|
2021-07-04 04:58:54 +02:00
|
|
|
class HandshakeActor final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2018-09-27 03:19:03 +02:00
|
|
|
HandshakeActor(unique_ptr<AuthKeyHandshake> handshake, unique_ptr<RawConnection> raw_connection,
|
|
|
|
unique_ptr<AuthKeyHandshakeContext> context, double timeout,
|
|
|
|
Promise<unique_ptr<RawConnection>> raw_connection_promise,
|
|
|
|
Promise<unique_ptr<AuthKeyHandshake>> handshake_promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
void close();
|
|
|
|
|
|
|
|
private:
|
2018-09-27 03:19:03 +02:00
|
|
|
unique_ptr<AuthKeyHandshake> handshake_;
|
|
|
|
unique_ptr<HandshakeConnection> connection_;
|
2018-12-31 20:04:05 +01:00
|
|
|
double timeout_;
|
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
Promise<unique_ptr<RawConnection>> raw_connection_promise_;
|
|
|
|
Promise<unique_ptr<AuthKeyHandshake>> handshake_promise_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
|
|
|
void tear_down() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
finish(Status::OK());
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final {
|
2021-05-31 20:51:48 +02:00
|
|
|
finish(Status::Error(1, "Canceled"));
|
2018-05-30 18:38:17 +02:00
|
|
|
stop();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void timeout_expired() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
finish(Status::Error("Timeout expired"));
|
|
|
|
stop();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void loop() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void finish(Status status) {
|
|
|
|
// NB: order may be important for parent
|
|
|
|
return_connection(std::move(status));
|
|
|
|
return_handshake();
|
|
|
|
}
|
|
|
|
|
|
|
|
void return_connection(Status status);
|
|
|
|
void return_handshake();
|
|
|
|
};
|
2019-01-31 03:05:40 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace mtproto
|
|
|
|
} // namespace td
|