summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-03 17:40:46 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-03 17:40:46 +0300
commite48f6311ff9f85b2bddf1e9fb1ea5a6734ea5e75 (patch)
tree2b3b75fbc2d1f534e14a822ec85efeb74ec22615
parentAdd option [pkg_list].del_pkg_list_when_dld_finished (diff)
downloadidfetch-e48f6311ff9f85b2bddf1e9fb1ea5a6734ea5e75.tar.gz
idfetch-e48f6311ff9f85b2bddf1e9fb1ea5a6734ea5e75.tar.bz2
idfetch-e48f6311ff9f85b2bddf1e9fb1ea5a6734ea5e75.zip
Add support for several networks to segget
Add [networks] section to segget.conf [networks] network0_priority=10 network1_priority=0 network2_priority=0 network3_priority=0 network4_priority=0 network5_priority=0 network6_priority=0 network7_priority=0 network8_priority=0 network9_priority=0 2) Following options moved from segget.conf to network#.conf [network_bind] bind_interface=none [network_connections] max_connections=2 connection_timeout=15 ftp_response_timeout=180 timeout=500 low_connection_speed_limit=1000 low_connection_speed_time=10 max_connection_speed=3000 [network_protocols] [network_user_data] user_agent=segget [network_proxy] proxy_ip_or_name=none proxy_port=3128 proxy_user=none proxy_password=none proxy_off=1 [network_mirrors] use_own_mirror_list_on=0
-rw-r--r--segget/checksum.cpp2
-rw-r--r--segget/config.cpp63
-rw-r--r--segget/connection.cpp8
-rw-r--r--segget/connection.h12
-rw-r--r--segget/distfile.cpp103
-rw-r--r--segget/distfile.h104
-rw-r--r--segget/logs/.gitignore0
-rw-r--r--segget/mirror.cpp2
-rw-r--r--segget/network.cpp71
-rw-r--r--segget/network.h103
-rw-r--r--segget/network0.conf179
-rw-r--r--segget/network1.conf179
-rw-r--r--segget/networkbroker.cpp32
-rw-r--r--segget/networkbroker.h40
-rw-r--r--segget/pkg.cpp2
-rw-r--r--segget/segget.conf246
-rw-r--r--segget/segget.cpp9
-rw-r--r--segget/segment.cpp52
-rw-r--r--segget/segment.h4
-rw-r--r--segget/settings.cpp34
-rw-r--r--segget/settings.h4
-rw-r--r--segget/stats.cpp2
-rw-r--r--segget/str.cpp25
-rw-r--r--segget/str.h38
-rw-r--r--segget/tui.cpp34
-rw-r--r--segget/tui.h6
-rw-r--r--segget/utils.cpp2
-rw-r--r--segget/utils.h3
28 files changed, 1026 insertions, 333 deletions
diff --git a/segget/checksum.cpp b/segget/checksum.cpp
index 7e3368a..ed7d3fa 100644
--- a/segget/checksum.cpp
+++ b/segget/checksum.cpp
@@ -37,7 +37,7 @@
#include "cryptopp/files.h"
#include "cryptopp/hex.h"
#include "tui.cpp"
-#include "str.cpp"
+#include "str.h"
bool rmd160_ok(string distfile_filename, string portage_hash){
try{
diff --git a/segget/config.cpp b/segget/config.cpp
index 8b29d6b..2a7f5cc 100644
--- a/segget/config.cpp
+++ b/segget/config.cpp
@@ -36,14 +36,16 @@ using namespace std;
map<string,string> content_;
class ConfigFile {
-
-public:
-
- ConfigFile(std::string const& configFile);
-
- 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;
+ 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
@@ -63,14 +65,15 @@ string trim(std::string const& source, char const* delims = " \t\r\n") {
return result;
}
-ConfigFile::ConfigFile(string const& configFile) {
+void ConfigFile::load_settings_from_config_file() {
+ ;
ifstream file;
file.exceptions (ifstream::failbit | ifstream::badbit);
try{
- file.open(configFile.c_str());
+ file.open(config_file_name.c_str());
}
catch(...){
- error_log("Error opening settings file: "+configFile+". Default settings will be used. Check if config file exists and segget has rights to access it.");
+ error_log("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it.");
return;
}
try{
@@ -96,11 +99,11 @@ ConfigFile::ConfigFile(string const& configFile) {
name = trim(line.substr(0,posEqual));
value = trim(line.substr(posEqual+1));
- content_[inSection+'/'+name]=value;
+ content_[inSection+'/'+name]=noupper(value);
}
}
catch(...){
- error_log("Settings file: "+configFile+" was opened, but an error occured while reading settings from it.");
+ error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it.");
}
}
@@ -108,13 +111,13 @@ int ConfigFile::set(string &dst, string const& section, string const& entry) con
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- log("! Settings: ["+section+"]."+entry+" has not been set in segget.conf.");
- log("! Settings: ["+section+"]."+entry+"="+dst+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst+". Default value forced.");
return 1;
}
else{
dst=ci->second;
- log("Settings: ["+section+"]."+entry+"="+dst);
+ log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst);
return 0;
}
}
@@ -123,32 +126,32 @@ int ConfigFile::set(ulong &dst, string const& section, string const& entry, uint
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- log("! Settings: ["+section+"]."+entry+" has not been set in segget.conf.");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
else{
return_value=atoi(ci->second.c_str());
if (return_value==0)
if (toString(return_value)!=ci->second){
- log("! Settings: ["+section+"]."+entry
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have an integer value in range from "+toString(min_limit)
+" to "+toString(max_limit)
+". Can't convert "+ci->second
+" to integer. ");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
if ((return_value>=min_limit) and (return_value<=max_limit)){
//everything is ok
- log("Settings: ["+section+"]."+entry+"="+toString(return_value));
+ log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
dst=return_value;
return 0;
}else{
- log("! Settings: ["+section+"]."+entry
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have an integer value in range from "+toString(min_limit)
+" to "+toString(max_limit)+".");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
}
@@ -158,30 +161,30 @@ int ConfigFile::set(bool &dst, string const& section, string const& entry) const
map<std::string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
- log("! Settings: ["+section+"]."+entry+" has not been set in segget.conf.");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
else{
return_value=atoi(ci->second.c_str());
if (return_value==0)
if (toString(return_value)!=ci->second){
- log("! Settings: ["+section+"]."+entry
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have a boolean value: 0 or 1"
+". Can't convert "+ci->second
+" to 0 or 1. ");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
if ((return_value==0) or (return_value==1)){
//everything is ok
- log("Settings: ["+section+"]."+entry+"="+toString(return_value));
+ log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value));
dst=return_value;
return 0;
}else{
- log("! Settings: ["+section+"]."+entry
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry
+" must have a boolean value: 0 or 1");
- log("! Settings: ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
+ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced.");
return 1;
}
}
diff --git a/segget/connection.cpp b/segget/connection.cpp
index 4014749..1cbbc44 100644
--- a/segget/connection.cpp
+++ b/segget/connection.cpp
@@ -25,12 +25,14 @@
*/
#include "connection.h"
-void Tconnection::start(){
+void Tconnection::start(uint network_number){
try{
+ network_num=network_number;
total_dld_bytes=0;
bytes_per_last_interval=0;
gettimeofday(&start_time,NULL);
active=true;
+ network_array[network_num].connect();
}catch(...){
error_log("Error in connection.cpp: start()");
}
@@ -38,7 +40,9 @@ void Tconnection::start(){
void Tconnection::stop(){
try{
+ msg_clean_connection(connection_num);
active=false;
+ network_array[network_num].disconnect();
}catch(...){
error_log("Error in connection.cpp: stop()");
}
@@ -57,7 +61,7 @@ void Tconnection::show_connection_progress(ulong time_diff){
try{
if (active){
stats.total_bytes_per_last_interval+=bytes_per_last_interval;
- msg_segment_progress(segment->connection_num,
+ msg_segment_progress(segment->connection_num, network_num,
segment->segment_num, segment->try_num,
segment->downloaded_bytes,
segment->segment_size,
diff --git a/segget/connection.h b/segget/connection.h
index f9bf314..2648775 100644
--- a/segget/connection.h
+++ b/segget/connection.h
@@ -35,7 +35,10 @@ class Tsegment;
using namespace std;
class Tconnection{
+ static uint total_connections;
private:
+ uint connection_num;
+ uint network_num;
bool active;
ulong total_dld_bytes;
ulong bytes_per_last_interval;
@@ -43,19 +46,20 @@ class Tconnection{
timeval start_time;
Tsegment *segment;
Tconnection():
+ connection_num(total_connections),
+ network_num(0),
active(0),
total_dld_bytes(0),
bytes_per_last_interval(0),
start_time(),
- segment(0){};
- void start();
+ segment(0){total_connections++;};
+ void start(uint network_number);
void stop();
void inc_bytes_per_last_interval(ulong new_bytes_count);
void show_connection_progress(ulong time_diff);
};
-#define MAX_CONNECTS 6 /* number of simultaneous transfers */
time_t prev_time;
-
+uint Tconnection::total_connections=0;
Tconnection connection_array[MAX_CONNECTS];
#endif \ No newline at end of file
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 1f8a339..9968658 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -23,65 +23,14 @@
* License along with Segget; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __DISTFILE_H__
-#define __DISTFILE_H__
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#ifndef WIN32
-# include <unistd.h>
-#endif
-#include <curl/multi.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fstream>
-#include <iostream>
-#include <json/json.h>
-#include "segment.cpp"
-#include "mirror.cpp"
-#include "checksum.cpp"
-
-using namespace std;
-
-typedef unsigned int uint;
-
-class Tdistfile{
- private:
- uint dld_segments_count;
- public:
- bool downloaded;
- uint active_connections_num;
- string *url_list;
- uint url_num;
- uint segment_num;
- uint segments_count;
- Tsegment *dn_segments;
- string name;
- uint num;
- ulong size;
- string RMD160;
- string SHA1;
- string SHA256;
- uint url_count;
- uint segment_size;
- Tdistfile(): dld_segments_count(0), downloaded(0),
- active_connections_num(0),
- url_list(0),url_num(0),segment_num(0),segments_count(0),
- dn_segments(0),name(""),num(0),size(0),
- RMD160(""),SHA1(""),SHA256(""),url_count(0),segment_size(settings.max_segment_size){};
- Tdistfile(const Tdistfile &L); // copy constructor
- Tdistfile & operator=(const Tdistfile &L);
- ~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();
- int provide_segment(CURLM* cm, uint connection_num, uint seg_num);
- void inc_dld_segments_count(Tsegment * current_segment);
- int combine_segments();
- bool check_if_dld();
-};
+#include "distfile.h"
+void Tdistfile::init(){
+ for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
+ networkbrokers_array[network_num].network_num=network_num;
+ }
+}
void Tdistfile::load_url_list(json_object* json_array_distfile_urllist){
try{
url_count=json_object_array_length(json_array_distfile_urllist);
@@ -182,11 +131,7 @@ Tdistfile::~Tdistfile(){
error_log("Error: distfile.cpp: ~Tdistfile()");
}
}
-
-int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
- try{
- active_connections_num++;
-
+bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num){
Tmirror *Pcurr_mirror;
Tmirror *Pbest_mirror=0; // the best isn't set let's find it
uint best_mirror_num=-1; // the best isn't set let's find it
@@ -211,11 +156,38 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
if (Pbest_mirror){
debug("Downloading from BEST_MIRROR:"+url_list[best_mirror_num]);
Pbest_mirror->start();
- dn_segments[seg_num].prepare_for_connection(cm, connection_num, num, url_list[best_mirror_num]);
+ dn_segments[seg_num].prepare_for_connection(cm, connection_num, network_num, num, url_list[best_mirror_num]);
connection_array[connection_num].segment=&dn_segments[seg_num];
+ return 0;
}
- else
+ else{
error_log("Can't choose mirror for segment:"+dn_segments[seg_num].file_name);
+ return 1;
+ }
+}
+
+int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
+
+ try{
+ active_connections_num++;
+ //choose network
+ for (uint cur_network_priority=10; cur_network_priority>0; cur_network_priority--){
+ debug("cur_network_priority="+toString(cur_network_priority));
+ 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==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));
+ //work with network
+ return choose_best_mirror(cm, connection_num, network_num, seg_num);
+ }
+ }
+ }
+// }
+ }
}catch(...){
error_log("Error: distfile.cpp: provide_segment()");
return 1;
@@ -327,5 +299,4 @@ int Tdistfile::combine_segments(){
return 7;
}
return 0;
-}
-#endif \ No newline at end of file
+} \ No newline at end of file
diff --git a/segget/distfile.h b/segget/distfile.h
new file mode 100644
index 0000000..62f8dc6
--- /dev/null
+++ b/segget/distfile.h
@@ -0,0 +1,104 @@
+/*
+* 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 __DISTFILE_H__
+#define __DISTFILE_H__
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifndef WIN32
+# include <unistd.h>
+#endif
+#include <curl/multi.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fstream>
+#include <iostream>
+#include <json/json.h>
+#include "segment.cpp"
+#include "mirror.cpp"
+#include "checksum.cpp"
+#include "network.h"
+#include "networkbroker.h"
+
+using namespace std;
+
+typedef unsigned int uint;
+
+class Tdistfile{
+ private:
+ uint dld_segments_count;
+ Tnetworkbroker networkbrokers_array[MAX_NETWORKS];
+ public:
+ bool downloaded;
+ uint active_connections_num;
+ string *url_list;
+ uint url_num;
+ uint segment_num;
+ uint segments_count;
+ Tsegment *dn_segments;
+ string name;
+ uint num;
+ ulong size;
+ string RMD160;
+ string SHA1;
+ string SHA256;
+ uint url_count;
+ uint segment_size;
+ Tdistfile():
+ dld_segments_count(0),
+ downloaded(0),
+ active_connections_num(0),
+ url_list(0),
+ url_num(0),
+ segment_num(0),
+ segments_count(0),
+ dn_segments(0),
+ name(""),
+ num(0),
+ size(0),
+ RMD160(""),
+ SHA1(""),
+ SHA256(""),
+ url_count(0),
+ segment_size(settings.max_segment_size)
+ {init();};
+ Tdistfile(const Tdistfile &L); // copy constructor
+ Tdistfile & operator=(const Tdistfile &L);
+ ~Tdistfile();
+ void init();
+ 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();
+ bool check_if_dld();
+};
+
+#endif \ No newline at end of file
diff --git a/segget/logs/.gitignore b/segget/logs/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/segget/logs/.gitignore
diff --git a/segget/mirror.cpp b/segget/mirror.cpp
index 4d66ea8..b9cbd2d 100644
--- a/segget/mirror.cpp
+++ b/segget/mirror.cpp
@@ -28,7 +28,7 @@
#include <string>
#include <map>
-#include "str.cpp"
+#include "str.h"
#include "tui.h"
#include "settings.cpp"
using namespace std;
diff --git a/segget/network.cpp b/segget/network.cpp
new file mode 100644
index 0000000..c975c94
--- /dev/null
+++ b/segget/network.cpp
@@ -0,0 +1,71 @@
+/*
+* 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
+*/
+#include "network.h"
+
+void Tnetwork::init(uint priority_value){
+ try{
+ priority=priority_value;
+ ConfigFile 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);
+ conf.set(ftp_response_timeout, "network_connections", "ftp_response_timeout",1,-1);
+ conf.set(time_out, "network_connections", "timeout",100,-1);
+ conf.set(low_connection_speed_limit, "network_connections", "low_connection_speed_limit",1,-1);
+ conf.set(low_connection_speed_time, "network_connections", "low_connection_speed_time",1,600);
+ conf.set(max_connection_speed, "network_connections", "max_connection_speed",1,-1);
+
+ conf.set(user_agent, "network_user_data", "user_agent");
+
+ conf.set(proxy_ip_or_name, "network_proxy", "proxy_ip_or_name");
+ conf.set(proxy_port, "network_proxy", "proxy_port",1,65535);
+ conf.set(proxy_off, "network_proxy", "proxy_off");
+ conf.set(proxy_user, "network_proxy", "proxy_user");
+ conf.set(proxy_password, "network_proxy", "proxy_password");
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error calling msg() in settings.cpp: load_from_conf_file()");
+ }
+}
+
+bool Tnetwork::get_busy_status(){
+ if (active_connections_num<max_connections){
+ return true;
+ }else{
+ return false;
+ }
+}
+
+
+bool Tnetwork::connect(){
+ if (active_connections_num<max_connections){
+ active_connections_num++;
+ return true;
+ }else{
+ return false;
+ }
+}
diff --git a/segget/network.h b/segget/network.h
new file mode 100644
index 0000000..830473e
--- /dev/null
+++ b/segget/network.h
@@ -0,0 +1,103 @@
+/*
+* 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 __NETWORK_H__
+#define __NETWORK_H__
+
+//#include <string>
+//#include <map>
+#include "str.h"
+//#include "tui.h"
+//#include "settings.cpp"
+using namespace std;
+
+#define MAX_NETWORKS 10
+
+class Tnetwork{
+ static uint network_count;
+ private:
+ uint active_connections_num;
+ public:
+ //network
+ uint network_num;
+ uint priority;
+ //connections
+ ulong max_connections;
+ ulong connection_timeout;
+ ulong ftp_response_timeout;
+ ulong time_out;
+ ulong low_connection_speed_limit;
+ ulong low_connection_speed_time;
+ 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
+ string proxy_ip_or_name;
+ ulong proxy_port;
+ bool proxy_off;
+ string proxy_user;
+ string proxy_password;
+ Tnetwork():
+ //private:
+ active_connections_num(0),
+ //network
+ network_num(network_count),
+ priority(0),
+ //connections
+ max_connections(6),
+ connection_timeout(15),
+ ftp_response_timeout(180),
+ time_out(500),
+ low_connection_speed_limit(1000),
+ low_connection_speed_time(10),
+ 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
+ proxy_ip_or_name("none"),
+ proxy_port(3128),
+ proxy_off(1),
+ proxy_user("none"),
+ proxy_password("none")
+ {network_count++;};
+ void init(uint priority_value);
+ bool get_busy_status();
+ bool connect();
+ void disconnect(){active_connections_num--;};
+};
+
+uint Tnetwork::network_count=0;
+Tnetwork network_array[MAX_NETWORKS];
+#endif \ No newline at end of file
diff --git a/segget/network0.conf b/segget/network0.conf
new file mode 100644
index 0000000..764ecca
--- /dev/null
+++ b/segget/network0.conf
@@ -0,0 +1,179 @@
+[network_bind]
+# BIND INTERFACE / IP
+# Pass a string as parameter. This sets the interface name to use as outgoing
+# network interface. The name can be an interface name, an IP address, or a host
+# name. No binding is set by default.
+# Default:
+# bind_interface=none
+bind_interface=none
+
+# BIND LOCALPORT
+# Pass a long. This sets the local port number of the socket used for connection.
+# This can be used in combination with BIND_INTERFACE and you are recommended to
+# use BIND_LOCALPORTRANGE as well when this is set.
+# Valid port numbers are 1 - 65535.
+
+# BIND_LOCALPORTRANGE
+# Pass a long. This is the number of attempts segget should make to find a
+# working local port number. It starts with the given BIND_LOCALPORT and adds
+# one to the number for each retry. Setting this to 1 or below will make segget
+# do only one try for the exact port number. Port numbers by nature are scarce
+# resources that will be busy at times so setting this value to something too
+# low might cause unnecessary connection setup failures.
+
+[network_connections]
+# NETWORK_MAX_CONNECTIONS
+# Define maximum number of connections
+# Minimum value: 1
+# Maximum value: 20
+# Default:
+# max_connections=10
+max_connections=2
+
+# CONNECTION_TIMEOUT
+# Set the number of seconds to wait while trying to connect. Use 0 to wait
+# indefinitely. Pass a long. It should contain the maximum time in seconds that
+# you allow the connection to the server to take. This only limits the connection
+# phase, once it has connected, this option is of no more use. Set to zero to
+# disable connection timeout (it will then only timeout on the system's internal
+# timeouts). See also the TIMEOUT option.
+# Minimum value: 1
+# Maximum value: 1000
+# Default:
+# connection_timeout=15
+connection_timeout=15
+
+# FTP_RESPONSE_TIMEOUT
+# Set a timeout period (in seconds) on the amount of time that the server is
+# allowed to take in order to generate a response message for a command before the
+# session is considered hung. While awaiting for a response, this value overrides
+# TIMEOUT. It is recommended that if used in conjunction with TIMEOUT, you set
+# FTP_RESPONSE_TIMEOUT to a value smaller than TIMEOUT.
+# Minimum value: 1
+# Maximum value: -1 (for no limit)
+# Default:
+# ftp_response_timeout=180
+ftp_response_timeout=180
+
+# TIMEOUT
+# maximum amount of time to download segment in seconds
+# Set the maximum number of seconds for a connection to execute.
+# Pass a long as parameter containing the maximum time in seconds that you allow
+# the transfer operation to take. Normally, name lookups can take a considerable
+# time and limiting operations to less than a few minutes risk aborting perfectly
+# normal operations.
+# Minimum value: 100
+# Maximum value: -1 (for no limit)
+# Default:
+# timeout=500
+timeout=500
+
+# LOW_CONNECTION_SPEED_LIMIT
+# Define the low speed limit for connection. Pass a long as parameter. It
+# contains the transfer speed in bytes per second that the transfer should be
+# below during LOW_CONNECTION_SPEED_TIME seconds to consider it too slow and abort.
+# Minimum value: 1
+# Maximum value: -1 (-1 for no limit)
+# Default:
+# low_connection_speed_limit=1000
+low_connection_speed_limit=1000
+
+# LOW_CONNECTION_SPEED_TIME
+# Pass a long as parameter. It contains the time in seconds that the transfer
+# should be below the LOW_CONNECTION_SPEED_LIMIT to consider it too slow and abort.
+# Minimum value: 1
+# Maximum value: 600
+# Default:
+# low_connection_speed_time=10
+low_connection_speed_time=10
+
+# MAX_CONNECTION_SPEED
+# If a download exceeds this speed (counted in bytes per second) on cumulative
+# average during the transfer, the transfer will pause to keep the average rate
+# less than or equal to the parameter value. Defaults to unlimited speed.
+# Minimum value: 1
+# Maximum value: -1 (-1 for no limit)
+# Default:
+# max_connection_speed=0
+max_connection_speed=3000
+
+[network_protocols]
+# SYNOPSIS: http_on=0 | 1
+# Default:
+# http_on=1
+# NOT IMPLEMENTED YET: http_on=1
+
+# SYNOPSIS: ftp_on=0 | 1
+# Default:
+# ftp_on=1
+# NOT IMPLEMENTED YET: ftp_on=1
+
+[network_user_data]
+# USER_AGENT
+# Set the User-Agent: header in the http request sent to the remote server.
+# This can be used to fool servers or scripts.
+# Default:
+# user_agent=segget
+user_agent=segget
+
+# Specify the user and password for authentication on a ftp servers.
+# NOT IMPLEMENTED YET: ftp-user=anonymous
+# NOT IMPLEMENTED YET: ftp-password=me@mail.ru
+
+[network_proxy]
+# PROXY_IP_OR_NAME
+# Specify a proxy to use (address and port).
+# Set HTTP proxy to use. The parameter should be a string holding the proxy host
+# name or dotted IP address. To specify port number in this string,
+# append :[port] to the end of the host name. The proxy string may be prefixed
+# with [protocol]:// since any such prefix will be ignored. The proxy's port
+# number may optionally be specified with the separate option. If not specified,
+# by default port 1080 will be used for proxies.
+# When you tell segget to use an HTTP proxy, segget will transparently convert
+# operations to HTTP even if you specify an FTP URL etc.
+# Segget respects the environment variables http_proxy, ftp_proxy, all_proxy etc,
+# if any of those are set. The PROXY option does however override any possibly
+# set environment variables.
+# Default:
+# proxy_ip_or_name=none
+proxy_ip_or_name=none
+
+# PROXY_PORT
+# Set the proxy port to connect to unless it is specified in the PROXY option.
+# Minimum value: 1
+# Maximum value: 65535
+# Default:
+# proxy_port=3128
+proxy_port=3128
+
+# PROXY_USER
+# Set user name to use for the transfer while connecting to Proxy.
+# The PROXY_USER option should be used in same way as the PROXY_PASSWORD is used.
+# In order to specify the password to be used in conjunction with the user name
+# use the PROXY_PASSWORD option.
+# Default:
+# proxy_user=none
+proxy_user=none
+
+# PROXY_PASSWORD
+# Set password to use for the transfer while connecting to Proxy.
+# The PROXY_PASSWORD option should be used in conjunction with the PROXY_USER
+# option.
+# Default:
+# proxy_password=none
+proxy_password=none
+
+# SYNOPSIS: proxy_off=0 | 1
+# Setting the proxy_off=1 will explicitly disable the use of a proxy, even if
+# there is an environment variable set for it.
+# Default:
+# proxy_off=1
+proxy_off=1
+
+[network_mirrors]
+# SYNOPSIS: NETWORK_USES_OWN_MIRROR_LIST_ON=0 | 1
+# - If set to 1, segget will replace mirror list provided by portage system with
+# the list from network1_mirros.list
+# Default:
+# use_own_mirror_list_on=0
+use_own_mirror_list_on=0 \ No newline at end of file
diff --git a/segget/network1.conf b/segget/network1.conf
new file mode 100644
index 0000000..de08c95
--- /dev/null
+++ b/segget/network1.conf
@@ -0,0 +1,179 @@
+[network_bind]
+# BIND INTERFACE / IP
+# Pass a string as parameter. This sets the interface name to use as outgoing
+# network interface. The name can be an interface name, an IP address, or a host
+# name. No binding is set by default.
+# Default:
+# bind_interface=none
+bind_interface=none
+
+# BIND LOCALPORT
+# Pass a long. This sets the local port number of the socket used for connection.
+# This can be used in combination with BIND_INTERFACE and you are recommended to
+# use BIND_LOCALPORTRANGE as well when this is set.
+# Valid port numbers are 1 - 65535.
+
+# BIND_LOCALPORTRANGE
+# Pass a long. This is the number of attempts segget should make to find a
+# working local port number. It starts with the given BIND_LOCALPORT and adds
+# one to the number for each retry. Setting this to 1 or below will make segget
+# do only one try for the exact port number. Port numbers by nature are scarce
+# resources that will be busy at times so setting this value to something too
+# low might cause unnecessary connection setup failures.
+
+[network_connections]
+# NETWORK_MAX_CONNECTIONS
+# Define maximum number of connections
+# Minimum value: 1
+# Maximum value: 20
+# Default:
+# max_connections=10
+max_connections=3
+
+# CONNECTION_TIMEOUT
+# Set the number of seconds to wait while trying to connect. Use 0 to wait
+# indefinitely. Pass a long. It should contain the maximum time in seconds that
+# you allow the connection to the server to take. This only limits the connection
+# phase, once it has connected, this option is of no more use. Set to zero to
+# disable connection timeout (it will then only timeout on the system's internal
+# timeouts). See also the TIMEOUT option.
+# Minimum value: 1
+# Maximum value: 1000
+# Default:
+# connection_timeout=15
+connection_timeout=15
+
+# FTP_RESPONSE_TIMEOUT
+# Set a timeout period (in seconds) on the amount of time that the server is
+# allowed to take in order to generate a response message for a command before the
+# session is considered hung. While awaiting for a response, this value overrides
+# TIMEOUT. It is recommended that if used in conjunction with TIMEOUT, you set
+# FTP_RESPONSE_TIMEOUT to a value smaller than TIMEOUT.
+# Minimum value: 1
+# Maximum value: -1 (for no limit)
+# Default:
+# ftp_response_timeout=180
+ftp_response_timeout=180
+
+# TIMEOUT
+# maximum amount of time to download segment in seconds
+# Set the maximum number of seconds for a connection to execute.
+# Pass a long as parameter containing the maximum time in seconds that you allow
+# the transfer operation to take. Normally, name lookups can take a considerable
+# time and limiting operations to less than a few minutes risk aborting perfectly
+# normal operations.
+# Minimum value: 100
+# Maximum value: -1 (for no limit)
+# Default:
+# timeout=500
+timeout=500
+
+# LOW_CONNECTION_SPEED_LIMIT
+# Define the low speed limit for connection. Pass a long as parameter. It
+# contains the transfer speed in bytes per second that the transfer should be
+# below during LOW_CONNECTION_SPEED_TIME seconds to consider it too slow and abort.
+# Minimum value: 1
+# Maximum value: -1 (-1 for no limit)
+# Default:
+# low_connection_speed_limit=1000
+low_connection_speed_limit=1000
+
+# LOW_CONNECTION_SPEED_TIME
+# Pass a long as parameter. It contains the time in seconds that the transfer
+# should be below the LOW_CONNECTION_SPEED_LIMIT to consider it too slow and abort.
+# Minimum value: 1
+# Maximum value: 600
+# Default:
+# low_connection_speed_time=10
+low_connection_speed_time=10
+
+# MAX_CONNECTION_SPEED
+# If a download exceeds this speed (counted in bytes per second) on cumulative
+# average during the transfer, the transfer will pause to keep the average rate
+# less than or equal to the parameter value. Defaults to unlimited speed.
+# Minimum value: 1
+# Maximum value: -1 (-1 for no limit)
+# Default:
+# max_connection_speed=0
+max_connection_speed=3000
+
+[network_protocols]
+# SYNOPSIS: http_on=0 | 1
+# Default:
+# http_on=1
+# NOT IMPLEMENTED YET: http_on=1
+
+# SYNOPSIS: ftp_on=0 | 1
+# Default:
+# ftp_on=1
+# NOT IMPLEMENTED YET: ftp_on=1
+
+[network_user_data]
+# USER_AGENT
+# Set the User-Agent: header in the http request sent to the remote server.
+# This can be used to fool servers or scripts.
+# Default:
+# user_agent=segget
+user_agent=segget
+
+# Specify the user and password for authentication on a ftp servers.
+# NOT IMPLEMENTED YET: ftp-user=anonymous
+# NOT IMPLEMENTED YET: ftp-password=me@mail.ru
+
+[network_proxy]
+# PROXY_IP_OR_NAME
+# Specify a proxy to use (address and port).
+# Set HTTP proxy to use. The parameter should be a string holding the proxy host
+# name or dotted IP address. To specify port number in this string,
+# append :[port] to the end of the host name. The proxy string may be prefixed
+# with [protocol]:// since any such prefix will be ignored. The proxy's port
+# number may optionally be specified with the separate option. If not specified,
+# by default port 1080 will be used for proxies.
+# When you tell segget to use an HTTP proxy, segget will transparently convert
+# operations to HTTP even if you specify an FTP URL etc.
+# Segget respects the environment variables http_proxy, ftp_proxy, all_proxy etc,
+# if any of those are set. The PROXY option does however override any possibly
+# set environment variables.
+# Default:
+# proxy_ip_or_name=none
+proxy_ip_or_name=none
+
+# PROXY_PORT
+# Set the proxy port to connect to unless it is specified in the PROXY option.
+# Minimum value: 1
+# Maximum value: 65535
+# Default:
+# proxy_port=3128
+proxy_port=3128
+
+# PROXY_USER
+# Set user name to use for the transfer while connecting to Proxy.
+# The PROXY_USER option should be used in same way as the PROXY_PASSWORD is used.
+# In order to specify the password to be used in conjunction with the user name
+# use the PROXY_PASSWORD option.
+# Default:
+# proxy_user=none
+proxy_user=none
+
+# PROXY_PASSWORD
+# Set password to use for the transfer while connecting to Proxy.
+# The PROXY_PASSWORD option should be used in conjunction with the PROXY_USER
+# option.
+# Default:
+# proxy_password=none
+proxy_password=none
+
+# SYNOPSIS: proxy_off=0 | 1
+# Setting the proxy_off=1 will explicitly disable the use of a proxy, even if
+# there is an environment variable set for it.
+# Default:
+# proxy_off=1
+proxy_off=1
+
+[network_mirrors]
+# SYNOPSIS: NETWORK_USES_OWN_MIRROR_LIST_ON=0 | 1
+# - If set to 1, segget will replace mirror list provided by portage system with
+# the list from network1_mirros.list
+# Default:
+# use_own_mirror_list_on=0
+use_own_mirror_list_on=0 \ No newline at end of file
diff --git a/segget/networkbroker.cpp b/segget/networkbroker.cpp
new file mode 100644
index 0000000..920fc56
--- /dev/null
+++ b/segget/networkbroker.cpp
@@ -0,0 +1,32 @@
+/*
+* 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
+*/
+
+#include "networkbroker.h"
+
+bool Tnetworkbroker::get_allowed_status(){
+ debug(" get_allowed_status_for_network_num="+toString(network_num));
+ return network_array[network_num].get_busy_status();
+} \ No newline at end of file
diff --git a/segget/networkbroker.h b/segget/networkbroker.h
new file mode 100644
index 0000000..ba78e08
--- /dev/null
+++ b/segget/networkbroker.h
@@ -0,0 +1,40 @@
+/*
+* 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 __NETWORKBROKER_H__
+#define __NETWORKBROKER_H__
+
+class Tnetworkbroker{
+ public:
+ ulong network_num;
+ bool local_mirrors;
+ bool get_allowed_status();
+ Tnetworkbroker():
+ network_num(0),
+ local_mirrors(0)
+ {};
+};
+
+#endif
diff --git a/segget/pkg.cpp b/segget/pkg.cpp
index 4a6ad37..40ddef3 100644
--- a/segget/pkg.cpp
+++ b/segget/pkg.cpp
@@ -31,7 +31,7 @@
#include <fstream>
#include <iostream>
#include <json/json.h>
-#include "distfile.cpp"
+#include "distfile.h"
using namespace std;
typedef unsigned int uint;
diff --git a/segget/segget.conf b/segget/segget.conf
index 214883c..326ca91 100644
--- a/segget/segget.conf
+++ b/segget/segget.conf
@@ -33,13 +33,17 @@ del_pkg_list_when_dld_finished=1
# MAX_CONNECTION_NUM_PER_DISTFILE
# Each distfile can have up to max_connection_num_per_distfile simultaneous
# connections.
-# default:
+# Minimum value: 1
+# Maximum value: 20
+# Default:
# max_connection_num_per_distfile=3
max_connection_num_per_distfile=3
[segments]
# MAX_SEGMENT_SIZE
# Define maximum segment size in bytes.
+# Minimum value: 10000
+# Maximum value: 10000000
# Default:
# max_segment_size=500000
max_segment_size=500000
@@ -59,6 +63,8 @@ resume_on=1
# MAX_TRIES
# If segment download was unsuccessful, new attempts are made. When attempts
# number reaches max_tries, segment gets FAILED status and error logged to error_log
+# Minimum value: 1
+# Maximum value: -1 (for no limit)
# Default:
# max_tries=10
max_tries=10
@@ -66,102 +72,31 @@ max_tries=10
[connections]
# MAX_CONNECTIONS
# Define maximum number of connections
-max_connections=10
-
-# CONNECTION_TIMEOUT
-# Set the number of seconds to wait while trying to connect. Use 0 to wait
-# indefinitely. Pass a long. It should contain the maximum time in seconds that
-# you allow the connection to the server to take. This only limits the connection
-# phase, once it has connected, this option is of no more use. Set to zero to
-# disable connection timeout (it will then only timeout on the system's internal
-# timeouts). See also the TIMEOUT option.
-# Default:
-# connection_timeout=15
-connection_timeout=15
-
-# FTP_RESPONSE_TIMEOUT
-# Set a timeout period (in seconds) on the amount of time that the server is
-# allowed to take in order to generate a response message for a command before the
-# session is considered hung. While awaiting for a response, this value overrides
-# TIMEOUT. It is recommended that if used in conjunction with TIMEOUT, you set
-# FTP_RESPONSE_TIMEOUT to a value smaller than TIMEOUT.
-# Default:
-# ftp_response_timeout=180
-ftp_response_timeout=180
-
-# TIMEOUT
-# maximum amount of time to download segment in seconds
-# Set the maximum number of seconds for a connection to execute.
-# Pass a long as parameter containing the maximum time in seconds that you allow
-# the transfer operation to take. Normally, name lookups can take a considerable
-# time and limiting operations to less than a few minutes risk aborting perfectly
-# normal operations.
+# Minimum value: 1
+# Maximum value: 20
# Default:
-# timeout=500
-timeout=500
-
-# LOW_CONNECTION_SPEED_LIMIT
-# Define the low speed limit for connection. Pass a long as parameter. It
-# contains the transfer speed in bytes per second that the transfer should be
-# below during LOW_CONNECTION_SPEED_TIME seconds to consider it too slow and abort.
-# Default:
-# low_connection_speed_limit=1000
-low_connection_speed_limit=1000
-
-# LOW_CONNECTION_SPEED_TIME
-# Pass a long as parameter. It contains the time in seconds that the transfer
-# should be below the LOW_CONNECTION_SPEED_LIMIT to consider it too slow and abort.
-# Default:
-# low_connection_speed_time=10
-low_connection_speed_time=10
-
-# MAX_CONNECTION_SPEED
-# If a download exceeds this speed (counted in bytes per second) on cumulative
-# average during the transfer, the transfer will pause to keep the average rate
-# less than or equal to the parameter value. Defaults to unlimited speed.
-# Default:
-# max_connection_speed=0
-max_connection_speed=3000
+# max_connections=10
+max_connections=7
# CURRENT_SPEED_TIME_INTERVAL_MSECS
# segget transfers may have bursty nature of their traffic. Therefore, while
# measuring current speed, segget actually calculates average speed during
# current_speed_time_interval_msecs time interval, defined in milliseconds.
-# Min limit:100
-# Max limit: 60000
+# Minimum value: 100
+# Maximum value: 60000
# Default:
# current_speed_time_interval_msecs=1000
current_speed_time_interval_msecs=1000
# NOT IMPLEMENTED YET: max_total_speed=50000
-# BIND INTERFACE / IP
-# Pass a string as parameter. This sets the interface name to use as outgoing
-# network interface. The name can be an interface name, an IP address, or a host
-# name. No binding is set by default.
-# Default:
-# bind_interface=none
-bind_interface=none
-
-# BIND LOCALPORT
-# Pass a long. This sets the local port number of the socket used for connection.
-# This can be used in combination with BIND_INTERFACE and you are recommended to
-# use BIND_LOCALPORTRANGE as well when this is set.
-# Valid port numbers are 1 - 65535.
-
-# BIND_LOCALPORTRANGE
-# Pass a long. This is the number of attempts segget should make to find a
-# working local port number. It starts with the given BIND_LOCALPORT and adds
-# one to the number for each retry. Setting this to 1 or below will make segget
-# do only one try for the exact port number. Port numbers by nature are scarce
-# resources that will be busy at times so setting this value to something too
-# low might cause unnecessary connection setup failures.
-
[mirrors]
# MAX_CONNECTIONS_NUM_PER_MIRROR
# Define how many simultaneous downloads from one mirror segget is allowed to
# have. While choosing a mirror segget will skip mirrors with
# max_connections_num_per_mirror active downloads.
+# Minimum value: 1
+# Maximum value: 10
# Default:
# max_connections_num_per_mirror=1
max_connections_num_per_mirror=2
@@ -215,85 +150,111 @@ use_benchmark_stats=1
#
# Therefore, setting benchmark_oblivion=100 will make mirror look twice
# less bad next time mirror->mirror_on_the_wall() called.
+# Minimum value: 0 (Beware: setting to 0, will can exclude unlucky mirrors)
+# Maximum value: 1000
# Default:
# benchmark_oblivion=5
benchmark_oblivion=5
-[protocols]
-# SYNOPSIS: http_on=0 | 1
-# Default:
-# http_on=1
-# NOT IMPLEMENTED YET: http_on=1
+[provide_mirror_to_others]
+# MIRROR_DIR
+# Define a dir to store distfiles for mirroring.
+# Default:
+# mirror_dir=./mirror
+# NOT IMPLEMENTED YET: mirror_dir=./mirror
-# SYNOPSIS: ftp_on=0 | 1
-# Default:
-# ftp_on=1
-# NOT IMPLEMENTED YET: ftp_on=1
+[networks]
+# NETWORK0_PRIORITY
+# Define priority as a value in range from lowest 0 to highest 10.
+# Segget tries to use networks with higher priority levels first, and in case of
+# failure will switch to networks with lower priority levels.
+# Segget will NOT use network if its priority level set to 0. Therefore at least
+# one network must have priority level higher than 0.
+# Networks with local mirrors usually would have higher priority than that of
+# networks with remote mirrors.
+# Segget can have up to 10 networks (from network0 to network9).
+# Settings for each network should be defined in network#.conf file, where
+# instead of # should be network number. For network0 it's network0.conf
+# Default:
+# network0_priority=10
+network0_priority=10
-[local-mirrors]
+# NETWORK1_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network1.conf
+# Default:
+# network1_priority=0
+network1_priority=0
-[schedule]
+# NETWORK2_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network2.conf
+# Default:
+# network2_priority=0
+network2_priority=0
+# NETWORK3_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network3.conf
+# Default:
+# network3_priority=0
+network3_priority=0
-[user-data]
-# USER_AGENT
-# Set the User-Agent: header in the http request sent to the remote server.
-# This can be used to fool servers or scripts.
+# NETWORK4_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network4.conf
# Default:
-# user_agent=segget
-user_agent=segget
+# network4_priority=0
+network4_priority=0
-# Specify the user and password for authentication on a ftp servers.
-# NOT IMPLEMENTED YET: ftp-user=anonymous
-# NOT IMPLEMENTED YET: ftp-password=me@mail.ru
+# NETWORK5_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network5.conf
+# Default:
+# network5_priority=0
+network5_priority=0
-[proxy]
-# PROXY_IP_OR_NAME
-# Specify a proxy to use (address and port).
-# Set HTTP proxy to use. The parameter should be a string holding the proxy host
-# name or dotted IP address. To specify port number in this string,
-# append :[port] to the end of the host name. The proxy string may be prefixed
-# with [protocol]:// since any such prefix will be ignored. The proxy's port
-# number may optionally be specified with the separate option. If not specified,
-# by default port 1080 will be used for proxies.
-# When you tell segget to use an HTTP proxy, segget will transparently convert
-# operations to HTTP even if you specify an FTP URL etc.
-# Segget respects the environment variables http_proxy, ftp_proxy, all_proxy etc,
-# if any of those are set. The PROXY option does however override any possibly
-# set environment variables.
+# NETWORK6_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network6.conf
# Default:
-# proxy_ip_or_name=none
-proxy_ip_or_name=none
+# network6_priority=0
+network6_priority=0
-# PROXY_PORT
-# Set the proxy port to connect to unless it is specified in the PROXY option.
+# NETWORK7_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network7.conf
# Default:
-# proxy_port=3128
-proxy_port=3128
-
-# PROXY_USER
-# Set user name to use for the transfer while connecting to Proxy.
-# The PROXY_USER option should be used in same way as the PROXY_PASSWORD is used.
-# In order to specify the password to be used in conjunction with the user name
-# use the PROXY_PASSWORD option.
+# network7_priority=0
+network7_priority=0
+
+# NETWORK8_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network8.conf
# Default:
-# proxy_user=none
-proxy_user=none
+# network8_priority=0
+network8_priority=0
-# PROXY_PASSWORD
-# Set password to use for the transfer while connecting to Proxy.
-# The PROXY_PASSWORD option should be used in conjunction with the PROXY_USER
-# option.
+# NETWORK9_PRIORITY
+# Description: same as for NETWORK0_PRIORITY
+# Define network specific settings in network9.conf
# Default:
-# proxy_password=none
-proxy_password=none
+# network9_priority=0
+network9_priority=0
-# SYNOPSIS: proxy_off=0 | 1
-# Setting the proxy_off=1 will explicitly disable the use of a proxy, even if
-# there is an environment variable set for it.
+[schedule]
+
+[user-data]
+# USER_AGENT
+# Set the User-Agent: header in the http request sent to the remote server.
+# This can be used to fool servers or scripts.
# Default:
-# proxy_off=1
-proxy_off=1
+# user_agent=segget
+user_agent=segget
+
+# Specify the user and password for authentication on a ftp servers.
+# NOT IMPLEMENTED YET: ftp-user=anonymous
+# NOT IMPLEMENTED YET: ftp-password=me@mail.ru
[proxy-fetcher]
# Specify proxy-fetcher address and port
@@ -311,13 +272,6 @@ proxy_off=1
# Set to forbid using proxy-fetcher.
# NOT IMPLEMENTED YET: no-proxy-fetcher
-[mirroring]
-# MIRROR_DIR
-# Define a dir to store distfiles for mirroring.
-# Default:
-# mirror_dir=./mirror
-# NOT IMPLEMENTED YET: mirror_dir=./mirror
-
[logs]
# LOGS_DIR
# Define a dir to store log files.
diff --git a/segget/segget.cpp b/segget/segget.cpp
index 4f26766..e2e42a3 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -31,8 +31,11 @@
#include <json/json.h>
#include <ncurses.h>
#include "pkg.cpp"
+#include "distfile.cpp"
#include "connection.cpp"
#include "utils.cpp"
+#include "network.cpp"
+#include "networkbroker.cpp"
//#include "settings.cpp"
using namespace std;
@@ -132,7 +135,7 @@ int choose_segment(uint connection_num){
segment_num++; // segment already downloaded/downloading => go for the next one
}
else
- debug(" distfile #"+toString(distfile_num)+" has "
+ debug(" distfile "+Ppkg_array[pkg_num]->Pdistfile_list[distfile_num]->name+" has "
+toString(Ppkg_array[pkg_num]->Pdistfile_list[distfile_num]->active_connections_num)
+" connections => choosing another distfile.");
segment_num=0;
@@ -173,7 +176,7 @@ int download_pkgs(){
return EXIT_FAILURE;
}
- for (uint connection_num = 0; connection_num < MAX_CONNECTS; ++connection_num) {
+ for (uint connection_num = 0; connection_num < settings.max_connections; ++connection_num) {
if (choose_segment(connection_num))
break;
};
@@ -285,7 +288,7 @@ int main()
}
try{
//load settings
- settings.load_from_conf_file();
+ settings.init();
}
catch(...)
{
diff --git a/segget/segment.cpp b/segget/segment.cpp
index cf33c3f..93c5098 100644
--- a/segget/segment.cpp
+++ b/segget/segment.cpp
@@ -56,17 +56,17 @@ void Tsegment::set_segment(void *prnt_distfile, uint seg_num, string distfile_na
error_log("Error in segment.cpp: prepare_for_connection()");
}
}
-void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint distfile_num, string segment_url){
+void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string segment_url){
try{
msg_connecting(con_num,distfile_num, segment_num,"Downloading from "+segment_url);
segments_in_progress[con_num]=this;
status=DOWNLOADING;
downloaded_bytes=0;
connection_num=con_num;
- connection_array[con_num].start();
+ connection_array[con_num].start(network_num);
url=segment_url;
try_num++;
- add_easy_handle_to_multi(cm);
+ add_easy_handle_to_multi(cm, network_num);
}catch(...){
error_log("Error in segment.cpp: prepare_for_connection()");
}
@@ -77,7 +77,7 @@ Tsegment::~Tsegment(){
segment_file.close();
}
-int Tsegment::add_easy_handle_to_multi(CURLM *cm){
+int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){
segment_file.exceptions (ofstream::badbit);
try{
segment_file.open((settings.segments_dir+"/"+file_name).c_str(), ios::trunc|ios::binary );
@@ -97,34 +97,38 @@ int Tsegment::add_easy_handle_to_multi(CURLM *cm){
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, this);
curl_easy_setopt(easyhandle, CURLOPT_PRIVATE, this);
curl_easy_setopt(easyhandle, CURLOPT_RANGE, range.c_str());
- curl_easy_setopt(easyhandle, CURLOPT_TIMEOUT, settings.time_out);
- curl_easy_setopt(easyhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, settings.ftp_response_timeout);
- curl_easy_setopt(easyhandle, CURLOPT_LOW_SPEED_LIMIT, settings.low_connection_speed_limit);
- curl_easy_setopt(easyhandle, CURLOPT_LOW_SPEED_TIME, settings.low_connection_speed_time);
- curl_easy_setopt(easyhandle, CURLOPT_MAX_RECV_SPEED_LARGE, settings.max_connection_speed);
- curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, settings.user_agent.c_str());
+ curl_easy_setopt(easyhandle, CURLOPT_TIMEOUT, network_array[network_num].time_out);
+ curl_easy_setopt(easyhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, network_array[network_num].ftp_response_timeout);
+ if ((network_array[network_num].low_connection_speed_limit!=0) and (network_array[network_num].low_connection_speed_limit!=(ulong)-1)){
+ curl_easy_setopt(easyhandle, CURLOPT_LOW_SPEED_LIMIT, network_array[network_num].low_connection_speed_limit);
+ }
+ curl_easy_setopt(easyhandle, CURLOPT_LOW_SPEED_TIME, network_array[network_num].low_connection_speed_time);
+
+ if ((network_array[network_num].max_connection_speed!=0) and (network_array[network_num].max_connection_speed!=(ulong)-1)){
+ curl_easy_setopt(easyhandle, CURLOPT_MAX_RECV_SPEED_LARGE, network_array[network_num].max_connection_speed);
+ }
+ curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, network_array[network_num].user_agent.c_str());
- if (settings.proxy_off)
+ if (network_array[network_num].proxy_off)
curl_easy_setopt(easyhandle, CURLOPT_NOPROXY, "*");
else{
- if ((settings.proxy_ip_or_name!="none") and (settings.proxy_port!=0)){
- curl_easy_setopt(easyhandle, CURLOPT_PROXY, settings.proxy_ip_or_name.c_str());
- curl_easy_setopt(easyhandle, CURLOPT_PROXYPORT, settings.proxy_port);
- debug("Using proxy:"+settings.proxy_ip_or_name+":"+toString(settings.proxy_port));
+ if ((network_array[network_num].proxy_ip_or_name!="none") and (network_array[network_num].proxy_port!=0)){
+ curl_easy_setopt(easyhandle, CURLOPT_PROXY, network_array[network_num].proxy_ip_or_name.c_str());
+ curl_easy_setopt(easyhandle, CURLOPT_PROXYPORT, network_array[network_num].proxy_port);
+ debug("Using proxy:"+network_array[network_num].proxy_ip_or_name+":"+toString(network_array[network_num].proxy_port));
}
- if (settings.proxy_user!="none"){
- curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERNAME, settings.proxy_user.c_str());
- if (settings.proxy_password!="none")
- curl_easy_setopt(easyhandle, CURLOPT_PROXYPASSWORD, settings.proxy_password.c_str());
+ if (network_array[network_num].proxy_user!="none"){
+ curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERNAME, network_array[network_num].proxy_user.c_str());
+ if (network_array[network_num].proxy_password!="none")
+ curl_easy_setopt(easyhandle, CURLOPT_PROXYPASSWORD, network_array[network_num].proxy_password.c_str());
}
}
- if ((settings.bind_interface!="none")
- and (settings.bind_interface!="")
- and (settings.bind_interface!="NONE"))
- curl_easy_setopt(easyhandle, CURLOPT_INTERFACE, settings.bind_interface.c_str());
+ if ((network_array[network_num].bind_interface!="none")
+ and (network_array[network_num].bind_interface!=""))
+ curl_easy_setopt(easyhandle, CURLOPT_INTERFACE, network_array[network_num].bind_interface.c_str());
//set connection timeout
- curl_easy_setopt(easyhandle, CURLOPT_CONNECTTIMEOUT, settings.connection_timeout);
+ curl_easy_setopt(easyhandle, CURLOPT_CONNECTTIMEOUT, network_array[network_num].connection_timeout);
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);
curl_multi_add_handle(cm, easyhandle);
return 0;
diff --git a/segget/segment.h b/segget/segment.h
index 34ca383..3151999 100644
--- a/segget/segment.h
+++ b/segget/segment.h
@@ -81,9 +81,9 @@ class Tsegment{
Tsegment & operator=(const Tsegment &L);
~Tsegment();
void set_segment(void *prnt_distfile, uint seg_num, string distfile_name, ulong default_seg_size, ulong range_end);
- void prepare_for_connection(CURLM *cm, uint con_num, uint distfile_num, string segment_url);
+ void prepare_for_connection(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string segment_url);
string get_file_name(){return file_name;};
- int add_easy_handle_to_multi(CURLM *cm);
+ int add_easy_handle_to_multi(CURLM *cm, uint network_num);
};
Tsegment *segments_in_progress[MAX_CONNECTS]={0};
diff --git a/segget/settings.cpp b/segget/settings.cpp
index dbbad53..f6e6c91 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -26,13 +26,14 @@
#include "settings.h"
-void Tsettings::load_from_conf_file(){
+void Tsettings::init(){
try{
ConfigFile 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");
conf.set(debug_log_file, "logs", "debug_log_file");
+ conf.set(max_connections, "connections", "max_connections",1,MAX_CONNECTS);
conf.set(distfiles_dir, "folders", "distfiles_dir");
conf.set(segments_dir, "folders", "segments_dir");
@@ -40,32 +41,31 @@ void Tsettings::load_from_conf_file(){
conf.set(pkg_list_dir, "pkg_list", "pkg_list_dir");
conf.set(del_pkg_list_when_dld_finished, "pkg_list", "del_pkg_list_when_dld_finished");
- conf.set(max_connection_num_per_distfile, "distfiles", "max_connection_num_per_distfile",1,20);
+ conf.set(max_connection_num_per_distfile, "distfiles", "max_connection_num_per_distfile",1,MAX_CONNECTS);
conf.set(resume_on, "segments", "resume_on");
conf.set(max_segment_size, "segments", "max_segment_size",10000,10000000);
conf.set(max_tries, "segments", "max_tries",1,-1);
- conf.set(max_connections, "connections", "max_connections",1,20);
- conf.set(connection_timeout, "connections", "connection_timeout",1,1000);
- conf.set(ftp_response_timeout, "connections", "ftp_response_timeout",1,-1);
- conf.set(time_out, "connections", "timeout",100,-1);
- conf.set(low_connection_speed_limit, "connections", "low_connection_speed_limit",0,-1);
- conf.set(low_connection_speed_time, "connections", "low_connection_speed_time",1,600);
- conf.set(max_connection_speed, "connections", "max_connection_speed",0,-1);
conf.set(current_speed_time_interval_msecs, "connections", "current_speed_time_interval_msecs",100,60000);
- conf.set(bind_interface, "connections", "bind_interface");
conf.set(max_connections_num_per_mirror, "mirrors", "max_connections_num_per_mirror",1,10);
- conf.set(benchmark_oblivion, "mirrors", "benchmark_oblivion",1,1000);
+ conf.set(benchmark_oblivion, "mirrors", "benchmark_oblivion",0,1000);
- conf.set(user_agent, "user-data", "user_agent");
+ ulong cur_network_priority;
+ for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
+ //set default values, in case segget.conf doesn't have these settings
+ if (network_num==0){
+ cur_network_priority=10;
+ }else{
+ cur_network_priority=0;
+ }
- conf.set(proxy_ip_or_name, "proxy", "proxy_ip_or_name");
- conf.set(proxy_port, "proxy", "proxy_port",1,65535);
- conf.set(proxy_off, "proxy", "proxy_off");
- conf.set(proxy_user, "proxy", "proxy_user");
- conf.set(proxy_password, "proxy", "proxy_password");
+ conf.set(cur_network_priority, "networks", "network"+toString(network_num)+"_priority",0,10);
+ if (cur_network_priority>0){
+ network_array[network_num].init(cur_network_priority);
+ }
+ }
}
catch(...)
{
diff --git a/segget/settings.h b/segget/settings.h
index ac2671d..c633a2c 100644
--- a/segget/settings.h
+++ b/segget/settings.h
@@ -29,7 +29,9 @@
#include <string>
#include "config.cpp"
+#include "network.h"
//#include "tui.cpp"
+#define MAX_CONNECTS 20 /* number of simultaneous transfers */
using namespace std;
@@ -117,7 +119,7 @@ class Tsettings{
{};
void set_resume(bool resume_setting){resume_on=resume_setting;};
bool get_resume(){return resume_on;};
- void load_from_conf_file();
+ void init();
};
Tsettings settings;
diff --git a/segget/stats.cpp b/segget/stats.cpp
index 00f83b6..5df2b7a 100644
--- a/segget/stats.cpp
+++ b/segget/stats.cpp
@@ -66,7 +66,7 @@ class Tstats{
void Tstats::inc_dld_distfiles_count(){
dld_distfiles_count++;
- if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>=distfiles_count)){
+ if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>distfiles_count)){
//delete pkg.list file;
if(remove((settings.pkg_list_dir+"/pkg.list").c_str()) != 0 )
error_log("Error in stats.cpp: inc_dld_distfiles_count(): Can't delete:"+settings.pkg_list_dir+"/pkg.list");
diff --git a/segget/str.cpp b/segget/str.cpp
index a482c3f..63cc680 100644
--- a/segget/str.cpp
+++ b/segget/str.cpp
@@ -24,12 +24,26 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __STR_H__
-#define __STR_H__
-#include <string>
-#include <algorithm>
+#include "str.h"
using namespace std;
+template<typename T> string toString(T t)
+{
+ stringstream s;
+ s << t;
+ return s.str();
+}
+
+template<typename T> string field(string prefix,T t, int width)
+{
+ stringstream s1,s2;
+ s1 << t;
+ width=width+prefix.length();
+ s2.width(width);
+ s2 << prefix+s1.str();
+ return s2.str();
+}
+
int lower_char(int c)
{
return tolower((unsigned char)c);
@@ -38,5 +52,4 @@ int lower_char(int c)
string noupper(string s){
transform(s.begin(), s.end(), s.begin(), lower_char);
return s;
-}
-#endif \ No newline at end of file
+} \ No newline at end of file
diff --git a/segget/str.h b/segget/str.h
new file mode 100644
index 0000000..c2b653c
--- /dev/null
+++ b/segget/str.h
@@ -0,0 +1,38 @@
+ /*
+* 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 __STR_H__
+#define __STR_H__
+#include <string>
+#include <algorithm>
+using namespace std;
+
+template<typename T> string toString(T t);
+template<typename T> string field(string prefix,T t, int width);
+
+int lower_char(int c);
+string noupper(string s);
+#endif \ No newline at end of file
diff --git a/segget/tui.cpp b/segget/tui.cpp
index 1ddf42a..355fc98 100644
--- a/segget/tui.cpp
+++ b/segget/tui.cpp
@@ -29,23 +29,6 @@ extern Tsettings settings;
const uint CONNECTION_LINES=5;
-template<typename T> string toString(T t)
-{
- stringstream s;
- s << t;
- return s.str();
-}
-
-template<typename T> string field(string prefix,T t, int width)
-{
- stringstream s1,s2;
- s1 << t;
- width=width+prefix.length();
- s2.width(width);
- s2 << prefix+s1.str();
- return s2.str();
-}
-
void msg(uint y, uint x, string msg_text){
move(y,x);
string ready_msg_text=msg_text+" ";
@@ -63,7 +46,7 @@ void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, st
}
}
-void msg_segment_progress(uint connection_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed, ulong avg_speed){
+void msg_segment_progress(uint connection_num, uint network_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed, ulong avg_speed){
try{
string speed_str;
string avg_speed_str;
@@ -78,6 +61,7 @@ void msg_segment_progress(uint connection_num, uint segment_num, uint try_num, u
int percent=dld_bytes*100/total_bytes;
msg(connection_num*CONNECTION_LINES,0,
field("[",connection_num,2)+"]"
+ +field(" Net",network_num,1)
+field(" Segment:",segment_num, 5)
+field(" Try:",try_num,4)
+field(" Bytes:",dld_bytes,7)
@@ -110,6 +94,12 @@ void msg_status2(uint connection_num, string msg_text){
error_log_no_msg("Error in tui.cpp: msg_status2()");
}
}
+void msg_clean_connection(uint connection_num){
+ msg(connection_num*CONNECTION_LINES,0," ");
+ msg(connection_num*CONNECTION_LINES+1,0," ");
+ msg(connection_num*CONNECTION_LINES+2,0," ");
+ msg(connection_num*CONNECTION_LINES+3,0," ");
+}
void msg_error(string error_text){
try{
msg(20,0, error_text);
@@ -121,7 +111,7 @@ void msg_error(string error_text){
}
void msg_total(string msg_text){
try{
- msg(30,0,msg_text);
+ msg(settings.max_connections*CONNECTION_LINES,0,msg_text);
}
catch(...)
{
@@ -129,7 +119,7 @@ void msg_total(string msg_text){
}
}
void log(string log_msg_text){
- msg(31,0, "LOG:"+log_msg_text);
+ msg(settings.max_connections*CONNECTION_LINES+1,0, "LOG:"+log_msg_text);
ofstream file;
file.exceptions (ofstream::failbit | ofstream::badbit);
try{
@@ -148,7 +138,7 @@ void log(string log_msg_text){
}
}
void debug(string debug_msg_text){
- msg(32,0, "DEBUG:"+debug_msg_text);
+ msg(settings.max_connections*CONNECTION_LINES+2,0, "DEBUG:"+debug_msg_text);
ofstream file;
file.exceptions (ofstream::failbit | ofstream::badbit);
try{
@@ -179,7 +169,7 @@ void error_log(string error_msg_text){
file << error_msg_text << endl;
file.close();
try{
- msg(33,0, "ERROR:"+error_msg_text);
+ msg(settings.max_connections*CONNECTION_LINES+3,0, "ERROR:"+error_msg_text);
}
catch(...)
{
diff --git a/segget/tui.h b/segget/tui.h
index 8b801b2..f20b413 100644
--- a/segget/tui.h
+++ b/segget/tui.h
@@ -29,16 +29,14 @@
#include "settings.h"
using namespace std;
-template<typename T> string toString(T t);
-template<typename T> string field(string prefix,T t, int width);
-
void msg_total(string msg_text);
void msg(uint y, uint x, string msg_text);
void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text);
-void msg_segment_progress(uint connection_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed);
+void msg_segment_progress(uint connection_num, uint network_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed);
void msg_status1(uint connection_num, uint segment_num, string msg_text);
void msg_status2(uint connection_num, string msg_text);
+void msg_clean_connection(uint connection_num);
void msg_error(string error_text);
void msg_total(string msg_text);
diff --git a/segget/utils.cpp b/segget/utils.cpp
index cdc2dc8..fdbbf5a 100644
--- a/segget/utils.cpp
+++ b/segget/utils.cpp
@@ -24,8 +24,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "utils.h"
-#include "sys/time.h"
ulong time_left_from(timeval from_time){
try{
timeval now_time;
diff --git a/segget/utils.h b/segget/utils.h
index 60fd70c..b286a79 100644
--- a/segget/utils.h
+++ b/segget/utils.h
@@ -27,6 +27,9 @@
#ifndef __UTILS_H__
#define __UTILS_H__
+#include "utils.h"
+#include "sys/time.h"
+
ulong time_left_from(timeval from_time);
#endif \ No newline at end of file