Complete pending preauthentication requests.

GitOrigin-RevId: 8e9b2ec7f8ba8e298f8d95ad7135f7607d440c2f
This commit is contained in:
levlam 2018-05-16 22:35:27 +03:00
parent 29ab63d063
commit 67c00e02ea
6 changed files with 77 additions and 8 deletions

View File

@ -94,6 +94,10 @@ class Global : public ActorContext {
return *net_query_dispatcher_;
}
bool have_net_query_dispatcher() const {
return net_query_dispatcher_ != nullptr;
}
void set_shared_config(std::unique_ptr<ConfigShared> shared_config);
ConfigShared &shared_config() {
@ -223,6 +227,9 @@ class Global : public ActorContext {
MtprotoHeader &mtproto_header();
void set_mtproto_header(std::unique_ptr<MtprotoHeader> mtproto_header);
bool have_mtproto_header() const {
return mtproto_header_ != nullptr;
}
const TdParameters &parameters() const {
return parameters_;

View File

@ -4037,7 +4037,7 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
}
if (is_preauthentication_request(function_id)) {
pending_preauthentication_requests_.emplace_back(id, std::move(function));
// return;
return;
}
return send_error_raw(id, 401, "Initialization parameters are needed");
}
@ -4070,7 +4070,7 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
}
if (is_preauthentication_request(function_id)) {
pending_preauthentication_requests_.emplace_back(id, std::move(function));
// return;
return;
}
return send_error_raw(id, 401, "Database encryption key is needed");
}
@ -4586,6 +4586,16 @@ class Td::UploadFileCallback : public FileManager::UploadCallback {
int VERBOSITY_NAME(td_init) = VERBOSITY_NAME(DEBUG) + 3;
template <class T>
void Td::complete_pending_preauthentication_requests(const T &func) {
for (auto &request : pending_preauthentication_requests_) {
if (request.second != nullptr && func(request.second->get_id())) {
downcast_call(*request.second, [this, id = request.first](auto &request) { this->on_request(id, request); });
request.second = nullptr;
}
}
}
Status Td::init(DbKey key) {
auto current_scheduler_id = Scheduler::instance()->sched_id();
auto scheduler_count = Scheduler::instance()->sched_count();
@ -4631,6 +4641,25 @@ Status Td::init(DbKey key) {
G()->set_connection_creator(std::move(connection_creator));
net_stats_manager_ = std::move(net_stats_manager);
complete_pending_preauthentication_requests([](int32 id) {
switch (id) {
case td_api::processDcUpdate::ID:
case td_api::setNetworkType::ID:
case td_api::getNetworkStatistics::ID:
case td_api::addNetworkStatistics::ID:
case td_api::resetNetworkStatistics::ID:
case td_api::addProxy::ID:
case td_api::enableProxy::ID:
case td_api::disableProxy::ID:
case td_api::removeProxy::ID:
case td_api::getProxies::ID:
case td_api::pingProxy::ID:
return true;
default:
return false;
}
});
}
VLOG(td_init) << "Create TempAuthKeyWatchdog";
@ -4653,6 +4682,16 @@ Status Td::init(DbKey key) {
config_manager_ = create_actor<ConfigManager>("ConfigManager", create_reference());
G()->set_config_manager(config_manager_.get());
complete_pending_preauthentication_requests([](int32 id) {
switch (id) {
case td_api::getOption::ID:
case td_api::setOption::ID:
return true;
default:
return false;
}
});
VLOG(td_init) << "Create NetQueryDispatcher";
auto net_query_dispatcher = std::make_unique<NetQueryDispatcher>([&] { return create_reference(); });
G()->set_net_query_dispatcher(std::move(net_query_dispatcher));
@ -4797,6 +4836,8 @@ Status Td::init(DbKey key) {
updates_manager_->get_difference("init");
}
complete_pending_preauthentication_requests([](int32 id) { return true; });
state_ = State::Run;
return Status::OK();
}

View File

@ -247,6 +247,9 @@ class Td final : public NetQueryCallback {
vector<std::pair<uint64, td_api::object_ptr<td_api::Function>>> pending_preauthentication_requests_;
template <class T>
void complete_pending_preauthentication_requests(const T &func);
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
void on_alarm_timeout(int64 alarm_id);

View File

@ -677,6 +677,16 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getTextEntities>(
"@telegram /test_command https://telegram.org telegram.me @gif @test"));
send_request(td_api::make_object<td_api::getOption>("use_pfs"));
send_request(td_api::make_object<td_api::setOption>(
"use_pfs", td_api::make_object<td_api::optionValueBoolean>(std::time(nullptr) / 86400 % 2 == 0)));
send_request(td_api::make_object<td_api::setOption>("use_storage_optimizer",
td_api::make_object<td_api::optionValueBoolean>(false)));
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeWiFi>()));
send_request(td_api::make_object<td_api::getNetworkStatistics>());
send_request(td_api::make_object<td_api::getCountryCode>());
auto bad_parameters = td_api::make_object<td_api::tdlibParameters>();
bad_parameters->database_directory_ = "/..";
bad_parameters->api_id_ = api_id_;

View File

@ -339,8 +339,7 @@ void ConnectionCreator::enable_proxy_impl(int32 proxy_id) {
if ((active_proxy_id_ != 0 && proxies_[active_proxy_id_].type() == Proxy::Type::Mtproto) ||
proxies_[proxy_id].type() == Proxy::Type::Mtproto) {
G()->mtproto_header().set_proxy(proxies_[proxy_id]);
G()->net_query_dispatcher().update_mtproto_header();
update_mtproto_header(proxies_[proxy_id]);
}
save_proxy_last_used_date(0);
@ -358,8 +357,7 @@ void ConnectionCreator::disable_proxy_impl() {
CHECK(proxies_.count(active_proxy_id_) == 1);
if (proxies_[active_proxy_id_].type() == Proxy::Type::Mtproto) {
G()->mtproto_header().set_proxy(Proxy());
G()->net_query_dispatcher().update_mtproto_header();
update_mtproto_header(Proxy());
}
active_proxy_id_ = 0;
@ -813,6 +811,15 @@ void ConnectionCreator::on_dc_update(DcId dc_id, string ip_port, Promise<> promi
}());
}
void ConnectionCreator::update_mtproto_header(const Proxy &proxy) {
if (G()->have_mtproto_header()) {
G()->mtproto_header().set_proxy(proxy);
}
if (G()->have_net_query_dispatcher()) {
G()->net_query_dispatcher().update_mtproto_header();
}
}
void ConnectionCreator::start_up() {
class StateCallback : public StateManager::Callback {
public:
@ -891,8 +898,7 @@ void ConnectionCreator::start_up() {
if (active_proxy_id_ != 0) {
if (proxies_[active_proxy_id_].type() == Proxy::Type::Mtproto) {
G()->mtproto_header().set_proxy(proxies_[active_proxy_id_]);
G()->net_query_dispatcher().update_mtproto_header();
update_mtproto_header(proxies_[active_proxy_id_]);
}
on_proxy_changed(true);

View File

@ -252,6 +252,8 @@ class ConnectionCreator : public NetQueryCallback {
void on_network(bool network_flag, uint32 network_generation);
void on_online(bool online_flag);
static void update_mtproto_header(const Proxy &proxy);
void client_wakeup(size_t hash);
void client_loop(ClientInfo &client);
struct ConnectionData {