diff --git a/td/mtproto/utils.cpp b/td/mtproto/utils.cpp index 40274d5b..13e981ae 100644 --- a/td/mtproto/utils.cpp +++ b/td/mtproto/utils.cpp @@ -7,9 +7,6 @@ #include "td/mtproto/utils.h" #include "td/mtproto/mtproto_api.h" -#include "td/telegram/telegram_api.h" - -#include "td/utils/logging.h" namespace td { @@ -17,17 +14,8 @@ TLStorer create_storer(const mtproto_api::Function &funct return TLStorer(function); } -TLStorer create_storer(const telegram_api::Function &function) { - LOG(DEBUG) << "Create storer for " << to_string(function); - return TLStorer(function); -} - TLObjectStorer create_storer(const mtproto_api::Object &object) { return TLObjectStorer(object); } -TLObjectStorer create_storer(const telegram_api::Object &object) { - return TLObjectStorer(object); -} - } // namespace td diff --git a/td/mtproto/utils.h b/td/mtproto/utils.h index d7c6cbbc..8fb4eba5 100644 --- a/td/mtproto/utils.h +++ b/td/mtproto/utils.h @@ -88,17 +88,8 @@ class Object; class Function; } // namespace mtproto_api -namespace telegram_api { -class Object; -class Function; -} // namespace telegram_api - TLStorer create_storer(const mtproto_api::Function &function); -TLStorer create_storer(const telegram_api::Function &function); - TLObjectStorer create_storer(const mtproto_api::Object &object); -TLObjectStorer create_storer(const telegram_api::Object &object); - } // namespace td diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index f6bd54b6..9720e258 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -176,7 +176,7 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) { was_check_bot_token_ = true; start_net_query(NetQueryType::BotAuthentication, G()->net_query_creator().create_unauth( - create_storer(telegram_api::auth_importBotAuthorization(0, api_id_, api_hash_, bot_token_)))); + telegram_api::auth_importBotAuthorization(0, api_id_, api_hash_, bot_token_))); } void AuthManager::request_qr_code_authentication(uint64 query_id, vector other_user_ids) { @@ -214,8 +214,8 @@ void AuthManager::request_qr_code_authentication(uint64 query_id, vector void AuthManager::send_export_login_token_query() { poll_export_login_code_timeout_.cancel_timeout(); start_net_query(NetQueryType::RequestQrCode, - G()->net_query_creator().create_unauth(create_storer( - telegram_api::auth_exportLoginToken(api_id_, api_hash_, vector(other_user_ids_))))); + G()->net_query_creator().create_unauth( + telegram_api::auth_exportLoginToken(api_id_, api_hash_, vector(other_user_ids_)))); } void AuthManager::set_login_token_expires_at(double login_token_expires_at) { @@ -269,9 +269,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_unauth( - create_storer(send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_)))); + start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth( + send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_))); } void AuthManager::resend_authentication_code(uint64 query_id) { @@ -286,8 +285,7 @@ void AuthManager::resend_authentication_code(uint64 query_id) { on_new_query(query_id); - start_net_query(NetQueryType::SendCode, - G()->net_query_creator().create_unauth(create_storer(r_resend_code.move_as_ok()))); + start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth(r_resend_code.move_as_ok())); } void AuthManager::check_code(uint64 query_id, string code) { @@ -298,8 +296,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_unauth(create_storer(telegram_api::auth_signIn( - send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_)))); + G()->net_query_creator().create_unauth(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) { @@ -314,10 +312,9 @@ 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_unauth(create_storer(telegram_api::auth_signUp( - send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), first_name, last_name)))); + start_net_query(NetQueryType::SignUp, G()->net_query_creator().create_unauth(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) { @@ -329,7 +326,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_unauth(create_storer(telegram_api::account_getPassword()))); + G()->net_query_creator().create_unauth(telegram_api::account_getPassword())); } void AuthManager::request_password_recovery(uint64 query_id) { @@ -339,7 +336,7 @@ void AuthManager::request_password_recovery(uint64 query_id) { on_new_query(query_id); start_net_query(NetQueryType::RequestPasswordRecovery, - G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_requestPasswordRecovery()))); + G()->net_query_creator().create_unauth(telegram_api::auth_requestPasswordRecovery())); } void AuthManager::recover_password(uint64 query_id, string code) { @@ -349,7 +346,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_unauth(create_storer(telegram_api::auth_recoverPassword(code)))); + G()->net_query_creator().create_unauth(telegram_api::auth_recoverPassword(code))); } void AuthManager::logout(uint64 query_id) { @@ -380,7 +377,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_unauth(create_storer(telegram_api::account_deleteAccount(reason)))); + G()->net_query_creator().create_unauth(telegram_api::account_deleteAccount(reason))); } void AuthManager::on_closing(bool destroy_flag) { @@ -512,10 +509,9 @@ void AuthManager::on_get_login_token(tl_object_ptrdc_id_; - start_net_query(NetQueryType::ImportQrCode, - G()->net_query_creator().create_unauth( - create_storer(telegram_api::auth_importLoginToken(std::move(token->token_))), - DcId::internal(token->dc_id_))); + start_net_query(NetQueryType::ImportQrCode, G()->net_query_creator().create_unauth( + telegram_api::auth_importLoginToken(std::move(token->token_)), + DcId::internal(token->dc_id_))); break; } case telegram_api::auth_loginTokenSuccess::ID: { @@ -570,8 +566,8 @@ void AuthManager::on_get_password_result(NetQueryPtr &result) { return; } else { start_net_query(NetQueryType::SignIn, - 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_)))); + G()->net_query_creator().create_unauth(telegram_api::auth_signIn( + send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_))); return; } @@ -587,8 +583,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_unauth( - create_storer(telegram_api::auth_checkPassword(std::move(hash))))); + start_net_query(NetQueryType::CheckPassword, + G()->net_query_creator().create_unauth(telegram_api::auth_checkPassword(std::move(hash)))); } else { update_state(State::WaitPassword); if (query_id_ != 0) { @@ -763,8 +759,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_unauth( - create_storer(telegram_api::account_getPassword()), dc_id)); + start_net_query(NetQueryType::GetPassword, + G()->net_query_creator().create_unauth(telegram_api::account_getPassword(), dc_id)); return; } if (result->error().message() == CSlice("PHONE_NUMBER_BANNED")) { diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index dd98b9fa..b148322b 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -504,7 +504,7 @@ ActorOwn<> get_full_config(DcOption option, Promise promise, ActorSh int_dc_id, false /*is_main*/, true /*use_pfs*/, false /*is_cdn*/, false /*need_destroy_auth_key*/, mtproto::AuthKey(), std::vector()); - auto query = G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getConfig()), DcId::empty()); + auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), DcId::empty()); query->total_timeout_limit = 60 * 60 * 24; query->set_callback(actor_shared(this)); query->dispatch_ttl = 0; @@ -931,7 +931,7 @@ void ConfigManager::get_app_config(Promise get_app_config_queries_.push_back(std::move(promise)); if (get_app_config_queries_.size() == 1) { - auto query = G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getAppConfig())); + auto query = G()->net_query_creator().create_unauth(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)); } @@ -987,7 +987,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_unauth(create_storer(telegram_api::help_getConfig()), dc_id); + auto query = G()->net_query_creator().create_unauth(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)); } diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index 4f9f84a4..53dadda8 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -384,7 +384,7 @@ void LanguagePackManager::send_language_get_difference_query(Language *language, Promise>()); }); send_with_promise(G()->net_query_creator().create_unauth( - create_storer(telegram_api::langpack_getDifference(language_pack_, language_code, version))), + telegram_api::langpack_getDifference(language_pack_, language_code, version)), std::move(request_promise)); } @@ -797,9 +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_unauth(create_storer(telegram_api::langpack_getLanguages(language_pack_))), - std::move(request_promise)); + send_with_promise(G()->net_query_creator().create_unauth(telegram_api::langpack_getLanguages(language_pack_)), + std::move(request_promise)); } void LanguagePackManager::search_language_info(string language_code, @@ -819,9 +818,9 @@ 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_unauth( - create_storer(telegram_api::langpack_getLanguage(language_pack_, language_code))), - std::move(request_promise)); + send_with_promise( + G()->net_query_creator().create_unauth(telegram_api::langpack_getLanguage(language_pack_, language_code)), + std::move(request_promise)); } void LanguagePackManager::repair_chosen_language_info() { @@ -1080,9 +1079,9 @@ void LanguagePackManager::get_language_pack_strings(string language_code, vector std::move(language_code), result->version_, false, vector(), std::move(result->strings_), std::move(promise)); }); - send_with_promise(G()->net_query_creator().create_unauth( - create_storer(telegram_api::langpack_getLangPack(language_pack_, language_code))), - std::move(request_promise)); + send_with_promise( + G()->net_query_creator().create_unauth(telegram_api::langpack_getLangPack(language_pack_, language_code)), + std::move(request_promise)); } else { auto request_promise = PromiseCreator::lambda([actor_id = actor_id(this), language_pack = language_pack_, language_code, keys, @@ -1095,8 +1094,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_unauth(create_storer( - telegram_api::langpack_getStrings(language_pack_, language_code, std::move(keys)))), + send_with_promise(G()->net_query_creator().create_unauth( + telegram_api::langpack_getStrings(language_pack_, language_code, std::move(keys))), std::move(request_promise)); } } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index cdb61999..f82e91f0 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -2545,10 +2545,10 @@ class EditInlineMessageQuery : public Td::ResultHandler { LOG(DEBUG) << "Edit inline message with flags " << flags; auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_); - send_query(G()->net_query_creator().create_guest_dc( - create_storer(telegram_api::messages_editInlineBotMessage( - flags, false /*ignored*/, std::move(input_bot_inline_message_id), text, std::move(input_media), - std::move(reply_markup), std::move(entities))), + send_query(G()->net_query_creator().create( + telegram_api::messages_editInlineBotMessage(flags, false /*ignored*/, std::move(input_bot_inline_message_id), + text, std::move(input_media), std::move(reply_markup), + std::move(entities)), dc_id)); } @@ -2650,10 +2650,9 @@ class SetInlineGameScoreQuery : public Td::ResultHandler { LOG(INFO) << "Set inline game score to " << score; auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_); - send_query(G()->net_query_creator().create_guest_dc( - create_storer(telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/, - std::move(input_bot_inline_message_id), - std::move(input_user), score)), + send_query(G()->net_query_creator().create( + telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/, + std::move(input_bot_inline_message_id), std::move(input_user), score), dc_id)); } @@ -2730,10 +2729,9 @@ class GetInlineGameHighScoresQuery : public Td::ResultHandler { random_id_ = random_id; auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_); - send_query( - G()->net_query_creator().create_guest_dc(create_storer(telegram_api::messages_getInlineGameHighScores( - std::move(input_bot_inline_message_id), std::move(input_user))), - dc_id)); + send_query(G()->net_query_creator().create( + telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)), + dc_id)); } void on_result(uint64 id, BufferSlice packet) override { diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 2ee5547b..f3bb976e 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -494,8 +494,8 @@ class GetBankCardInfoQuery : public Td::ResultHandler { } void send(const string &bank_card_number) { - send_query(G()->net_query_creator().create_guest_dc( - create_storer(telegram_api::payments_getBankCardData(bank_card_number)), G()->get_webfile_dc_id())); + send_query(G()->net_query_creator().create(telegram_api::payments_getBankCardData(bank_card_number), + G()->get_webfile_dc_id())); } void on_result(uint64 id, BufferSlice packet) override { @@ -525,7 +525,7 @@ class SendLiteRequestQuery : public Td::ResultHandler { } void send(BufferSlice request) { - send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::wallet_sendLiteRequest(std::move(request))))); + send_query(G()->net_query_creator().create_unauth(telegram_api::wallet_sendLiteRequest(std::move(request)))); } void on_result(uint64 id, BufferSlice packet) override { diff --git a/td/telegram/PhoneNumberManager.cpp b/td/telegram/PhoneNumberManager.cpp index 67d98c52..10f2c481 100644 --- a/td/telegram/PhoneNumberManager.cpp +++ b/td/telegram/PhoneNumberManager.cpp @@ -90,8 +90,7 @@ void PhoneNumberManager::resend_authentication_code(uint64 query_id) { on_new_query(query_id); - start_net_query(NetQueryType::SendCode, - G()->net_query_creator().create_unauth(create_storer(r_resend_code.move_as_ok()))); + start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth(r_resend_code.move_as_ok())); } template diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 71e295bc..3182fdac 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -71,8 +71,7 @@ SecretChatActor::SecretChatActor(int32 id, unique_ptr context, bool can template NetQueryPtr SecretChatActor::create_net_query(QueryType type, const T &function) { return context_->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast(type)), - create_storer(function), DcId::main(), NetQuery::Type::Common, - NetQuery::AuthFlag::On); + function, DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); } void SecretChatActor::update_chat(telegram_api::object_ptr chat) { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0d5acdfd..e75f7958 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -104,7 +104,6 @@ #include "td/mtproto/HandshakeActor.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/TransportType.h" -#include "td/mtproto/utils.h" // for create_storer, fetch_result, etc, TODO #include "td/utils/buffer.h" #include "td/utils/filesystem.h" @@ -157,7 +156,7 @@ class GetNearestDcQuery : public Td::ResultHandler { } void send() { - send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getNearestDc()))); + send_query(G()->net_query_creator().create_unauth(telegram_api::help_getNearestDc())); } void on_result(uint64 id, BufferSlice packet) override { @@ -431,7 +430,7 @@ class GetDeepLinkInfoQuery : public Td::ResultHandler { pos++; } link.truncate(pos); - send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getDeepLinkInfo(link.str())))); + send_query(G()->net_query_creator().create_unauth(telegram_api::help_getDeepLinkInfo(link.str()))); } void on_result(uint64 id, BufferSlice packet) override { @@ -483,8 +482,7 @@ class SaveAppLogQuery : public Td::ResultHandler { vector> input_app_events; input_app_events.push_back( make_tl_object(G()->server_time_cached(), type, peer_id, std::move(data))); - send_query(G()->net_query_creator().create_unauth( - create_storer(telegram_api::help_saveAppLog(std::move(input_app_events))))); + send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events)))); } void on_result(uint64 id, BufferSlice packet) override { @@ -511,7 +509,7 @@ class TestQuery : public Td::ResultHandler { } void send() { - send_query(G()->net_query_creator().create_unauth(create_storer(telegram_api::help_getConfig()))); + send_query(G()->net_query_creator().create_unauth(telegram_api::help_getConfig())); } void on_result(uint64 id, BufferSlice packet) override { diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index f425ac2e..854253f5 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -246,15 +246,19 @@ Result> FileDownloader::start_part(Part part, int32 } #endif DcId dc_id = remote_.is_web() ? G()->get_webfile_dc_id() : remote_.get_dc_id(); - net_query = G()->net_query_creator().create( - UniqueId::next(UniqueId::Type::Default, static_cast(QueryType::Default)), - remote_.is_web() - ? create_storer(telegram_api::upload_getWebFile(remote_.as_input_web_file_location(), - static_cast(part.offset), static_cast(size))) - : create_storer(telegram_api::upload_getFile(flags, false /*ignored*/, false /*ignored*/, - remote_.as_input_file_location(), - static_cast(part.offset), static_cast(size))), - dc_id, net_query_type, NetQuery::AuthFlag::On); + auto id = UniqueId::next(UniqueId::Type::Default, static_cast(QueryType::Default)); + net_query = remote_.is_web() + ? G()->net_query_creator().create( + id, + telegram_api::upload_getWebFile(remote_.as_input_web_file_location(), + static_cast(part.offset), static_cast(size)), + dc_id, net_query_type, NetQuery::AuthFlag::On) + : G()->net_query_creator().create( + id, + telegram_api::upload_getFile(flags, false /*ignored*/, false /*ignored*/, + remote_.as_input_file_location(), + static_cast(part.offset), static_cast(size)), + dc_id, net_query_type, NetQuery::AuthFlag::On); } else { if (remote_.is_web()) { return Status::Error("Can't download web file from CDN"); @@ -267,12 +271,12 @@ Result> FileDownloader::start_part(Part part, int32 LOG(DEBUG) << part.id << " " << to_string(query); net_query = G()->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast(QueryType::CDN)), - create_storer(query), cdn_dc_id_, net_query_type, NetQuery::AuthFlag::Off); + query, cdn_dc_id_, net_query_type, NetQuery::AuthFlag::Off); } else { auto query = telegram_api::upload_reuploadCdnFile(BufferSlice(cdn_file_token_), BufferSlice(it->second)); LOG(DEBUG) << part.id << " " << to_string(query); net_query = G()->net_query_creator().create( - UniqueId::next(UniqueId::Type::Default, static_cast(QueryType::ReuploadCDN)), create_storer(query), + UniqueId::next(UniqueId::Type::Default, static_cast(QueryType::ReuploadCDN)), query, remote_.get_dc_id(), net_query_type, NetQuery::AuthFlag::On); cdn_part_reupload_token_.erase(it); } @@ -466,7 +470,7 @@ Result FileDownloader::check_loop(int64 checked_prefix_si auto query = telegram_api::upload_getFileHashes(remote_.as_input_file_location(), narrow_cast(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); + auto net_query = G()->net_query_creator().create(query, remote_.get_dc_id(), net_query_type); info.queries.push_back(std::move(net_query)); break; } diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 19e27579..25ee6dfb 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -203,9 +203,9 @@ class MapDownloadGenerateActor : public FileGenerateActor { net_callback_ = create_actor("MapDownloadGenerateCallback", actor_id(this)); LOG(INFO) << "Download " << conversion_; - auto query = G()->net_query_creator().create( - create_storer(telegram_api::upload_getWebFile(r_input_web_file.move_as_ok(), 0, 1 << 20)), - G()->get_webfile_dc_id(), NetQuery::Type::DownloadSmall); + auto query = + G()->net_query_creator().create(telegram_api::upload_getWebFile(r_input_web_file.move_as_ok(), 0, 1 << 20), + G()->get_webfile_dc_id(), NetQuery::Type::DownloadSmall); G()->net_query_dispatcher().dispatch_with_callback(std::move(query), {net_callback_.get(), 0}); } diff --git a/td/telegram/files/FileUploader.cpp b/td/telegram/files/FileUploader.cpp index d83d9022..664876a4 100644 --- a/td/telegram/files/FileUploader.cpp +++ b/td/telegram/files/FileUploader.cpp @@ -277,10 +277,10 @@ Result> FileUploader::start_part(Part part, int32 p if (big_flag_) { auto query = telegram_api::upload_saveBigFilePart(file_id_, part.id, local_is_ready_ ? part_count : -1, std::move(bytes)); - net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload); + net_query = G()->net_query_creator().create(query, DcId::main(), NetQuery::Type::Upload); } else { auto query = telegram_api::upload_saveFilePart(file_id_, part.id, std::move(bytes)); - net_query = G()->net_query_creator().create(create_storer(query), DcId::main(), NetQuery::Type::Upload); + net_query = G()->net_query_creator().create(query, DcId::main(), NetQuery::Type::Upload); } net_query->file_type_ = narrow_cast(file_type_); return std::make_pair(std::move(net_query), false); diff --git a/td/telegram/net/DcAuthManager.cpp b/td/telegram/net/DcAuthManager.cpp index 0ed01c1d..9cc4467f 100644 --- a/td/telegram/net/DcAuthManager.cpp +++ b/td/telegram/net/DcAuthManager.cpp @@ -171,9 +171,8 @@ void DcAuthManager::dc_loop(DcInfo &dc) { // send auth.exportAuthorization to auth_dc VLOG(dc) << "Send exportAuthorization to " << dc.dc_id; auto id = UniqueId::next(); - auto query = G()->net_query_creator().create( - id, create_storer(telegram_api::auth_exportAuthorization(dc.dc_id.get_raw_id())), DcId::main(), - NetQuery::Type::Common, NetQuery::AuthFlag::On); + auto query = G()->net_query_creator().create(id, telegram_api::auth_exportAuthorization(dc.dc_id.get_raw_id()), + DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); 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; @@ -189,8 +188,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, 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; diff --git a/td/telegram/net/NetQuery.h b/td/telegram/net/NetQuery.h index 444e2614..ea160a37 100644 --- a/td/telegram/net/NetQuery.h +++ b/td/telegram/net/NetQuery.h @@ -13,7 +13,7 @@ #include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" -#include "td/mtproto/utils.h" // for create_storer, fetch_result TODO +#include "td/mtproto/utils.h" // for fetch_result TODO #include "td/utils/buffer.h" #include "td/utils/common.h" @@ -365,6 +365,7 @@ inline StringBuilder &operator<<(StringBuilder &stream, const NetQuery &net_quer stream << "]"; return stream; } + inline StringBuilder &operator<<(StringBuilder &stream, const NetQueryPtr &net_query_ptr) { return stream << *net_query_ptr; } @@ -397,6 +398,7 @@ Result fetch_result(Result r_query) { inline void NetQueryCallback::on_result(NetQueryPtr query) { on_result_resendable(std::move(query), Auto()); } + inline void NetQueryCallback::on_result_resendable(NetQueryPtr query, Promise promise) { on_result(std::move(query)); } @@ -404,6 +406,7 @@ inline void NetQueryCallback::on_result_resendable(NetQueryPtr query, Promisestart_migrate(sched_id); } + inline void finish_migrate(NetQueryPtr &net_query) { net_query->finish_migrate(); } diff --git a/td/telegram/net/NetQueryCreator.cpp b/td/telegram/net/NetQueryCreator.cpp index 7f3462e0..4a5870a7 100644 --- a/td/telegram/net/NetQueryCreator.cpp +++ b/td/telegram/net/NetQueryCreator.cpp @@ -6,19 +6,24 @@ // #include "td/telegram/net/NetQueryCreator.h" +#include "td/telegram/telegram_api.h" + #include "td/utils/format.h" #include "td/utils/Gzip.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/Storer.h" namespace td { -NetQueryPtr NetQueryCreator::create_regular(const Storer &storer) { - return create(UniqueId::next(), storer, DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); +NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, DcId dc_id, NetQuery::Type type) { + return create(UniqueId::next(), function, dc_id, type, NetQuery::AuthFlag::On); } -NetQueryPtr NetQueryCreator::create(uint64 id, const Storer &storer, DcId dc_id, NetQuery::Type type, +NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &function, DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag) { + LOG(DEBUG) << "Create query " << to_string(function); + auto storer = DefaultStorer(function); BufferSlice slice(storer.size()); auto real_size = storer.store(slice.as_slice().ubegin()); LOG_CHECK(real_size == slice.size()) << real_size << " " << slice.size() << " " diff --git a/td/telegram/net/NetQueryCreator.h b/td/telegram/net/NetQueryCreator.h index 203dbd37..31dab5d3 100644 --- a/td/telegram/net/NetQueryCreator.h +++ b/td/telegram/net/NetQueryCreator.h @@ -6,18 +6,19 @@ // #pragma once -#include "td/mtproto/utils.h" - #include "td/telegram/net/DcId.h" #include "td/telegram/net/NetQuery.h" #include "td/telegram/UniqueId.h" #include "td/utils/buffer.h" #include "td/utils/ObjectPool.h" -#include "td/utils/StorerBase.h" namespace td { +namespace telegram_api { +class Function; +} // namespace telegram_api + class NetQueryCreator { public: NetQueryCreator() { @@ -33,26 +34,15 @@ class NetQueryCreator { NetQuery::Type::Common, NetQuery::AuthFlag::On, NetQuery::GzipFlag::Off, 0); } - template - NetQueryPtr create(const T &function) { - return create_regular(create_storer(function)); + NetQueryPtr create(const telegram_api::Function &function, DcId dc_id = DcId::main(), + NetQuery::Type type = NetQuery::Type::Common); + + NetQueryPtr create_unauth(const telegram_api::Function &function, DcId dc_id = DcId::main()) { + return create(UniqueId::next(), function, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off); } - NetQueryPtr create(const Storer &storer, DcId dc_id, NetQuery::Type type) { - return create(UniqueId::next(), storer, dc_id, type, NetQuery::AuthFlag::On); - } - - NetQueryPtr create_regular(const Storer &storer); - - NetQueryPtr create_guest_dc(const Storer &storer, DcId dc_id) { - return create(UniqueId::next(), storer, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::On); - } - - NetQueryPtr create_unauth(const Storer &storer, DcId dc_id = DcId::main()) { - return create(UniqueId::next(), storer, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off); - } - - NetQueryPtr create(uint64 id, const Storer &storer, DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag); + NetQueryPtr create(uint64 id, const telegram_api::Function &function, DcId dc_id, NetQuery::Type type, + NetQuery::AuthFlag auth_flag); private: ObjectPool object_pool_; diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index 0b4e3ab0..225c95e1 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -25,6 +25,7 @@ #include "td/mtproto/SessionConnection.h" #include "td/mtproto/TransportType.h" +#include "td/utils/as.h" #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" @@ -540,11 +541,8 @@ void Session::on_session_created(uint64 unique_id, uint64 first_id) { LOG(INFO) << "New session " << unique_id << " created with first message_id " << first_id; if (is_main_) { LOG(DEBUG) << "Sending updatesTooLong to force getDifference"; - telegram_api::updatesTooLong too_long; - auto storer = create_storer(too_long); - BufferSlice packet(storer.size()); - auto real_size = storer.store(packet.as_slice().ubegin()); - CHECK(real_size == packet.size()); + BufferSlice packet(4); + as(packet.as_slice().begin()) = telegram_api::updatesTooLong::ID; return_query(G()->net_query_creator().create_update(std::move(packet))); } @@ -1105,9 +1103,8 @@ bool Session::connection_send_check_main_key(ConnectionInfo *info) { LOG(INFO) << "Check main key"; being_checked_main_auth_key_id_ = key_id; last_check_query_id_ = UniqueId::next(UniqueId::BindKey); - NetQueryPtr query = - G()->net_query_creator().create(last_check_query_id_, create_storer(telegram_api::help_getNearestDc()), - DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); + NetQueryPtr query = G()->net_query_creator().create(last_check_query_id_, telegram_api::help_getNearestDc(), + DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); query->dispatch_ttl = 0; query->set_callback(actor_shared(this)); connection_send_query(info, std::move(query)); @@ -1143,8 +1140,8 @@ bool Session::connection_send_bind_key(ConnectionInfo *info) { LOG(INFO) << "Bind key: " << tag("tmp", key_id) << tag("perm", static_cast(perm_auth_key_id)); NetQueryPtr query = G()->net_query_creator().create( last_bind_query_id_, - create_storer(telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expires_at, std::move(encrypted))), - DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); + telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expires_at, std::move(encrypted)), DcId::main(), + NetQuery::Type::Common, NetQuery::AuthFlag::On); query->dispatch_ttl = 0; query->set_callback(actor_shared(this)); connection_send_query(info, std::move(query), message_id); diff --git a/td/telegram/net/TempAuthKeyWatchdog.h b/td/telegram/net/TempAuthKeyWatchdog.h index 691203ca..203ae55b 100644 --- a/td/telegram/net/TempAuthKeyWatchdog.h +++ b/td/telegram/net/TempAuthKeyWatchdog.h @@ -111,8 +111,7 @@ class TempAuthKeyWatchdog : public NetQueryCallback { return; } LOG(WARNING) << "Start auth_dropTempAuthKeys except keys " << format::as_array(ids); - auto query = - G()->net_query_creator().create_unauth(create_storer(telegram_api::auth_dropTempAuthKeys(std::move(ids)))); + auto query = G()->net_query_creator().create_unauth(telegram_api::auth_dropTempAuthKeys(std::move(ids))); G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this)); }