summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-17 10:31:20 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-17 10:31:20 +0300
commit3dede84d71f02468a7b2c70bc5cde82864058e27 (patch)
tree0da3a83c69c1fdfb5d077fd814f5a2ae6c275da9
parentFix: warnings with unused variables (diff)
downloadidfetch-3dede84d71f02468a7b2c70bc5cde82864058e27.tar.gz
idfetch-3dede84d71f02468a7b2c70bc5cde82864058e27.tar.bz2
idfetch-3dede84d71f02468a7b2c70bc5cde82864058e27.zip
Add section [network_proxy_fetcher]
PROXY_FETCHER_IP This option is active only when NETWORK_MODE=1, in other cases it's ignored. Specify IP addres of the proxy-fetcher Default: proxy_fetcher_ip=none PROXY_FETCHER_PORT This option is active only when NETWORK_MODE=1, in other cases it's ignored. Specify proxy-fetcher address Default: proxy_fetcher_port=3131
-rw-r--r--segget/config.cpp6
-rw-r--r--segget/config.h6
-rw-r--r--segget/distfile.cpp8
-rw-r--r--segget/distfile.h2
-rw-r--r--segget/network.cpp58
-rw-r--r--segget/network.h10
-rw-r--r--segget/network0.conf26
-rw-r--r--segget/network1.conf26
-rw-r--r--segget/network2.conf26
-rw-r--r--segget/segget.conf11
-rw-r--r--segget/segget.cpp14
-rw-r--r--segget/settings.cpp47
12 files changed, 163 insertions, 77 deletions
diff --git a/segget/config.cpp b/segget/config.cpp
index 7029691..6c926df 100644
--- a/segget/config.cpp
+++ b/segget/config.cpp
@@ -72,7 +72,7 @@ void Tconfig::load_settings_from_config_file(){
}
}
-int Tconfig::set(string &dst, string const& section, string const& entry) const {
+int Tconfig::set(string const& section, string const& entry, string &dst) const {
try{
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
if (ci == content_.end()){
@@ -90,7 +90,7 @@ int Tconfig::set(string &dst, string const& section, string const& entry) const
return 1;
}
}
-int Tconfig::set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const {
+int Tconfig::set(string const& section, string const& entry, ulong &dst, uint const& min_limit, uint const& max_limit) const {
try{
uint return_value;
map<string,string>::const_iterator ci = content_.find(section + '/' + entry);
@@ -130,7 +130,7 @@ int Tconfig::set(ulong &dst, string const& section, string const& entry, uint co
}
}
-int Tconfig::set(bool &dst, string const& section, string const& entry) const {
+int Tconfig::set(string const& section, string const& entry, bool &dst) const {
try{
uint return_value;
map<std::string,string>::const_iterator ci = content_.find(section + '/' + entry);
diff --git a/segget/config.h b/segget/config.h
index db77347..60ae673 100644
--- a/segget/config.h
+++ b/segget/config.h
@@ -44,9 +44,9 @@ class Tconfig {
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;
+ int set(string const& section, string const& entry, string &dst) const;
+ int set(string const& section, string const& entry, ulong &dst, uint const& min_limit, uint const& max_limit) const;
+ int set(string const& section, string const& entry, bool &dst) const;
void clear();
};
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 506f8d8..43d3641 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -29,7 +29,7 @@
//Make the necessary includes and set up the variables:
using namespace std;
-Tdistfile_status Tdistfile::request(string msg)
+Tdistfile_status Tdistfile::request(ulong network_num, string msg)
{
int sockfd;
int len;
@@ -40,8 +40,8 @@ Tdistfile_status Tdistfile::request(string msg)
//Name the socket, as agreed with the server:
address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr("127.0.0.1");
- address.sin_port = htons(9888);
+ address.sin_addr.s_addr = inet_addr(network_array[network_num].proxy_fetcher_ip.c_str());
+ address.sin_port = htons(network_array[network_num].proxy_fetcher_port);
len = sizeof(address);
//Connect your socket to the server’s socket:
@@ -399,7 +399,7 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
// return 1;
}
// request from proxy fethcer
- status=request(json_data);
+ status=request(best_proxy_fetcher_network_num, json_data);
debug("Trying to dowload distfile"+name+" via proxy_fetcher. status="+toString(status));
if (status==DPROXY_DOWNLOADED){
// start download from the proxy_fetcher
diff --git a/segget/distfile.h b/segget/distfile.h
index 4ec2fc3..d97de3e 100644
--- a/segget/distfile.h
+++ b/segget/distfile.h
@@ -138,7 +138,7 @@ class Tdistfile{
Tdistfile(const Tdistfile &L); // copy constructor
Tdistfile & operator=(const Tdistfile &L);
~Tdistfile();
- Tdistfile_status request(string msg);
+ Tdistfile_status request(ulong network_num, string msg);
void init();
bool allows_new_actions();
void load_distfile_from_json(json_object* json_obj_distfile);
diff --git a/segget/network.cpp b/segget/network.cpp
index 2705947..b3a6f9a 100644
--- a/segget/network.cpp
+++ b/segget/network.cpp
@@ -25,7 +25,6 @@
*/
#include "network.h"
-uint Tnetwork::network_count=0;
Tnetwork network_array[MAX_NETWORKS];
void Tnetwork::load_mirror_list(){
@@ -67,30 +66,49 @@ void Tnetwork::init(uint priority_value){
try{
priority=priority_value;
Tconfig conf("network"+toString(network_num)+".conf");
- conf.set(network_mode, "mode", "network_mode",0,2);
- 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("mode","network_mode",network_mode,0,2);
+ conf.set("network_bind","bind_interface",bind_interface);
+ conf.set("network_connections","max_connections",max_connections,1,MAX_CONNECTS);
+ conf.set("network_connections","connection_timeout",connection_timeout,1,1000);
+ conf.set("network_connections","ftp_response_timeout",ftp_response_timeout,1,-1);
+ conf.set("network_connections","timeout",time_out,100,-1);
+ conf.set("network_connections","low_connection_speed_limit",low_connection_speed_limit,1,-1);
+ conf.set("network_connections","low_connection_speed_time",low_connection_speed_time,1,600);
+ conf.set("network_connections","max_connection_speed",max_connection_speed,1,-1);
- conf.set(user_agent, "network_user_data", "user_agent");
+ conf.set("network_user_data","user_agent",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");
+ conf.set("network_proxy","proxy_ip_or_name",proxy_ip_or_name);
+ conf.set("network_proxy","proxy_port",proxy_port,1,65535);
+ conf.set("network_proxy","proxy_off",proxy_off);
+ conf.set("network_proxy","proxy_user",proxy_user);
+ conf.set("network_proxy","proxy_password",proxy_password);
// conf.set(use_own_mirror_list_only_on, "network_mirrors", "use_own_mirror_list_only_on");
- if (network_mode==MODE_LOCAL){
- conf.set(only_local_when_possible, "network_mirrors", "only_local_when_possible");
- load_mirror_list();
- log("Settings: Network"+toString(network_num)+" local mirror_list size:"+toString(mirror_list.size()));
+ switch (network_mode){
+ case MODE_LOCAL:
+ {
+ conf.set("network_mirrors","only_local_when_possible",only_local_when_possible);
+ load_mirror_list();
+ log("Settings: Network"+toString(network_num)+" local mirror_list size:"+toString(mirror_list.size()));
+ break;
+ };
+ case MODE_PROXY_FETCHER:
+ {
+ if (proxy_fetcher_ip!="none"){
+ conf.set("network_proxy_fetcher","proxy_fetcher_port",proxy_fetcher_port,1,65535);
+ conf.set("network_mirrors","only_local_when_possible",only_local_when_possible);
+ conf.set("network_proxy_fetcher","proxy_fetcher_ip",proxy_fetcher_ip);
+ load_mirror_list();
+ log("Settings: Network"+toString(network_num)+" local fetcher_local_mirrors_list size:"+toString(mirror_list.size()));
+ }else{
+ error_log("Network"+toString(network_num)+" in PROXY_FETCHER mode, but proxy_fetcher_ip variable haven't been set. Network will be disabled.");
+ priority=0;
+ }
+ break;
+ }
+ default: break; // network in MODE_REMOTE
}
conf.clear();
}catch(...){
diff --git a/segget/network.h b/segget/network.h
index e86e494..e1180fa 100644
--- a/segget/network.h
+++ b/segget/network.h
@@ -75,6 +75,9 @@ class Tnetwork{
bool proxy_off;
string proxy_user;
string proxy_password;
+ //proxy_fetcher
+ string proxy_fetcher_ip;
+ ulong proxy_fetcher_port;
//mirrors
// bool use_own_mirror_list_only_on;
bool only_local_when_possible;
@@ -82,7 +85,7 @@ class Tnetwork{
benchmarked_mirror_list(),
active_connections_num(0),
//network
- network_num(network_count),
+ network_num(0),
priority(0),
//mode
network_mode(0),
@@ -105,10 +108,13 @@ class Tnetwork{
proxy_off(1),
proxy_user("none"),
proxy_password("none"),
+ //proxy_fetcher
+ proxy_fetcher_ip("none"),
+ proxy_fetcher_port(3131),
//mirrors
// use_own_mirror_list_only_on(0),
only_local_when_possible(1)
- {network_count++;};
+ {};
void init(uint priority_value);
bool has_free_connections();
bool connect();
diff --git a/segget/network0.conf b/segget/network0.conf
index 6eee6da..9681fa9 100644
--- a/segget/network0.conf
+++ b/segget/network0.conf
@@ -63,7 +63,7 @@ bind_interface=none
# Maximum value: 20
# Default:
# max_connections=10
-max_connections=1
+max_connections=20
# CONNECTION_TIMEOUT
# Set the number of seconds to wait while trying to connect. Use 0 to wait
@@ -205,14 +205,24 @@ proxy_password=none
# proxy_off=1
proxy_off=1
-[proxy-fetcher]
-# Specify proxy-fetcher address and port
-proxy-fetcher-ip=127.0.0.1
-proxy-fetcher-port=9797
-# Specify the user and password for authentication on a proxy-fetcher-server.
-# proxy-fetcher-user=user
-# proxy-fetcher-password=password
+[network_proxy_fetcher]
+# PROXY_FETCHER_IP
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify IP addres of the proxy-fetcher
+# Default:
+# proxy_fetcher_ip=none
+proxy_fetcher_ip=none
+# PROXY_FETCHER_PORT
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify proxy-fetcher address
+# Default:
+# proxy_fetcher_port=3131
+proxy_fetcher_port=3131
+
+# Specify the user and password for authentication on a proxy-fetcher-server.
+# NOT IMPLEMENTED YET: proxy-fetcher-user=user
+# NOT IMPLEMENTED YET: proxy-fetcher-password=password
# Set to forbid direct connections to Internet servers if it's possible to use
# proxy-fetcher.
# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-if-possible=1
diff --git a/segget/network1.conf b/segget/network1.conf
index ea7e9bf..5edb228 100644
--- a/segget/network1.conf
+++ b/segget/network1.conf
@@ -205,6 +205,32 @@ proxy_password=none
# proxy_off=1
proxy_off=1
+[network_proxy_fetcher]
+# PROXY_FETCHER_IP
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify IP addres of the proxy-fetcher
+# Default:
+# proxy_fetcher_ip=none
+proxy_fetcher_ip=none
+
+# PROXY_FETCHER_PORT
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify proxy-fetcher address
+# Default:
+# proxy_fetcher_port=3131
+proxy_fetcher_port=3131
+
+# Specify the user and password for authentication on a proxy-fetcher-server.
+# NOT IMPLEMENTED YET: proxy-fetcher-user=user
+# NOT IMPLEMENTED YET: proxy-fetcher-password=password
+# Set to forbid direct connections to Internet servers if it's possible to use
+# proxy-fetcher.
+# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-if-possible=1
+# Set to forbid direct connections to Internet servers.
+# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-only=0
+# Set to forbid using proxy-fetcher.
+# NOT IMPLEMENTED YET: no-proxy-fetcher
+
[network_mirrors]
# SYNOPSIS: NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 | 1
# - If set to 1, segget will replace mirror list provided by portage system with
diff --git a/segget/network2.conf b/segget/network2.conf
index bc2548d..e87b213 100644
--- a/segget/network2.conf
+++ b/segget/network2.conf
@@ -205,6 +205,32 @@ proxy_password=none
# proxy_off=1
proxy_off=1
+[network_proxy_fetcher]
+# PROXY_FETCHER_IP
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify IP addres of the proxy-fetcher
+# Default:
+# proxy_fetcher_ip=none
+proxy_fetcher_ip=none
+
+# PROXY_FETCHER_PORT
+# This option is active only when NETWORK_MODE=1, in other cases it's ignored.
+# Specify proxy-fetcher address
+# Default:
+# proxy_fetcher_port=3131
+proxy_fetcher_port=3131
+
+# Specify the user and password for authentication on a proxy-fetcher-server.
+# NOT IMPLEMENTED YET: proxy-fetcher-user=user
+# NOT IMPLEMENTED YET: proxy-fetcher-password=password
+# Set to forbid direct connections to Internet servers if it's possible to use
+# proxy-fetcher.
+# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-if-possible=1
+# Set to forbid direct connections to Internet servers.
+# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-only=0
+# Set to forbid using proxy-fetcher.
+# NOT IMPLEMENTED YET: no-proxy-fetcher
+
[network_mirrors]
# SYNOPSIS: NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 | 1
# - If set to 1, segget will replace mirror list provided by portage system with
diff --git a/segget/segget.conf b/segget/segget.conf
index 5e103c0..26b39dd 100644
--- a/segget/segget.conf
+++ b/segget/segget.conf
@@ -76,7 +76,7 @@ max_tries=10
# Maximum value: 20
# Default:
# max_connections=10
-max_connections=3
+max_connections=20
# CURRENT_SPEED_TIME_INTERVAL_MSECS
# segget transfers may have bursty nature of their traffic. Therefore, while
@@ -175,14 +175,11 @@ provide_mirror_dir=./provide_mirror_dir
provide_mirror_files_restrict_list_on=1
[provide_proxy_fetcher_to_others]
-# tuiclient monitors segget's activity by establishing tcp connection
-# with segget daemon (ui_server part of it).
-
# PROVIDE_PROXY_FETCHER_IP
# Define an ip address segget will use to provide access for tuiclients.
# The parameter should be a string holding your host dotted IP address.
# Default:
-# provide_proxy_fetcher_ip=127.0.0.1
+# provide_proxy_fetcher_ip=none
provide_proxy_fetcher_ip=127.0.0.1
# PROVIDE_PROXY_FETCHER_PORT
@@ -191,8 +188,8 @@ provide_proxy_fetcher_ip=127.0.0.1
# Minimum value: 1
# Maximum value: 65535
# Default:
-# provide_proxy_fetcher_port=9777
-provide_proxy_fetcher_port=9777
+# provide_proxy_fetcher_port=3131
+provide_proxy_fetcher_port=3130
[networks]
# NETWORK0_PRIORITY
diff --git a/segget/segget.cpp b/segget/segget.cpp
index 4880f98..b8f2b5e 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -293,12 +293,14 @@ void launch_ui_server_thread(){
}
void launch_proxy_fetcher_server_thread(){
- pthread_t proxy_fetcher_server_thread;
- int iret1;
- debug_no_msg("Creating ui_server_thread.");
-// proxy_fetcher_server_thread.init();
- iret1 = pthread_create( &proxy_fetcher_server_thread, NULL, run_proxy_fetcher_server, (void*) NULL);
- debug_no_msg("proxy_fetcher_server_thread launched");
+ if (settings.provide_proxy_fetcher_ip!="none"){
+ pthread_t proxy_fetcher_server_thread;
+ int iret1;
+ debug_no_msg("Creating ui_server_thread.");
+// proxy_fetcher_server_thread.init();
+ iret1 = pthread_create( &proxy_fetcher_server_thread, NULL, run_proxy_fetcher_server, (void*) NULL);
+ debug_no_msg("proxy_fetcher_server_thread launched");
+ }
}
void segget_exit(int sig){
diff --git a/segget/settings.cpp b/segget/settings.cpp
index 329efb3..5a44ad4 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -68,56 +68,57 @@ void Tsettings::load_provide_mirror_files_restricted_patterns_vector(){
void Tsettings::init(){
try{
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");
- conf.set(debug_log_file, "logs", "debug_log_file");
- conf.set(max_connections, "connections", "max_connections",1,MAX_CONNECTS);
+ conf.set("logs","general_log_file",general_log_file);
+ conf.set("logs","logs_dir",logs_dir);
+ conf.set("logs","error_log_file",error_log_file);
+ conf.set("logs","debug_log_file",debug_log_file);
+ conf.set("connections","max_connections",max_connections,1,MAX_CONNECTS);
- conf.set(distfiles_dir, "folders", "distfiles_dir");
- conf.set(segments_dir, "folders", "segments_dir");
+ conf.set("folders","distfiles_dir",distfiles_dir);
+ conf.set("folders","segments_dir",segments_dir);
- 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("pkg_list","pkg_list_dir",pkg_list_dir);
+ conf.set("pkg_list","del_pkg_list_when_dld_finished",del_pkg_list_when_dld_finished);
- conf.set(max_connection_num_per_distfile, "distfiles", "max_connection_num_per_distfile",1,MAX_CONNECTS);
+ conf.set("distfiles","max_connection_num_per_distfile",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("segments","resume_on",resume_on);
+ conf.set("segments","max_segment_size",max_segment_size,10000,10000000);
+ conf.set("segments","max_tries",max_tries,1,-1);
- conf.set(current_speed_time_interval_msecs, "connections", "current_speed_time_interval_msecs",100,60000);
+ conf.set("connections","current_speed_time_interval_msecs",current_speed_time_interval_msecs,100,60000);
- conf.set(max_connections_num_per_mirror, "mirrors", "max_connections_num_per_mirror",1,10);
- conf.set(benchmark_oblivion, "mirrors", "benchmark_oblivion",0,1000);
+ conf.set("mirrors","max_connections_num_per_mirror",max_connections_num_per_mirror,1,10);
+ conf.set("mirrors","benchmark_oblivion",benchmark_oblivion,0,1000);
- conf.set(provide_mirror_dir, "provide_mirror_to_others", "provide_mirror_dir");
+ conf.set("provide_mirror_to_others","provide_mirror_dir",provide_mirror_dir);
if (provide_mirror_dir!="none"){
- conf.set(provide_mirror_files_restrict_list_on, "provide_mirror_to_others", "provide_mirror_files_restrict_list_on");
+ conf.set("provide_mirror_to_others","provide_mirror_files_restrict_list_on",provide_mirror_files_restrict_list_on);
if (provide_mirror_files_restrict_list_on)
load_provide_mirror_files_restricted_patterns_vector();
}
- conf.set(provide_proxy_fetcher_ip, "provide_proxy_fetcher_to_others", "provide_proxy_fetcher_ip");
- conf.set(provide_proxy_fetcher_port, "provide_proxy_fetcher_to_others", "provide_proxy_fetcher_port",1,65535);
+ conf.set("provide_proxy_fetcher_to_others","provide_proxy_fetcher_ip",provide_proxy_fetcher_ip);
+ conf.set("provide_proxy_fetcher_to_others","provide_proxy_fetcher_port",provide_proxy_fetcher_port,1,65535);
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
+ network_array[network_num].network_num=network_num;
if (network_num==0){
cur_network_priority=10;
}else{
cur_network_priority=0;
}
- conf.set(cur_network_priority, "networks", "network"+toString(network_num)+"_priority",0,10);
+ conf.set("networks","network"+toString(network_num)+"_priority",cur_network_priority,0,10);
if (cur_network_priority>0){
network_array[network_num].init(cur_network_priority);
}
}
- conf.set(ui_ip, "ui_server", "ui_ip");
- conf.set(ui_port, "ui_server", "ui_port",1,65535);
+ conf.set("ui_server","ui_ip",ui_ip);
+ conf.set("ui_server","ui_port",ui_port,1,65535);
conf.clear();
}catch(...){