summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-04 14:41:38 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-04 14:41:38 +0300
commit7e22e9dbb26d4aaefe7d925d58d3cba7c78d5823 (patch)
tree199feb0d409c654b8d8821a87424522e3336213e
parentAdd support for local mirrors (diff)
downloadidfetch-7e22e9dbb26d4aaefe7d925d58d3cba7c78d5823.tar.gz
idfetch-7e22e9dbb26d4aaefe7d925d58d3cba7c78d5823.tar.bz2
idfetch-7e22e9dbb26d4aaefe7d925d58d3cba7c78d5823.zip
Add option [network_mirrors].ONLY_LOCAL_WHEN_POSSIBLE to network#.conf files.
SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1 If NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 this option will be ignored. - If set to 1, segget will not use remote mirrors with equal or lower priority until all mirrors in network0_mirrors.conf file have failed. - If set to 0, segget will use remote mirrors with equal priority or mirrors with lower priority when this network has NO free connections (see option NETWORK_MAX_CONNECTIONS in [network_connections] section of this file). Default: only_local_when_possible=1
-rw-r--r--segget/config.cpp61
-rw-r--r--segget/config.h53
-rw-r--r--segget/distfile.cpp58
-rw-r--r--segget/mirror.h4
-rw-r--r--segget/mirror_local.cpp124
-rw-r--r--segget/network.cpp19
-rw-r--r--segget/network.h17
-rw-r--r--segget/network0.conf13
-rw-r--r--segget/network1.conf13
-rw-r--r--segget/networkbroker.cpp35
-rw-r--r--segget/networkbroker.h10
-rw-r--r--segget/segget.cpp11
-rw-r--r--segget/segment.cpp9
-rw-r--r--segget/settings.cpp6
-rw-r--r--segget/settings.h2
-rw-r--r--segget/str.cpp16
-rw-r--r--segget/str.h1
17 files changed, 194 insertions, 258 deletions
diff --git a/segget/config.cpp b/segget/config.cpp
index e75418b..540c641 100644
--- a/segget/config.cpp
+++ b/segget/config.cpp
@@ -24,48 +24,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __CONFIG_H__
-#define __CONFIG_H__
+#include "config.h"
-#include <string>
-#include <map>
-#include "str.h"
-#include "tui.h"
-using namespace std;
-
-map<string,string> content_;
-
-class ConfigFile {
- private:
- string config_file_name;
- public:
- ConfigFile(string const& file_name):
- config_file_name("")
- {config_file_name=file_name;load_settings_from_config_file();};
- void load_settings_from_config_file();
- int set(string &dst,string const& section, string const& entry) const;
- int set(ulong &dst,string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const;
- int set(bool &dst,string const& section, string const& entry) const;
-};
-
-#endif
-#include <fstream>
-
-string trim(std::string const& source, char const* delims = " \t\r\n") {
- string result(source);
- string::size_type index = result.find_last_not_of(delims);
- if(index != string::npos)
- result.erase(++index);
-
- index = result.find_first_not_of(delims);
- if(index != string::npos)
- result.erase(0, index);
- else
- result.erase();
- return result;
-}
-
-void ConfigFile::load_settings_from_config_file() {
+void Tconfig::load_settings_from_config_file() {
ifstream file;
file.exceptions (ifstream::failbit | ifstream::badbit);
@@ -101,13 +62,17 @@ void ConfigFile::load_settings_from_config_file() {
content_[inSection+'/'+name]=noupper(value);
}
- }
- catch(...){
+ }catch(ifstream::failure e){
+ if (!file.eof()){
+ error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading it.");
+ return;
+ }
+ }catch(...){
error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it.");
}
}
-int ConfigFile::set(string &dst, string const& section, string const& entry) const {
+int Tconfig::set(string &dst, string const& section, string const& entry) const {
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
@@ -121,7 +86,7 @@ int ConfigFile::set(string &dst, string const& section, string const& entry) con
return 0;
}
}
-int ConfigFile::set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const {
+int Tconfig::set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const {
uint return_value;
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
@@ -156,7 +121,7 @@ int ConfigFile::set(ulong &dst, string const& section, string const& entry, uint
}
}
}
-int ConfigFile::set(bool &dst, string const& section, string const& entry) const {
+int Tconfig::set(bool &dst, string const& section, string const& entry) const {
uint return_value;
map<std::string,string>::const_iterator ci = content_.find(section + '/' + entry);
@@ -188,4 +153,8 @@ int ConfigFile::set(bool &dst, string const& section, string const& entry) const
return 1;
}
}
+}
+
+void Tconfig::clear(){
+ content_.clear();
} \ No newline at end of file
diff --git a/segget/config.h b/segget/config.h
new file mode 100644
index 0000000..db77347
--- /dev/null
+++ b/segget/config.h
@@ -0,0 +1,53 @@
+/*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#include <string>
+#include <map>
+#include <fstream>
+#include "str.h"
+#include "tui.h"
+using namespace std;
+
+class Tconfig {
+ private:
+ map<string,string> content_;
+ string config_file_name;
+ public:
+ Tconfig(string const& file_name):
+ content_(),
+ config_file_name("")
+ {config_file_name=file_name;load_settings_from_config_file();};
+ void load_settings_from_config_file();
+ int set(string &dst,string const& section, string const& entry) const;
+ int set(ulong &dst,string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const;
+ int set(bool &dst,string const& section, string const& entry) const;
+ void clear();
+};
+
+#endif \ No newline at end of file
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index df972bc..f98d811 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -28,9 +28,7 @@
void Tdistfile::init(){
for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
- network_distfile_brokers_array[network_num].network_num=network_num;
- Tmirror cur_mirror;
- network_array[network_num].benchmarked_mirror_list.push_back(cur_mirror);
+ network_distfile_brokers_array[network_num].init(network_num);
}
}
void Tdistfile::load_url_list(json_object* json_array_distfile_urllist){
@@ -211,46 +209,60 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
//----------------------------------------------------------------------------------------------------------
int best_local_network_num=-1;
int best_network_num=-1;
+ bool allow_remote_mirrors=true;
for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
//if network priority set then it's active
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 (network_distfile_brokers_array[network_num].get_allowed_status()){
- debug(" Allowed network#:"+toString(network_num));
- if (network_array[network_num].use_own_mirror_list_only_on){
+ debug(" network_priority="+toString(network_array[network_num].priority));
+ if (network_array[network_num].use_own_mirror_list_only_on){
+ if (network_array[network_num].has_free_connections()){
+// debug(" Allowed network#:"+toString(network_num));
if ((best_local_network_num==-1)
or (network_array[best_local_network_num].active_connections_num>network_array[network_num].active_connections_num)){
best_local_network_num=network_num;
debug(" Replace best LOCAL network to network#:"+toString(network_num));
}
}else{
- 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 to network#:"+toString(network_num));
+ if (network_array[network_num].only_local_when_possible){
+ if (!network_distfile_brokers_array[network_num].have_all_mirrors_failed()){
+ allow_remote_mirrors=false;
+ debug("Network"+toString(network_num)+" forbids using remote mirrors because not all local mirrors have failed");
+ }
}
}
+ }else{
+ if (network_array[network_num].has_free_connections()){
+ 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 to network#:"+toString(network_num));
+ }
+ }
+ }
//work with network
- }
}
}
}
if (best_local_network_num!=-1){
//best network has been found
//work with network
- debug(" So best LOCAL network is network#:"+toString(best_local_network_num));
- int resultik=choose_best_local_mirror(cm, connection_num, best_local_network_num, seg_num);
- return resultik;
+ debug(" So best LOCAL network is network#:"+toString(best_local_network_num));
+ int res=choose_best_local_mirror(cm, connection_num, best_local_network_num, seg_num);
+ return res;
}else{
- // remote_mirrors_go_second
- if (best_network_num!=-1){
- //best network has been found
- //work with network
- debug(" So best network is network#:"+toString(best_network_num));
- return choose_best_mirror(cm, connection_num, best_network_num, seg_num);
+ if (allow_remote_mirrors){ //since all local failed, go to remote
+ // remote_mirrors_go_second
+ if (best_network_num!=-1){
+ //best network has been found
+ //work with network
+ debug(" So best network is network#:"+toString(best_network_num));
+ return choose_best_mirror(cm, connection_num, best_network_num, seg_num);
+ }
+ }else{
+ debug("Restricted to local mirrors only when possible");
}
}
}
diff --git a/segget/mirror.h b/segget/mirror.h
index 0dff255..765708f 100644
--- a/segget/mirror.h
+++ b/segget/mirror.h
@@ -37,15 +37,15 @@ using namespace std;
class Tmirror{
private:
- string url;
uint active_num;
public:
+ string url;
ulong dld_time;
ulong dld_size;
double honesty;
Tmirror():
- url(""),
active_num(0),
+ url(""),
dld_time(0),
dld_size(1),
honesty(1){};
diff --git a/segget/mirror_local.cpp b/segget/mirror_local.cpp
deleted file mode 100644
index e29217f..0000000
--- a/segget/mirror_local.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
-* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
-*
-* Project: IDFetch.
-* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
-* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
-* Mentoring organization: Gentoo Linux.
-* Sponsored by GSOC 2010.
-*
-* This file is part of Segget.
-*
-* Segget is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* Segget is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with Segget; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-#ifndef __MIRROR_BENCHMARKER_H__
-#define __MIRROR_BENCHMARKER_H__
-
-#include <string>
-#include <map>
-#include "str.h"
-#include "tui.h"
-#include "settings.cpp"
-using namespace std;
-
-extern Tsettings settings;
-class Tmirror_local{
- private:
- uint active_num;
- public:
- ulong dld_time;
- ulong dld_size;
- double honesty;
- Tmirror():
- active_num(0),
- dld_time(0),
- dld_size(1),
- honesty(1){};
- void start();
- void stop(ulong time, uint size);
- double mirror_on_the_wall();
- uint get_active_num(){return active_num;};
-};
-
-map<string,Tmirror *> mirror_local_list;
-
-double Tmirror_local::mirror_on_the_wall(){
- try{
- double criterion=honesty*1000000000*dld_time/dld_size;
- honesty=honesty*100/(100+settings.benchmark_oblivion);
- return criterion;
- }catch(...){
- error_log("Error in mirror.cpp: mirror_on_the_wall()");
- return 0;
- }
-}
-void Tmirror::start(){
- try{
- if (!dld_time)
- dld_time=1;
- active_num++;
- honesty=1;
- }catch(...){
- error_log("Error in mirror.cpp: start()");
- }
-}
-
-void Tmirror::stop(ulong time, uint size){
- try{
- dld_time+=time/1000;
- dld_size+=size;
- honesty=1;
- debug(toString(time)+"---"+toString(size));
- active_num--;
- }catch(...){
- error_log("Error in mirror.cpp: stop()");
- }
-}
-
-Tmirror* find_mirror(string mirror_url){
- try{
- map<string,Tmirror*>::const_iterator mirror_iterator = mirror_list.find(mirror_url);
- if (mirror_iterator==mirror_list.end()){
- Tmirror * Pnew_mirror=new Tmirror;
- debug("Cant find mirror:"+mirror_url+" - creating new record");
- mirror_list[mirror_url]=Pnew_mirror;
- return Pnew_mirror;
- }
- else{
- debug("Found mirror:"+mirror_url);
- debug("==================>>");
- debug(" time:"+toString(mirror_iterator->second->dld_time));
- debug(" size:"+toString(mirror_iterator->second->dld_size));
- debug(" honesty:"+toString(mirror_iterator->second->honesty));
- debug(" criterion:"+toString(mirror_iterator->second->mirror_on_the_wall()));
- return mirror_iterator->second;
- }
- }catch(...){
- error_log("Error in mirror.cpp: find_mirror()");
- return 0;
- }
-}
-
-string strip_mirror_name(string path){
- try{
- string mirror_name;
- mirror_name=path.substr(0,path.find("/",(path.find("://",0)+3)));
- return mirror_name;
- }catch(...){
- error_log("Error in mirror.cpp: strip_mirror_name()");
- return "";
- }
-}
-#endif \ No newline at end of file
diff --git a/segget/network.cpp b/segget/network.cpp
index e2c288b..f37ad81 100644
--- a/segget/network.cpp
+++ b/segget/network.cpp
@@ -46,6 +46,15 @@ void Tnetwork::load_mirror_list(){
if (mirror_line[0] == ';') continue;
mirror_list.push_back(mirror_line);
debug("LOCAL_MIRROR_ADDED:"+mirror_line);
+//=======================================================================================================
+//
+// You don't need mirror_list, you have everything in benchmarked_mirror_list
+//
+//
+ Tmirror cur_mirror;
+ cur_mirror.url=mirror_line;
+ benchmarked_mirror_list.push_back(cur_mirror);
+
}
}
catch(...){
@@ -56,7 +65,7 @@ void Tnetwork::load_mirror_list(){
void Tnetwork::init(uint priority_value){
try{
priority=priority_value;
- ConfigFile conf("network"+toString(network_num)+".conf");
+ Tconfig conf("network"+toString(network_num)+".conf");
conf.set(bind_interface, "network_bind", "bind_interface");
conf.set(max_connections, "network_connections", "max_connections",1,MAX_CONNECTS);
conf.set(connection_timeout, "network_connections", "connection_timeout",1,1000);
@@ -77,9 +86,11 @@ void Tnetwork::init(uint priority_value){
conf.set(use_own_mirror_list_only_on, "network_mirrors", "use_own_mirror_list_only_on");
if (use_own_mirror_list_only_on){
+ conf.set(only_local_when_possible, "network_mirrors", "only_local_when_possible");
load_mirror_list();
- log("Network#"+toString(network_num)+" LOCAL_MIRROR_LIST size:"+toString(mirror_list.size()));
+ log("Settings: Network"+toString(network_num)+" local mirror_list size:"+toString(mirror_list.size()));
}
+ conf.clear();
}
catch(...)
{
@@ -87,7 +98,7 @@ void Tnetwork::init(uint priority_value){
}
}
-bool Tnetwork::get_busy_status(){
+bool Tnetwork::has_free_connections(){
if (active_connections_num<max_connections){
return true;
}else{
@@ -103,4 +114,4 @@ bool Tnetwork::connect(){
}else{
return false;
}
-}
+} \ No newline at end of file
diff --git a/segget/network.h b/segget/network.h
index 6653196..2b48126 100644
--- a/segget/network.h
+++ b/segget/network.h
@@ -31,6 +31,7 @@
#include "str.h"
#include <vector>
#include "mirror.h"
+#include "config.h"
//#include "tui.h"
//#include "settings.cpp"
using namespace std;
@@ -58,9 +59,6 @@ class Tnetwork{
ulong max_connection_speed;
ulong current_speed_time_interval_msecs;
string bind_interface;
- //mirrors
- ulong max_connections_num_per_mirror;
- ulong benchmark_oblivion;
//user-data
string user_agent;
//proxy
@@ -69,8 +67,10 @@ class Tnetwork{
bool proxy_off;
string proxy_user;
string proxy_password;
+ //mirrors
bool use_own_mirror_list_only_on;
- Tnetwork():
+ bool only_local_when_possible;
+ Tnetwork():
mirror_list(),
benchmarked_mirror_list(),
active_connections_num(0),
@@ -87,9 +87,6 @@ class Tnetwork{
max_connection_speed(0),
current_speed_time_interval_msecs(1000),
bind_interface("none"),
- //mirrors
- max_connections_num_per_mirror(1),
- benchmark_oblivion(5),
//user-data
user_agent("segget"),
//proxy
@@ -98,10 +95,12 @@ class Tnetwork{
proxy_off(1),
proxy_user("none"),
proxy_password("none"),
- use_own_mirror_list_only_on(0)
+ //mirrors
+ use_own_mirror_list_only_on(0),
+ only_local_when_possible(1)
{network_count++;};
void init(uint priority_value);
- bool get_busy_status();
+ bool has_free_connections();
bool connect();
void disconnect(){active_connections_num--;};
};
diff --git a/segget/network0.conf b/segget/network0.conf
index 215c3aa..aabc4c2 100644
--- a/segget/network0.conf
+++ b/segget/network0.conf
@@ -178,4 +178,15 @@ proxy_off=1
# and will NOT use the list from network0_mirrors.conf file
# Default:
# use_own_mirror_list_only_on=0
-use_own_mirror_list_only_on=0 \ No newline at end of file
+use_own_mirror_list_only_on=0
+
+# SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1
+# If NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 this option will be ignored.
+# - If set to 1, segget will not use remote mirrors with equal or lower priority
+# untill all mirrors in network0_mirrors.conf file have failed.
+# - If set to 0, segget will use remote mirrors with equal priority or mirrors
+# with lower priority when this network has NO free connections (see option
+# NETWORK_MAX_CONNECTIONS in [network_connections] section of this file).
+# Default:
+# only_local_when_possible=1
+only_local_when_possible=1
diff --git a/segget/network1.conf b/segget/network1.conf
index dc7b80b..510e9d3 100644
--- a/segget/network1.conf
+++ b/segget/network1.conf
@@ -178,4 +178,15 @@ proxy_off=1
# and will NOT use the list from network1_mirrors.conf file
# Default:
# use_own_mirror_list_only_on=0
-use_own_mirror_list_only_on=1 \ No newline at end of file
+use_own_mirror_list_only_on=1
+
+# SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1
+# If NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 this option will be ignored.
+# - If set to 1, segget will not use remote mirrors with equal or lower priority
+# untill all mirrors in network0_mirrors.conf file have failed.
+# - If set to 0, segget will use remote mirrors with equal priority or mirrors
+# with lower priority when this network has NO free connections (see option
+# NETWORK_MAX_CONNECTIONS in [network_connections] section of this file).
+# Default:
+# only_local_when_possible=1
+only_local_when_possible=0 \ No newline at end of file
diff --git a/segget/networkbroker.cpp b/segget/networkbroker.cpp
index 8b7212f..f72e8a2 100644
--- a/segget/networkbroker.cpp
+++ b/segget/networkbroker.cpp
@@ -25,32 +25,15 @@
*/
#include "networkbroker.h"
-
-bool Tnetwork_distfile_broker::get_allowed_status(){
- debug(" get_allowed_status_for_network_num="+toString(network_num));
- return network_array[network_num].get_busy_status();
+void Tnetwork_distfile_broker::init(ulong network_number){
+ network_num=network_number;
+ if (network_array[network_num].use_own_mirror_list_only_on){
+ // create flags for each mirror from this network
+ mirror_fails_vector.insert(mirror_fails_vector.begin(),network_array[network_num].mirror_list.size(),false);
+ }
}
-Tmirror* Tnetwork_distfile_broker::find_mirror(string mirror_url){
- try{
- map<string,Tmirror*>::const_iterator mirror_iterator = mirror_list.find(mirror_url);
- if (mirror_iterator==mirror_list.end()){
- Tmirror * Pnew_mirror=new Tmirror;
- debug("Cant find mirror:"+mirror_url+" - creating new record");
- mirror_list[mirror_url]=Pnew_mirror;
- return Pnew_mirror;
- }
- else{
- debug("Found mirror:"+mirror_url);
- debug("==================>>");
- debug(" time:"+toString(mirror_iterator->second->dld_time));
- debug(" size:"+toString(mirror_iterator->second->dld_size));
- debug(" honesty:"+toString(mirror_iterator->second->honesty));
- debug(" criterion:"+toString(mirror_iterator->second->mirror_on_the_wall()));
- return mirror_iterator->second;
- }
- }catch(...){
- error_log("Error in mirror.cpp: find_mirror()");
- return 0;
- }
+bool Tnetwork_distfile_broker::have_all_mirrors_failed(){
+ debug(" get_allowed_status_for_network_num="+toString(network_num));
+ return network_array[network_num].has_free_connections();
} \ No newline at end of file
diff --git a/segget/networkbroker.h b/segget/networkbroker.h
index 79781f2..e8db32b 100644
--- a/segget/networkbroker.h
+++ b/segget/networkbroker.h
@@ -29,14 +29,14 @@
class Tnetwork_distfile_broker{
public:
// map<string,Tmirror *> benchmarked_mirror_list;
+ vector<bool> mirror_fails_vector;
ulong network_num;
- bool local;
Tnetwork_distfile_broker():
- network_num(0),
- local(0)
+ mirror_fails_vector(),
+ network_num(0)
{};
- bool get_allowed_status();
- Tmirror* find_mirror(string mirror_url);
+ void init(ulong network_number);
+ bool have_all_mirrors_failed();
};
#endif
diff --git a/segget/segget.cpp b/segget/segget.cpp
index e4b13f1..2f6981c 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -30,17 +30,18 @@
#include <iostream>
#include <json/json.h>
#include <ncurses.h>
-#include "pkg.cpp"
+#include "config.cpp"
+#include "connection.cpp"
#include "distfile.cpp"
#include "mirror.cpp"
-#include "segment.cpp"
-#include "connection.cpp"
-#include "utils.cpp"
#include "network.cpp"
#include "networkbroker.cpp"
+#include "pkg.cpp"
+#include "segment.cpp"
+#include "settings.cpp"
#include "str.cpp"
#include "tui.cpp"
-#include "settings.cpp"
+#include "utils.cpp"
//#include "settings.cpp"
using namespace std;
diff --git a/segget/segment.cpp b/segget/segment.cpp
index 56c5542..81c658a 100644
--- a/segget/segment.cpp
+++ b/segget/segment.cpp
@@ -58,19 +58,14 @@ void Tsegment::set_segment(Tdistfile *prnt_distfile, uint seg_num, string distfi
}
void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint network_num, uint distfile_num, uint mirror_num){
try{
- string url__;
- debug("==========NETWORK:"+toString(network_num));
- debug("==========local_on:"+toString(network_array[network_num].use_own_mirror_list_only_on));
+ debug("NETWORK:"+toString(network_num)+(network_array[network_num].use_own_mirror_list_only_on ? " - LOCAL": " - REMOTE"));
if (network_array[network_num].use_own_mirror_list_only_on){
url=network_array[network_num].mirror_list[mirror_num]+parent_distfile->name;
- url__=network_array[network_num].mirror_list[mirror_num]+parent_distfile->name;
- debug("URL:"+url);
- debug("URL___________________:"+url__);
+ debug(" URL:"+url);
}else{
url=parent_distfile->url_list[mirror_num];
}
msg_connecting(con_num,distfile_num, segment_num,"Downloading from "+url);
- msg_connecting(con_num,distfile_num, segment_num,"Downloading from "+url);
segments_in_progress[con_num]=this;
status=DOWNLOADING;
downloaded_bytes=0;
diff --git a/segget/settings.cpp b/segget/settings.cpp
index f6e6c91..66214e0 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -28,7 +28,7 @@
void Tsettings::init(){
try{
- ConfigFile conf("segget.conf");
+ Tconfig conf("segget.conf");
conf.set(general_log_file, "logs", "general_log_file");
conf.set(logs_dir, "logs", "logs_dir");
conf.set(error_log_file, "logs", "error_log_file");
@@ -66,8 +66,8 @@ void Tsettings::init(){
network_array[network_num].init(cur_network_priority);
}
}
- }
- catch(...)
+ conf.clear();
+ }catch(...)
{
error_log_no_msg("Error calling msg() in settings.cpp: load_from_conf_file()");
}
diff --git a/segget/settings.h b/segget/settings.h
index a9d048b..c8aab5e 100644
--- a/segget/settings.h
+++ b/segget/settings.h
@@ -28,7 +28,7 @@
#define __SETTINGS_H__
#include <string>
-#include "config.cpp"
+#include "config.h"
#include "network.h"
//#include "tui.cpp"
#define MAX_CONNECTS 20 /* number of simultaneous transfers */
diff --git a/segget/str.cpp b/segget/str.cpp
index 63cc680..094d0e0 100644
--- a/segget/str.cpp
+++ b/segget/str.cpp
@@ -52,4 +52,18 @@ int lower_char(int c)
string noupper(string s){
transform(s.begin(), s.end(), s.begin(), lower_char);
return s;
-} \ No newline at end of file
+}
+
+string trim(std::string const& source, char const* delims) {
+ string result(source);
+ string::size_type index = result.find_last_not_of(delims);
+ if(index != string::npos)
+ result.erase(++index);
+
+ index = result.find_first_not_of(delims);
+ if(index != string::npos)
+ result.erase(0, index);
+ else
+ result.erase();
+ return result;
+}
diff --git a/segget/str.h b/segget/str.h
index c2b653c..438117e 100644
--- a/segget/str.h
+++ b/segget/str.h
@@ -33,6 +33,7 @@ using namespace std;
template<typename T> string toString(T t);
template<typename T> string field(string prefix,T t, int width);
+string trim(std::string const& source, char const* delims = " \t\r\n");
int lower_char(int c);
string noupper(string s);
#endif \ No newline at end of file