DcOptionsSet::find_all_connections.

GitOrigin-RevId: ed921667bf1cbc57ad4a442e70a3fd307d839319
This commit is contained in:
levlam 2018-06-03 02:35:32 +03:00
parent 066e6a90e3
commit 13f17714fc
2 changed files with 16 additions and 8 deletions

View File

@ -43,7 +43,7 @@ DcOptions DcOptionsSet::get_dc_options() const {
return result;
}
Result<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_connection(DcId dc_id, bool allow_media_only, bool use_static) {
vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_id, bool allow_media_only, bool use_static) {
std::vector<ConnectionInfo> options;
std::vector<ConnectionInfo> static_options;
@ -97,6 +97,12 @@ Result<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_connection(DcId dc_id, b
options.end());
}
return options;
}
Result<DcOptionsSet::ConnectionInfo> 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::ConnectionInfo> 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;

View File

@ -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<ConnectionInfo> find_all_connections(DcId dc_id, bool allow_media_only, bool use_static);
Result<ConnectionInfo> find_connection(DcId dc_id, bool allow_media_only, bool use_static);
void reset();