diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-03 20:25:17 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-03 20:25:17 +0300 |
commit | 3cf1bc826d1725e5578e42de42898a48463aaaed (patch) | |
tree | df742d2daf3a31ad30056d699b996edb4fe4fa6f | |
parent | Add support for several networks to segget (diff) | |
download | idfetch-3cf1bc826d1725e5578e42de42898a48463aaaed.tar.gz idfetch-3cf1bc826d1725e5578e42de42898a48463aaaed.tar.bz2 idfetch-3cf1bc826d1725e5578e42de42898a48463aaaed.zip |
Add competitions among networks with equal priority levels.
Network with the smallest active_connections_num wins.
-rw-r--r-- | segget/distfile.cpp | 27 | ||||
-rw-r--r-- | segget/distfile.h | 2 | ||||
-rw-r--r-- | segget/network.h | 2 |
3 files changed, 25 insertions, 6 deletions
diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 9968658..4852108 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -173,20 +173,39 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){ //choose network for (uint cur_network_priority=10; cur_network_priority>0; cur_network_priority--){ debug("cur_network_priority="+toString(cur_network_priority)); +//---------------------------------------------------------------------------------------------------------- +// +// Several criterions can be used here to choose among networks with equal priority: +// min_active_connection, min_ratio_active_to_max_connection, best_speed_accocding_to_stats, etc +// add these options to segget.conf file +// +//---------------------------------------------------------------------------------------------------------- + int best_network_num=-1; for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){ debug(" network_num="+toString(network_num)); //if network priority set then it's active -// if (network_array[network_num].priority){ + if (network_array[network_num].priority){ if (network_array[network_num].priority==cur_network_priority){ debug(" network_priority="+toString(network_array[network_num].priority)); if (networkbrokers_array[network_num].get_allowed_status()){ - debug(" choose_best_mirror_for_network:"+toString(network_num)); + debug(" Allowed network#:"+toString(network_num)); + if + ((best_network_num==-1) + or + (network_array[best_network_num].active_connections_num>network_array[network_num].active_connections_num)){ + best_network_num=network_num; + debug(" Replace best network to network#:"+toString(network_num)); + } //work with network - return choose_best_mirror(cm, connection_num, network_num, seg_num); } } } -// } + } + if (best_network_num!=-1){ + //best network has been found + debug(" So best network is network#:"+toString(best_network_num)); + return choose_best_mirror(cm, connection_num, best_network_num, seg_num); + } } }catch(...){ error_log("Error: distfile.cpp: provide_segment()"); diff --git a/segget/distfile.h b/segget/distfile.h index 62f8dc6..c1e38c2 100644 --- a/segget/distfile.h +++ b/segget/distfile.h @@ -53,6 +53,7 @@ class Tdistfile{ private: uint dld_segments_count; Tnetworkbroker networkbrokers_array[MAX_NETWORKS]; + bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num); public: bool downloaded; uint active_connections_num; @@ -94,7 +95,6 @@ class Tdistfile{ void load_distfile_from_json(json_object* json_obj_distfile); void load_url_list(json_object* json_array_distfile_urllist); void split_into_segments(); - bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num); int provide_segment(CURLM* cm, uint connection_num, uint seg_num); void inc_dld_segments_count(Tsegment * current_segment); int combine_segments(); diff --git a/segget/network.h b/segget/network.h index 830473e..b37642e 100644 --- a/segget/network.h +++ b/segget/network.h @@ -38,8 +38,8 @@ using namespace std; class Tnetwork{ static uint network_count; private: - uint active_connections_num; public: + uint active_connections_num; //network uint network_num; uint priority; |