Skip to content

Commit

Permalink
Move HandshakeActor methods to cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 22, 2021
1 parent 562af8b commit 7f61725
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
20 changes: 20 additions & 0 deletions td/mtproto/HandshakeActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ void HandshakeActor::loop() {
}
}

void HandshakeActor::hangup() {
finish(Status::Error(1, "Canceled"));
stop();
}

void HandshakeActor::timeout_expired() {
finish(Status::Error("Timeout expired"));
stop();
}

void HandshakeActor::tear_down() {
finish(Status::OK());
}

void HandshakeActor::finish(Status status) {
// NB: order may be important for parent
return_connection(std::move(status));
return_handshake();
}

void HandshakeActor::return_connection(Status status) {
auto raw_connection = connection_->move_as_raw_connection();
if (!raw_connection) {
Expand Down
27 changes: 10 additions & 17 deletions td/mtproto/HandshakeActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace td {
namespace mtproto {

// Has Raw connection. Generates new auth key. And returns it and raw_connection. Or error...
// Owns RawConnection. Generates new auth key. And returns it and RawConnection. Or error...
class HandshakeActor final : public Actor {
public:
HandshakeActor(unique_ptr<AuthKeyHandshake> handshake, unique_ptr<RawConnection> raw_connection,
Expand All @@ -36,26 +36,19 @@ class HandshakeActor final : public Actor {
Promise<unique_ptr<AuthKeyHandshake>> handshake_promise_;

void start_up() final;
void tear_down() final {
finish(Status::OK());
}
void hangup() final {
finish(Status::Error(1, "Canceled"));
stop();
}
void timeout_expired() final {
finish(Status::Error("Timeout expired"));
stop();
}

void tear_down() final;

void hangup() final;

void timeout_expired() final;

void loop() final;

void finish(Status status) {
// NB: order may be important for parent
return_connection(std::move(status));
return_handshake();
}
void finish(Status status);

void return_connection(Status status);

void return_handshake();
};

Expand Down

0 comments on commit 7f61725

Please sign in to comment.