Add NetQueryCreator::create_unauth.

GitOrigin-RevId: 79043a3662b0353f000f388b3ee2763abf49fe2d
This commit is contained in:
levlam 2020-03-15 04:51:14 +03:00
parent c4c9e51157
commit 8d01251f8b
10 changed files with 56 additions and 83 deletions

View File

@ -175,9 +175,8 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
bot_token_ = bot_token;
was_check_bot_token_ = true;
start_net_query(NetQueryType::BotAuthentication,
G()->net_query_creator().create(
create_storer(telegram_api::auth_importBotAuthorization(0, api_id_, api_hash_, bot_token_)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(
create_storer(telegram_api::auth_importBotAuthorization(0, api_id_, api_hash_, bot_token_))));
}
void AuthManager::request_qr_code_authentication(uint64 query_id, vector<int32> other_user_ids) {
@ -215,9 +214,8 @@ void AuthManager::request_qr_code_authentication(uint64 query_id, vector<int32>
void AuthManager::send_export_login_token_query() {
poll_export_login_code_timeout_.cancel_timeout();
start_net_query(NetQueryType::RequestQrCode,
G()->net_query_creator().create(create_storer(telegram_api::auth_exportLoginToken(
api_id_, api_hash_, vector<int32>(other_user_ids_))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(
telegram_api::auth_exportLoginToken(api_id_, api_hash_, vector<int32>(other_user_ids_)))));
}
void AuthManager::set_login_token_expires_at(double login_token_expires_at) {
@ -272,9 +270,8 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
on_new_query(query_id);
start_net_query(NetQueryType::SendCode,
G()->net_query_creator().create(
create_storer(send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(
create_storer(send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_))));
}
void AuthManager::resend_authentication_code(uint64 query_id) {
@ -290,8 +287,7 @@ void AuthManager::resend_authentication_code(uint64 query_id) {
on_new_query(query_id);
start_net_query(NetQueryType::SendCode,
G()->net_query_creator().create(create_storer(r_resend_code.move_as_ok()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(r_resend_code.move_as_ok())));
}
void AuthManager::check_code(uint64 query_id, string code) {
@ -302,10 +298,8 @@ void AuthManager::check_code(uint64 query_id, string code) {
code_ = std::move(code);
on_new_query(query_id);
start_net_query(NetQueryType::SignIn,
G()->net_query_creator().create(
create_storer(telegram_api::auth_signIn(send_code_helper_.phone_number().str(),
send_code_helper_.phone_code_hash().str(), code_)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_signIn(
send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_))));
}
void AuthManager::register_user(uint64 query_id, string first_name, string last_name) {
@ -322,10 +316,8 @@ void AuthManager::register_user(uint64 query_id, string first_name, string last_
last_name = clean_name(last_name, MAX_NAME_LENGTH);
start_net_query(
NetQueryType::SignUp,
G()->net_query_creator().create(
create_storer(telegram_api::auth_signUp(send_code_helper_.phone_number().str(),
send_code_helper_.phone_code_hash().str(), first_name, last_name)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_signUp(
send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), first_name, last_name))));
}
void AuthManager::check_password(uint64 query_id, string password) {
@ -337,8 +329,7 @@ void AuthManager::check_password(uint64 query_id, string password) {
on_new_query(query_id);
password_ = std::move(password);
start_net_query(NetQueryType::GetPassword,
G()->net_query_creator().create(create_storer(telegram_api::account_getPassword()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::account_getPassword())));
}
void AuthManager::request_password_recovery(uint64 query_id) {
@ -348,8 +339,7 @@ void AuthManager::request_password_recovery(uint64 query_id) {
on_new_query(query_id);
start_net_query(NetQueryType::RequestPasswordRecovery,
G()->net_query_creator().create(create_storer(telegram_api::auth_requestPasswordRecovery()),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_requestPasswordRecovery())));
}
void AuthManager::recover_password(uint64 query_id, string code) {
@ -359,8 +349,7 @@ void AuthManager::recover_password(uint64 query_id, string code) {
on_new_query(query_id);
start_net_query(NetQueryType::RecoverPassword,
G()->net_query_creator().create(create_storer(telegram_api::auth_recoverPassword(code)), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_recoverPassword(code))));
}
void AuthManager::logout(uint64 query_id) {
@ -391,8 +380,7 @@ void AuthManager::delete_account(uint64 query_id, const string &reason) {
on_new_query(query_id);
LOG(INFO) << "Deleting account";
start_net_query(NetQueryType::DeleteAccount,
G()->net_query_creator().create(create_storer(telegram_api::account_deleteAccount(reason)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::account_deleteAccount(reason))));
}
void AuthManager::on_closing(bool destroy_flag) {
@ -525,9 +513,9 @@ void AuthManager::on_get_login_token(tl_object_ptr<telegram_api::auth_LoginToken
imported_dc_id_ = token->dc_id_;
start_net_query(NetQueryType::ImportQrCode,
G()->net_query_creator().create(
G()->net_query_creator().create_unauth(
create_storer(telegram_api::auth_importLoginToken(std::move(token->token_))),
DcId::internal(token->dc_id_), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
DcId::internal(token->dc_id_)));
break;
}
case telegram_api::auth_loginTokenSuccess::ID: {
@ -582,10 +570,8 @@ void AuthManager::on_get_password_result(NetQueryPtr &result) {
return;
} else {
start_net_query(NetQueryType::SignIn,
G()->net_query_creator().create(
create_storer(telegram_api::auth_signIn(send_code_helper_.phone_number().str(),
send_code_helper_.phone_code_hash().str(), code_)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_signIn(
send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_))));
return;
}
@ -601,9 +587,8 @@ void AuthManager::on_get_password_result(NetQueryPtr &result) {
wait_password_state_.srp_g_, wait_password_state_.srp_p_,
wait_password_state_.srp_B_, wait_password_state_.srp_id_);
start_net_query(NetQueryType::CheckPassword,
G()->net_query_creator().create(create_storer(telegram_api::auth_checkPassword(std::move(hash))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
start_net_query(NetQueryType::CheckPassword, G()->net_query_creator().create_unauth(
create_storer(telegram_api::auth_checkPassword(std::move(hash)))));
} else {
update_state(State::WaitPassword);
if (query_id_ != 0) {
@ -778,9 +763,8 @@ void AuthManager::on_result(NetQueryPtr result) {
CHECK(DcId::is_valid(imported_dc_id_));
dc_id = DcId::internal(imported_dc_id_);
}
start_net_query(NetQueryType::GetPassword,
G()->net_query_creator().create(create_storer(telegram_api::account_getPassword()), dc_id,
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
start_net_query(NetQueryType::GetPassword, G()->net_query_creator().create_unauth(
create_storer(telegram_api::account_getPassword()), dc_id));
return;
}
if (result->error().message() == CSlice("PHONE_NUMBER_BANNED")) {

View File

@ -504,8 +504,7 @@ ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorSh
int_dc_id, false /*is_main*/, true /*use_pfs*/, false /*is_cdn*/,
false /*need_destroy_auth_key*/, mtproto::AuthKey(),
std::vector<mtproto::ServerSalt>());
auto query = G()->net_query_creator().create(create_storer(telegram_api::help_getConfig()), DcId::empty(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off);
auto query = G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getConfig()), DcId::empty());
query->total_timeout_limit = 60 * 60 * 24;
query->set_callback(actor_shared(this));
query->dispatch_ttl = 0;
@ -932,8 +931,7 @@ void ConfigManager::get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>
get_app_config_queries_.push_back(std::move(promise));
if (get_app_config_queries_.size() == 1) {
auto query = G()->net_query_creator().create(create_storer(telegram_api::help_getAppConfig()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off);
auto query = G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getAppConfig()));
query->total_timeout_limit = 60 * 60 * 24;
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 1));
}
@ -991,8 +989,7 @@ void ConfigManager::on_dc_options_update(DcOptions dc_options) {
void ConfigManager::request_config_from_dc_impl(DcId dc_id) {
config_sent_cnt_++;
auto query = G()->net_query_creator().create(create_storer(telegram_api::help_getConfig()), dc_id,
NetQuery::Type::Common, NetQuery::AuthFlag::Off);
auto query = G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getConfig()), dc_id);
query->total_timeout_limit = 60 * 60 * 24;
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 0));
}

View File

@ -383,9 +383,8 @@ void LanguagePackManager::send_language_get_difference_query(Language *language,
std::move(language_code), result->version_, true, vector<string>(), std::move(result->strings_),
Promise<td_api::object_ptr<td_api::languagePackStrings>>());
});
send_with_promise(G()->net_query_creator().create(
create_storer(telegram_api::langpack_getDifference(language_pack_, language_code, version)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off),
send_with_promise(G()->net_query_creator().create_unauth(
create_storer(telegram_api::langpack_getDifference(language_pack_, language_code, version))),
std::move(request_promise));
}
@ -798,8 +797,8 @@ void LanguagePackManager::get_languages(bool only_local,
send_closure(actor_id, &LanguagePackManager::on_get_languages, r_result.move_as_ok(), std::move(language_pack),
false, std::move(promise));
});
send_with_promise(G()->net_query_creator().create(create_storer(telegram_api::langpack_getLanguages(language_pack_)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off),
send_with_promise(
G()->net_query_creator().create_unauth(create_storer(telegram_api::langpack_getLanguages(language_pack_))),
std::move(request_promise));
}
@ -820,9 +819,8 @@ void LanguagePackManager::search_language_info(string language_code,
send_closure(actor_id, &LanguagePackManager::on_get_language, r_result.move_as_ok(), std::move(language_pack),
std::move(language_code), std::move(promise));
});
send_with_promise(
G()->net_query_creator().create(create_storer(telegram_api::langpack_getLanguage(language_pack_, language_code)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off),
send_with_promise(G()->net_query_creator().create_unauth(
create_storer(telegram_api::langpack_getLanguage(language_pack_, language_code))),
std::move(request_promise));
}
@ -1082,9 +1080,8 @@ void LanguagePackManager::get_language_pack_strings(string language_code, vector
std::move(language_code), result->version_, false, vector<string>(), std::move(result->strings_),
std::move(promise));
});
send_with_promise(G()->net_query_creator().create(
create_storer(telegram_api::langpack_getLangPack(language_pack_, language_code)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off),
send_with_promise(G()->net_query_creator().create_unauth(
create_storer(telegram_api::langpack_getLangPack(language_pack_, language_code))),
std::move(request_promise));
} else {
auto request_promise =
@ -1098,9 +1095,8 @@ void LanguagePackManager::get_language_pack_strings(string language_code, vector
send_closure(actor_id, &LanguagePackManager::on_get_language_pack_strings, std::move(language_pack),
std::move(language_code), -1, false, std::move(keys), r_result.move_as_ok(), std::move(promise));
});
send_with_promise(G()->net_query_creator().create(create_storer(telegram_api::langpack_getStrings(
language_pack_, language_code, std::move(keys))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off),
send_with_promise(G()->net_query_creator().create_unauth(create_storer(
telegram_api::langpack_getStrings(language_pack_, language_code, std::move(keys)))),
std::move(request_promise));
}
}

View File

@ -527,8 +527,7 @@ class SendLiteRequestQuery : public Td::ResultHandler {
}
void send(BufferSlice request) {
send_query(G()->net_query_creator().create(create_storer(telegram_api::wallet_sendLiteRequest(std::move(request))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::wallet_sendLiteRequest(std::move(request)))));
}
void on_result(uint64 id, BufferSlice packet) override {

View File

@ -91,8 +91,7 @@ void PhoneNumberManager::resend_authentication_code(uint64 query_id) {
on_new_query(query_id);
start_net_query(NetQueryType::SendCode,
G()->net_query_creator().create(create_storer(r_resend_code.move_as_ok()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
G()->net_query_creator().create_unauth(create_storer(r_resend_code.move_as_ok())));
}
template <class T>

View File

@ -157,8 +157,7 @@ class GetNearestDcQuery : public Td::ResultHandler {
}
void send() {
send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getNearestDc()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getNearestDc())));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -432,8 +431,7 @@ class GetDeepLinkInfoQuery : public Td::ResultHandler {
pos++;
}
link.truncate(pos);
send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getDeepLinkInfo(link.str())),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getDeepLinkInfo(link.str()))));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -485,9 +483,8 @@ class SaveAppLogQuery : public Td::ResultHandler {
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
input_app_events.push_back(
make_tl_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type, peer_id, std::move(data)));
send_query(
G()->net_query_creator().create(create_storer(telegram_api::help_saveAppLog(std::move(input_app_events))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
send_query(G()->net_query_creator().create_unauth(
create_storer(telegram_api::help_saveAppLog(std::move(input_app_events)))));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -514,8 +511,7 @@ class TestQuery : public Td::ResultHandler {
}
void send() {
send_query(G()->net_query_creator().create(create_storer(telegram_api::help_getConfig()), DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getConfig())));
}
void on_result(uint64 id, BufferSlice packet) override {

View File

@ -466,8 +466,7 @@ Result<FileLoader::CheckInfo> FileDownloader::check_loop(int64 checked_prefix_si
auto query =
telegram_api::upload_getFileHashes(remote_.as_input_file_location(), narrow_cast<int32>(checked_prefix_size));
auto net_query_type = is_small_ ? NetQuery::Type::DownloadSmall : NetQuery::Type::Download;
auto net_query = G()->net_query_creator().create(create_storer(query), remote_.get_dc_id(), net_query_type,
NetQuery::AuthFlag::On);
auto net_query = G()->net_query_creator().create(create_storer(query), remote_.get_dc_id(), net_query_type);
info.queries.push_back(std::move(net_query));
break;
}

View File

@ -189,8 +189,8 @@ void DcAuthManager::dc_loop(DcInfo &dc) {
uint64 id = UniqueId::next();
VLOG(dc) << "Send importAuthorization to " << dc.dc_id;
auto query = G()->net_query_creator().create(
id, create_storer(telegram_api::auth_importAuthorization(dc.export_id, std::move(dc.export_bytes))), dc.dc_id,
NetQuery::Type::Common, NetQuery::AuthFlag::Off);
id, create_storer(telegram_api::auth_importAuthorization(dc.export_id, std::move(dc.export_bytes))),
dc.dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off);
query->total_timeout_limit = 60 * 60 * 24;
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, dc.dc_id.get_raw_id()));
dc.wait_id = id;

View File

@ -34,9 +34,12 @@ class NetQueryCreator {
NetQuery::Type::Common, NetQuery::AuthFlag::On, NetQuery::GzipFlag::Off, 0);
}
Ptr create(const Storer &storer, DcId dc_id = DcId::main(), NetQuery::Type type = NetQuery::Type::Common,
NetQuery::AuthFlag auth_flag = NetQuery::AuthFlag::On) {
return create(UniqueId::next(), storer, dc_id, type, auth_flag);
Ptr create(const Storer &storer, DcId dc_id = DcId::main(), NetQuery::Type type = NetQuery::Type::Common) {
return create(UniqueId::next(), storer, dc_id, type, NetQuery::AuthFlag::On);
}
Ptr create_unauth(const Storer &storer, DcId dc_id = DcId::main()) {
return create(UniqueId::next(), storer, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off);
}
Ptr create(uint64 id, const Storer &storer, DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag);

View File

@ -111,8 +111,8 @@ class TempAuthKeyWatchdog : public NetQueryCallback {
return;
}
LOG(WARNING) << "Start auth_dropTempAuthKeys except keys " << format::as_array(ids);
auto query = G()->net_query_creator().create(create_storer(telegram_api::auth_dropTempAuthKeys(std::move(ids))),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off);
auto query =
G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_dropTempAuthKeys(std::move(ids))));
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this));
}