From 13f17714fc85c6ad2ad04624346062ab39b09b54 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 3 Jun 2018 02:35:32 +0300 Subject: [PATCH] DcOptionsSet::find_all_connections. GitOrigin-RevId: ed921667bf1cbc57ad4a442e70a3fd307d839319 --- td/telegram/net/DcOptionsSet.cpp | 12 +++++++++--- td/telegram/net/DcOptionsSet.h | 12 +++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/td/telegram/net/DcOptionsSet.cpp b/td/telegram/net/DcOptionsSet.cpp index 4aefd3b7..1df19c51 100644 --- a/td/telegram/net/DcOptionsSet.cpp +++ b/td/telegram/net/DcOptionsSet.cpp @@ -43,7 +43,7 @@ DcOptions DcOptionsSet::get_dc_options() const { return result; } -Result DcOptionsSet::find_connection(DcId dc_id, bool allow_media_only, bool use_static) { +vector DcOptionsSet::find_all_connections(DcId dc_id, bool allow_media_only, bool use_static) { std::vector options; std::vector static_options; @@ -97,6 +97,12 @@ Result DcOptionsSet::find_connection(DcId dc_id, b options.end()); } + return options; +} + +Result DcOptionsSet::find_connection(DcId dc_id, bool allow_media_only, bool use_static) { + auto options = find_all_connections(dc_id, allow_media_only, use_static); + if (options.empty()) { return Status::Error(PSLICE() << "No such connection: " << tag("dc_id", dc_id) << tag("allow_media_only", allow_media_only) << tag("use_static", use_static)); @@ -116,12 +122,12 @@ Result DcOptionsSet::find_connection(DcId dc_id, b if (a_state != b_state) { return a_state < b_state; } - if (a_state == Stat::Ok) { + if (a_state == Stat::State::Ok) { if (a_option.order == b_option.order) { return a_option.use_http < b_option.use_http; } return a_option.order < b_option.order; - } else if (a_state == Stat::Error) { + } else if (a_state == Stat::State::Error) { return a.error_at < b.error_at; } return a_option.order < b_option.order; diff --git a/td/telegram/net/DcOptionsSet.h b/td/telegram/net/DcOptionsSet.h index c5463b76..e6d9b699 100644 --- a/td/telegram/net/DcOptionsSet.h +++ b/td/telegram/net/DcOptionsSet.h @@ -27,7 +27,7 @@ class DcOptionsSet { double ok_at{-1000}; double error_at{-1001}; double check_at{-1002}; - enum State : int32 { Ok, Error, Checking }; + enum class State : int32 { Ok, Error, Checking }; void on_ok() { ok_at = Time::now_cached(); @@ -39,16 +39,16 @@ class DcOptionsSet { check_at = Time::now_cached(); } bool is_ok() const { - return state() == Ok; + return state() == State::Ok; } State state() const { if (ok_at > error_at && ok_at > check_at) { - return Ok; + return State::Ok; } if (check_at > ok_at && check_at > error_at) { - return Checking; + return State::Checking; } - return Error; + return State::Error; } }; @@ -60,6 +60,8 @@ class DcOptionsSet { Stat *stat{nullptr}; }; + vector find_all_connections(DcId dc_id, bool allow_media_only, bool use_static); + Result find_connection(DcId dc_id, bool allow_media_only, bool use_static); void reset();