Fix closing of CallActor, PasswordManager, PrivacyManager and SecureManager.
GitOrigin-RevId: 511d025620ecc9fedcf6081b0bbfb9713a78251b
This commit is contained in:
parent
056569f497
commit
ece337342b
@ -635,6 +635,12 @@ void CallActor::send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promis
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, id));
|
||||
}
|
||||
|
||||
void CallActor::hangup() {
|
||||
container_.for_each(
|
||||
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });
|
||||
stop();
|
||||
}
|
||||
|
||||
vector<string> CallActor::get_emojis_fingerprint(const string &key, const string &g_a) {
|
||||
string str = key + g_a;
|
||||
unsigned char sha256_buf[32];
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
|
||||
struct CallProtocol {
|
||||
bool udp_p2p{true};
|
||||
bool udp_reflector{true};
|
||||
@ -169,7 +170,9 @@ class CallActor : public NetQueryCallback {
|
||||
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);
|
||||
|
||||
void timeout_expired() override;
|
||||
void hangup() override;
|
||||
|
||||
void on_error(Status status);
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -84,14 +84,14 @@ void PasswordManager::do_get_secure_secret(bool recursive, string password, opti
|
||||
}
|
||||
auto state = r_state.move_as_ok();
|
||||
if (!state.state.has_password) {
|
||||
return promise.set_error(Status::Error(400, "2fa is off"));
|
||||
return promise.set_error(Status::Error(400, "2-step verification is disabled"));
|
||||
}
|
||||
if (state.private_state.secret) {
|
||||
send_closure(actor_id, &PasswordManager::cache_secret, state.private_state.secret.value().clone());
|
||||
return promise.set_value(std::move(state.private_state.secret.value()));
|
||||
}
|
||||
if (!recursive) {
|
||||
return promise.set_error(Status::Error(400, "Failed to get secure secret"));
|
||||
return promise.set_error(Status::Error(400, "Failed to get Telegram Passport secret"));
|
||||
}
|
||||
|
||||
auto new_promise = PromiseCreator::lambda([password, hash = std::move(hash), promise = std::move(promise),
|
||||
@ -340,6 +340,7 @@ BufferSlice create_salt(Slice server_salt) {
|
||||
return new_salt;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void PasswordManager::do_update_password_settings(UpdateSettings update_settings, PasswordFullState full_state,
|
||||
Promise<bool> promise) {
|
||||
auto state = std::move(full_state.state);
|
||||
@ -476,6 +477,7 @@ void PasswordManager::do_get_state(Promise<PasswordState> promise) {
|
||||
promise.set_value(std::move(state));
|
||||
}));
|
||||
}
|
||||
|
||||
void PasswordManager::cache_secret(secure_storage::Secret secret) {
|
||||
LOG(ERROR) << "CACHE";
|
||||
secret_ = std::move(secret);
|
||||
@ -485,6 +487,7 @@ void PasswordManager::on_result(NetQueryPtr query) {
|
||||
auto token = get_link_token();
|
||||
container_.extract(token).set_value(std::move(query));
|
||||
}
|
||||
|
||||
void PasswordManager::send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise) {
|
||||
auto id = container_.create(std::move(promise));
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, id));
|
||||
@ -494,4 +497,10 @@ void PasswordManager::start_up() {
|
||||
temp_password_state_ = get_temp_password_state_sync();
|
||||
}
|
||||
|
||||
void PasswordManager::hangup() {
|
||||
container_.for_each(
|
||||
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });
|
||||
stop();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -140,6 +140,7 @@ class PasswordManager : public NetQueryCallback {
|
||||
void on_result(NetQueryPtr query) override;
|
||||
|
||||
void start_up() override;
|
||||
void hangup() override;
|
||||
|
||||
Container<Promise<NetQueryPtr>> container_;
|
||||
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);
|
||||
|
@ -375,4 +375,10 @@ void PrivacyManager::send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> p
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, id));
|
||||
}
|
||||
|
||||
void PrivacyManager::hangup() {
|
||||
container_.for_each(
|
||||
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });
|
||||
stop();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -123,5 +123,7 @@ class PrivacyManager : public NetQueryCallback {
|
||||
void on_result(NetQueryPtr query) override;
|
||||
Container<Promise<NetQueryPtr>> container_;
|
||||
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);
|
||||
|
||||
void hangup() override;
|
||||
};
|
||||
} // namespace td
|
||||
|
@ -153,9 +153,10 @@ void GetSecureValue::on_error(Status status) {
|
||||
}
|
||||
|
||||
void GetSecureValue::on_secret(Result<secure_storage::Secret> r_secret, bool dummy) {
|
||||
LOG_IF(ERROR, r_secret.is_error()) << r_secret.error();
|
||||
LOG_IF(ERROR, r_secret.is_ok()) << r_secret.ok().get_hash();
|
||||
if (r_secret.is_error()) {
|
||||
if (!G()->close_flag()) {
|
||||
LOG(ERROR) << "Receive error instead of secret: " << r_secret.error();
|
||||
}
|
||||
return on_error(r_secret.move_as_error());
|
||||
}
|
||||
secret_ = r_secret.move_as_ok();
|
||||
@ -202,7 +203,6 @@ void GetSecureValue::on_result(NetQueryPtr query) {
|
||||
if (result.size() != 1) {
|
||||
return on_error(Status::Error(PSLICE() << "Expected vector of size 1 got " << result.size()));
|
||||
}
|
||||
LOG(ERROR) << to_string(result[0]);
|
||||
encrypted_secure_value_ =
|
||||
get_encrypted_secure_value(G()->td().get_actor_unsafe()->file_manager_.get(), std::move(result[0]));
|
||||
loop();
|
||||
@ -219,9 +219,10 @@ void GetAllSecureValues::on_error(Status status) {
|
||||
}
|
||||
|
||||
void GetAllSecureValues::on_secret(Result<secure_storage::Secret> r_secret, bool dummy) {
|
||||
LOG_IF(ERROR, r_secret.is_error()) << r_secret.error();
|
||||
LOG_IF(ERROR, r_secret.is_ok()) << r_secret.ok().get_hash();
|
||||
if (r_secret.is_error()) {
|
||||
if (!G()->close_flag()) {
|
||||
LOG(ERROR) << "Receive error instead of secret: " << r_secret.error();
|
||||
}
|
||||
return on_error(r_secret.move_as_error());
|
||||
}
|
||||
secret_ = r_secret.move_as_ok();
|
||||
@ -321,9 +322,10 @@ void SetSecureValue::on_error(Status status) {
|
||||
}
|
||||
|
||||
void SetSecureValue::on_secret(Result<secure_storage::Secret> r_secret, bool x) {
|
||||
LOG_IF(ERROR, r_secret.is_error()) << r_secret.error();
|
||||
LOG_IF(ERROR, r_secret.is_ok()) << r_secret.ok().get_hash();
|
||||
if (r_secret.is_error()) {
|
||||
if (!G()->close_flag()) {
|
||||
LOG(ERROR) << "Receive error instead of secret: " << r_secret.error();
|
||||
}
|
||||
return on_error(r_secret.move_as_error());
|
||||
}
|
||||
secret_ = r_secret.move_as_ok();
|
||||
@ -386,7 +388,6 @@ void SetSecureValue::loop() {
|
||||
file_manager, encrypt_secure_value(file_manager, *secret_, secure_value_), to_upload_, selfie_);
|
||||
auto save_secure_value =
|
||||
telegram_api::account_saveSecureValue(std::move(input_secure_value), secret_.value().get_hash());
|
||||
LOG(ERROR) << to_string(save_secure_value);
|
||||
auto query = G()->net_query_creator().create(create_storer(save_secure_value));
|
||||
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this));
|
||||
@ -407,7 +408,6 @@ void SetSecureValue::on_result(NetQueryPtr query) {
|
||||
return on_error(r_result.move_as_error());
|
||||
}
|
||||
auto result = r_result.move_as_ok();
|
||||
LOG(ERROR) << to_string(result);
|
||||
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
|
||||
auto encrypted_secure_value = get_encrypted_secure_value(file_manager, std::move(result));
|
||||
if (secure_value_.files.size() != encrypted_secure_value.files.size()) {
|
||||
@ -432,7 +432,7 @@ void SetSecureValue::merge(FileManager *file_manager, FileId file_id, EncryptedS
|
||||
CHECK(!file_view.empty());
|
||||
CHECK(file_view.encryption_key().has_value_hash());
|
||||
if (file_view.encryption_key().value_hash().as_slice() != encrypted_file.file_hash) {
|
||||
LOG(ERROR) << "hash mismatch";
|
||||
LOG(ERROR) << "Hash mismatch";
|
||||
return;
|
||||
}
|
||||
auto status = file_manager->merge(encrypted_file.file_id, file_id);
|
||||
@ -494,9 +494,10 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
|
||||
telegram_api::object_ptr<telegram_api::account_authorizationForm> authorization_form_;
|
||||
|
||||
void on_secret(Result<secure_storage::Secret> r_secret, bool dummy) {
|
||||
LOG_IF(ERROR, r_secret.is_error()) << r_secret.error();
|
||||
LOG_IF(ERROR, r_secret.is_ok()) << r_secret.ok().get_hash();
|
||||
if (r_secret.is_error()) {
|
||||
if (!G()->close_flag()) {
|
||||
LOG(ERROR) << "Receive error instead of secret: " << r_secret.error();
|
||||
}
|
||||
return on_error(r_secret.move_as_error());
|
||||
}
|
||||
secret_ = r_secret.move_as_ok();
|
||||
@ -831,9 +832,7 @@ void SecureManager::send_passport_authorization_form(string password, int32 auth
|
||||
}
|
||||
join->credentials_.push_back(r_secure_value.move_as_ok().credentials);
|
||||
join->wait_cnt_--;
|
||||
LOG(ERROR) << tag("wait_cnt", join->wait_cnt_);
|
||||
if (join->wait_cnt_ == 0) {
|
||||
LOG(ERROR) << "set promise";
|
||||
join->promise_.set_value(std::move(join->credentials_));
|
||||
}
|
||||
}));
|
||||
@ -841,7 +840,6 @@ void SecureManager::send_passport_authorization_form(string password, int32 auth
|
||||
join->promise_ =
|
||||
PromiseCreator::lambda([promise = std::move(promise), actor_id = actor_id(this),
|
||||
authorization_form_id](Result<vector<SecureValueCredentials>> r_credentials) mutable {
|
||||
LOG(ERROR) << "on promise";
|
||||
if (r_credentials.is_error()) {
|
||||
return promise.set_error(r_credentials.move_as_error());
|
||||
}
|
||||
@ -852,7 +850,6 @@ void SecureManager::send_passport_authorization_form(string password, int32 auth
|
||||
|
||||
void SecureManager::do_send_passport_authorization_form(int32 authorization_form_id,
|
||||
vector<SecureValueCredentials> credentials, Promise<> promise) {
|
||||
LOG(ERROR) << "do_send_passport_authorization_form";
|
||||
auto it = authorization_forms_.find(authorization_form_id);
|
||||
if (it == authorization_forms_.end()) {
|
||||
return promise.set_error(Status::Error(400, "Unknown authorization_form_id"));
|
||||
@ -875,7 +872,6 @@ void SecureManager::do_send_passport_authorization_form(int32 authorization_form
|
||||
auto td_query = telegram_api::account_acceptAuthorization(
|
||||
it->second.bot_user_id.get(), it->second.scope, it->second.public_key, std::move(hashes),
|
||||
get_secure_credentials_encrypted_object(r_encrypted_credentials.move_as_ok()));
|
||||
LOG(ERROR) << to_string(td_query);
|
||||
auto query = G()->net_query_creator().create(create_storer(td_query));
|
||||
auto new_promise =
|
||||
PromiseCreator::lambda([promise = std::move(promise)](Result<NetQueryPtr> r_net_query_ptr) mutable {
|
||||
@ -889,6 +885,8 @@ void SecureManager::do_send_passport_authorization_form(int32 authorization_form
|
||||
}
|
||||
|
||||
void SecureManager::hangup() {
|
||||
container_.for_each(
|
||||
[](auto id, Promise<NetQueryPtr> &promise) { promise.set_error(Status::Error(500, "Request aborted")); });
|
||||
dec_refcnt();
|
||||
}
|
||||
|
||||
|
@ -966,7 +966,7 @@ class CliClient final : public Actor {
|
||||
return make_tl_object<td_api::inputPassportDataPhoneNumber>(arg);
|
||||
} else if (passport_data_type == "pd") {
|
||||
return make_tl_object<td_api::inputPassportDataPersonalDetails>(make_tl_object<td_api::personalDetails>(
|
||||
"Mike", "Towers", make_tl_object<td_api::date>(29, 2, 1999), "male", "US"));
|
||||
"Mike", "Towers", make_tl_object<td_api::date>(29, 2, 2000), "male", "US"));
|
||||
} else if (passport_data_type == "driver_license" || passport_data_type == "dl") {
|
||||
return make_tl_object<td_api::inputPassportDataDriverLicense>(make_tl_object<td_api::inputIdentityDocument>(
|
||||
"1234567890", make_tl_object<td_api::date>(1, 3, 2029), std::move(files), nullptr));
|
||||
@ -1149,6 +1149,9 @@ class CliClient final : public Actor {
|
||||
std::tie(password, args) = split(args);
|
||||
std::tie(passport_data_type, arg) = split(args);
|
||||
send_request(make_tl_object<td_api::setPassportData>(as_input_passport_data(passport_data_type, arg), password));
|
||||
} else if (op == "dpd") {
|
||||
string passport_data_type = args;
|
||||
send_request(make_tl_object<td_api::deletePassportData>(as_passport_data_type(passport_data_type)));
|
||||
} else if (op == "pdu" || op == "processDcUpdate") {
|
||||
string dc_id;
|
||||
string ip_port;
|
||||
|
Reference in New Issue
Block a user