Support sending of queries with a prefix.

This commit is contained in:
levlam 2024-03-07 18:37:28 +03:00
parent f78a0e4326
commit 4bc3b380b8
7 changed files with 47 additions and 21 deletions

View File

@ -24,10 +24,11 @@ inputStickerSetThumbLegacy#dbaeae9 stickerset:InputStickerSet volume_id:long loc
---functions--- ---functions---
test.useError = Error;
test.useConfigSimple = help.ConfigSimple; test.useConfigSimple = help.ConfigSimple;
test.parseInputAppEvent = InputAppEvent; test.parseInputAppEvent = InputAppEvent;
invokeWithBusinessConnectionPrefix connection_id:string = Error;
---types--- ---types---
inputPeerEmpty#7f3b18ea = InputPeer; inputPeerEmpty#7f3b18ea = InputPeer;

View File

@ -67,7 +67,7 @@ SecretChatActor::SecretChatActor(int32 id, unique_ptr<Context> context, bool can
template <class T> template <class T>
NetQueryPtr SecretChatActor::create_net_query(QueryType type, const T &function) { NetQueryPtr SecretChatActor::create_net_query(QueryType type, const T &function) {
return context_->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(type)), return context_->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(type)),
function, {}, DcId::main(), NetQuery::Type::Common, nullptr, function, {}, DcId::main(), NetQuery::Type::Common,
NetQuery::AuthFlag::On); NetQuery::AuthFlag::On);
} }

View File

@ -253,12 +253,12 @@ Result<std::pair<NetQueryPtr, bool>> FileDownloader::start_part(Part part, int32
net_query = net_query =
remote_.is_web() remote_.is_web()
? G()->net_query_creator().create( ? G()->net_query_creator().create(
unique_id, unique_id, nullptr,
telegram_api::upload_getWebFile(remote_.as_input_web_file_location(), narrow_cast<int32>(part.offset), telegram_api::upload_getWebFile(remote_.as_input_web_file_location(), narrow_cast<int32>(part.offset),
narrow_cast<int32>(size)), narrow_cast<int32>(size)),
{}, dc_id, net_query_type, NetQuery::AuthFlag::On) {}, dc_id, net_query_type, NetQuery::AuthFlag::On)
: G()->net_query_creator().create( : G()->net_query_creator().create(
unique_id, unique_id, nullptr,
telegram_api::upload_getFile(flags, false /*ignored*/, false /*ignored*/, telegram_api::upload_getFile(flags, false /*ignored*/, false /*ignored*/,
remote_.as_input_file_location(), part.offset, narrow_cast<int32>(size)), remote_.as_input_file_location(), part.offset, narrow_cast<int32>(size)),
{}, dc_id, net_query_type, NetQuery::AuthFlag::On); {}, dc_id, net_query_type, NetQuery::AuthFlag::On);
@ -272,11 +272,11 @@ Result<std::pair<NetQueryPtr, bool>> FileDownloader::start_part(Part part, int32
cdn_part_file_token_generation_[part.id] = cdn_file_token_generation_; cdn_part_file_token_generation_[part.id] = cdn_file_token_generation_;
net_query = net_query =
G()->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::CDN)), G()->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::CDN)),
query, {}, cdn_dc_id_, net_query_type, NetQuery::AuthFlag::Off); nullptr, query, {}, cdn_dc_id_, net_query_type, NetQuery::AuthFlag::Off);
} else { } else {
auto query = telegram_api::upload_reuploadCdnFile(BufferSlice(cdn_file_token_), BufferSlice(it->second)); auto query = telegram_api::upload_reuploadCdnFile(BufferSlice(cdn_file_token_), BufferSlice(it->second));
net_query = G()->net_query_creator().create( net_query = G()->net_query_creator().create(
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::ReuploadCDN)), query, {}, UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::ReuploadCDN)), nullptr, query, {},
remote_.get_dc_id(), net_query_type, NetQuery::AuthFlag::On); remote_.get_dc_id(), net_query_type, NetQuery::AuthFlag::On);
cdn_part_reupload_token_.erase(it); cdn_part_reupload_token_.erase(it);
} }

View File

@ -156,8 +156,9 @@ void DcAuthManager::dc_loop(DcInfo &dc) {
// send auth.exportAuthorization to auth_dc // send auth.exportAuthorization to auth_dc
VLOG(dc) << "Send exportAuthorization to " << dc.dc_id; VLOG(dc) << "Send exportAuthorization to " << dc.dc_id;
auto id = UniqueId::next(); auto id = UniqueId::next();
auto query = G()->net_query_creator().create(id, telegram_api::auth_exportAuthorization(dc.dc_id.get_raw_id()), auto query =
{}, DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); G()->net_query_creator().create(id, nullptr, 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; 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())); G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, dc.dc_id.get_raw_id()));
dc.wait_id = id; dc.wait_id = id;
@ -173,7 +174,7 @@ void DcAuthManager::dc_loop(DcInfo &dc) {
uint64 id = UniqueId::next(); uint64 id = UniqueId::next();
VLOG(dc) << "Send importAuthorization to " << dc.dc_id; VLOG(dc) << "Send importAuthorization to " << dc.dc_id;
auto query = G()->net_query_creator().create( auto query = G()->net_query_creator().create(
id, telegram_api::auth_importAuthorization(dc.export_id, std::move(dc.export_bytes)), {}, dc.dc_id, id, nullptr, telegram_api::auth_importAuthorization(dc.export_id, std::move(dc.export_bytes)), {}, dc.dc_id,
NetQuery::Type::Common, NetQuery::AuthFlag::Off); NetQuery::Type::Common, NetQuery::AuthFlag::Off);
query->total_timeout_limit_ = 60 * 60 * 24; 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())); G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, dc.dc_id.get_raw_id()));

View File

@ -29,17 +29,36 @@ NetQueryCreator::NetQueryCreator(std::shared_ptr<NetQueryStats> net_query_stats)
NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, vector<ChainId> chain_ids, DcId dc_id, NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, vector<ChainId> chain_ids, DcId dc_id,
NetQuery::Type type) { NetQuery::Type type) {
return create(UniqueId::next(), function, std::move(chain_ids), dc_id, type, NetQuery::AuthFlag::On); return create(UniqueId::next(), nullptr, function, std::move(chain_ids), dc_id, type, NetQuery::AuthFlag::On);
} }
NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &function, vector<ChainId> &&chain_ids, NetQueryPtr NetQueryCreator::create_with_prefix(const unique_ptr<telegram_api::Function> &prefix,
DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag) { const telegram_api::Function &function, DcId dc_id,
NetQuery::Type type) {
return create(UniqueId::next(), prefix, function, {}, dc_id, type, NetQuery::AuthFlag::On);
}
NetQueryPtr NetQueryCreator::create(uint64 id, const unique_ptr<telegram_api::Function> &prefix,
const telegram_api::Function &function, vector<ChainId> &&chain_ids, DcId dc_id,
NetQuery::Type type, NetQuery::AuthFlag auth_flag) {
LOG(INFO) << "Create query " << to_string(function); LOG(INFO) << "Create query " << to_string(function);
string prefix_str;
if (prefix != nullptr) {
auto storer = DefaultStorer<telegram_api::Function>(*prefix);
prefix_str.resize(storer.size());
auto real_size = storer.store(MutableSlice(prefix_str).ubegin());
CHECK(real_size == prefix_str.size());
}
auto storer = DefaultStorer<telegram_api::Function>(function); auto storer = DefaultStorer<telegram_api::Function>(function);
BufferSlice slice(storer.size()); BufferSlice slice(prefix_str.size() + storer.size());
auto real_size = storer.store(slice.as_mutable_slice().ubegin()); auto real_size = storer.store(slice.as_mutable_slice().ubegin() + prefix_str.size());
LOG_CHECK(real_size == slice.size()) << real_size << " " << slice.size() << " " LOG_CHECK(prefix_str.size() + real_size == slice.size())
<< format::as_hex_dump<4>(slice.as_slice()); << prefix_str.size() << ' ' << real_size << ' ' << slice.size() << ' '
<< format::as_hex_dump<4>(slice.as_slice());
if (prefix != nullptr) {
slice.as_mutable_slice().copy_from(prefix_str);
}
size_t min_gzipped_size = 128; size_t min_gzipped_size = 128;
int32 tl_constructor = function.get_id(); int32 tl_constructor = function.get_id();

View File

@ -35,10 +35,15 @@ class NetQueryCreator {
NetQuery::Type type = NetQuery::Type::Common); NetQuery::Type type = NetQuery::Type::Common);
NetQueryPtr create_unauth(const telegram_api::Function &function, DcId dc_id = DcId::main()) { 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); return create(UniqueId::next(), nullptr, function, {}, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off);
} }
NetQueryPtr create(uint64 id, const telegram_api::Function &function, vector<ChainId> &&chain_ids, DcId dc_id, NetQueryPtr create_with_prefix(const unique_ptr<telegram_api::Function> &prefix,
const telegram_api::Function &function, DcId dc_id,
NetQuery::Type type = NetQuery::Type::Common);
NetQueryPtr create(uint64 id, const unique_ptr<telegram_api::Function> &prefix,
const telegram_api::Function &function, vector<ChainId> &&chain_ids, DcId dc_id,
NetQuery::Type type, NetQuery::AuthFlag auth_flag); NetQuery::Type type, NetQuery::AuthFlag auth_flag);
private: private:

View File

@ -1345,8 +1345,8 @@ bool Session::connection_send_check_main_key(ConnectionInfo *info) {
LOG(INFO) << "Check main key"; LOG(INFO) << "Check main key";
being_checked_main_auth_key_id_ = key_id; being_checked_main_auth_key_id_ = key_id;
last_check_query_id_ = UniqueId::next(UniqueId::BindKey); last_check_query_id_ = UniqueId::next(UniqueId::BindKey);
NetQueryPtr query = G()->net_query_creator().create(last_check_query_id_, telegram_api::help_getNearestDc(), {}, NetQueryPtr query = G()->net_query_creator().create(last_check_query_id_, nullptr, telegram_api::help_getNearestDc(),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On); {}, DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::On);
query->dispatch_ttl_ = 0; query->dispatch_ttl_ = 0;
query->set_callback(actor_shared(this)); query->set_callback(actor_shared(this));
connection_send_query(info, std::move(query)); connection_send_query(info, std::move(query));
@ -1382,7 +1382,7 @@ bool Session::connection_send_bind_key(ConnectionInfo *info) {
LOG(INFO) << "Bind key: " << tag("tmp", key_id) << tag("perm", static_cast<uint64>(perm_auth_key_id)); LOG(INFO) << "Bind key: " << tag("tmp", key_id) << tag("perm", static_cast<uint64>(perm_auth_key_id));
NetQueryPtr query = G()->net_query_creator().create( NetQueryPtr query = G()->net_query_creator().create(
last_bind_query_id_, last_bind_query_id_, nullptr,
telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expires_at, std::move(encrypted)), {}, DcId::main(), telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expires_at, std::move(encrypted)), {}, DcId::main(),
NetQuery::Type::Common, NetQuery::AuthFlag::On); NetQuery::Type::Common, NetQuery::AuthFlag::On);
query->dispatch_ttl_ = 0; query->dispatch_ttl_ = 0;