From 2ea25367f590f4e3698cb1e224953bf450cf4307 Mon Sep 17 00:00:00 2001 From: Kostyantyn Ovechko Date: Sat, 17 Jul 2010 13:33:27 +0300 Subject: Add options from tuiclient.conf file [ui_server] tuiclient monitors segget's activity by establishing tcp connection with segget daemon (ui_server part of it). UI_IP Define an ip address segget uses to provide access for tuiclients. The parameter should be a string holding your host dotted IP address. Default: ui_ip=127.0.0.1 UI_PORT Define a port segget uses to provide access for tuiclients. The parameter should be an integer. Minimum value: 1 Maximum value: 65535 Default: ui_port=9999 [logs] LOGS_DIR Define a dir to store log files. Default: logs_dir=./logs GENERAL_LOG_FILE Define a file name to store general log. Default: general_log_file=tuiclient.log ERROR_LOG_FILE Define a file name to store error log. Default: error_log_file=segget.log DEBUG_LOG_FILE Define a file name to store debug log. Default: debug_log_file=segget.log --- segget/connection.cpp | 9 ++++++++- segget/connection.h | 7 ++++--- segget/network.cpp | 22 ++++++++++++++-------- segget/network0.conf | 13 ++----------- segget/network1.conf | 15 +++------------ segget/network2.conf | 13 ++----------- segget/proxyfetcher.cpp | 7 +++---- segget/segget.cpp | 5 +++++ segget/str.cpp | 20 ++++++++++++++++++++ segget/str.h | 4 ++++ segget/ui_server.cpp | 2 +- 11 files changed, 66 insertions(+), 51 deletions(-) (limited to 'segget') diff --git a/segget/connection.cpp b/segget/connection.cpp index 254f971..d64fc16 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -28,19 +28,26 @@ uint Tconnection::total_connections=0; Tconnection connection_array[MAX_CONNECTS]; time_t prev_time; +void init_connections(){ + for (ulong connection_num=0; connection_numparent_distfile->name); + debug("Starting connection for distfile: "+segment->parent_distfile->name); mirror_num=best_mirror_num; network_num=network_number; total_dld_bytes=0; bytes_per_last_interval=0; gettimeofday(&start_time,NULL); active=true; + debug("Connecting network"+toString(network_num)); network_array[network_num].connect(); segment->prepare_for_connection(cm, connection_num, network_num, distfile_num, mirror_num); + debug("Started connection for distfile: "+segment->parent_distfile->name); }catch(...){ error_log("Error in connection.cpp: start()"); } diff --git a/segget/connection.h b/segget/connection.h index 91184e3..d1f9551 100644 --- a/segget/connection.h +++ b/segget/connection.h @@ -38,24 +38,24 @@ using namespace std; class Tconnection{ static uint total_connections; private: - uint connection_num; uint network_num; uint mirror_num; ulong total_dld_bytes; ulong bytes_per_last_interval; public: + uint connection_num; bool active; timeval start_time; Tsegment *segment; Tconnection(): - connection_num(total_connections), network_num(0), mirror_num(0), total_dld_bytes(0), bytes_per_last_interval(0), + connection_num(0), active(0), start_time(), - segment(0){total_connections++;}; + segment(0){}; void start(CURLM *cm, uint network_number, uint distfile_num, Tsegment *started_segment, uint best_mirror_num); void stop(uint connection_result); void inc_bytes_per_last_interval(ulong new_bytes_count); @@ -64,4 +64,5 @@ class Tconnection{ extern time_t prev_time; extern Tconnection connection_array[MAX_CONNECTS]; +void init_connections(); #endif \ No newline at end of file diff --git a/segget/network.cpp b/segget/network.cpp index b3a6f9a..f67d2fb 100644 --- a/segget/network.cpp +++ b/segget/network.cpp @@ -96,15 +96,21 @@ void Tnetwork::init(uint priority_value){ }; 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."); + conf.set("network_proxy_fetcher","proxy_fetcher_ip",proxy_fetcher_ip); + if (proxy_fetcher_ip=="none"){ + error_log("Network"+toString(network_num)+" in PROXY_FETCHER mode, but proxy_fetcher_ip="+proxy_fetcher_ip+". Network will be disabled."); priority=0; + }else{ + conf.set("network_proxy_fetcher","proxy_fetcher_port",proxy_fetcher_port,1,65535); + if (proxy_fetcher_ip==settings.provide_proxy_fetcher_ip && proxy_fetcher_port==settings.provide_proxy_fetcher_port){ + error_log("Error: Network"+toString(network_num)+" settings have the same ip and port for proxy-fetcher as the ones in [provide_proxy_fetcher_to_others] section of segget.conf file."); + error_log(" Segget instance can NOT serve as a proxy-fetcher for itself - network will be disabled"); + priority=0; + }else{ + conf.set("network_mirrors","only_local_when_possible",only_local_when_possible); + load_mirror_list(); + log("Settings: Network"+toString(network_num)+" local fetcher_local_mirrors_list size:"+toString(mirror_list.size())); + } } break; } diff --git a/segget/network0.conf b/segget/network0.conf index 9681fa9..d338d65 100644 --- a/segget/network0.conf +++ b/segget/network0.conf @@ -3,8 +3,8 @@ # 0 - remote mirrors (default) # 1 - proxy fetcher # 2 - local mirrors -# - If set to 2, segget will replace mirror list provided by portage -# system with the list from network0_mirrors.conf file +# - If set to 1 or 2, segget will replace mirror list provided by portage +# system with the list from network#_mirrors.conf file # - If set to 0, segget will use ONLY mirror list provided by portage # system, and will NOT use the list from network0_mirrors.conf file # In some cases it's necessary to make segget prefer local mirrors over @@ -232,15 +232,6 @@ proxy_fetcher_port=3131 # 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 -# the list from network0_mirrors.conf file -# - If set to 0, segget will use ONLY mirror list provided by portage system, -# 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 - # SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1 # If NETWORK_MODE=0 or NETWORK_MODE=1 this option will be ignored. # - If set to 1, segget will not use remote mirrors with equal or lower diff --git a/segget/network1.conf b/segget/network1.conf index 5edb228..da1c680 100644 --- a/segget/network1.conf +++ b/segget/network1.conf @@ -3,8 +3,8 @@ # 0 - remote mirrors (default) # 1 - proxy fetcher # 2 - local mirrors -# - If set to 2, segget will replace mirror list provided by portage -# system with the list from network0_mirrors.conf file +# - If set to 1 or 2, segget will replace mirror list provided by portage +# system with the list from network#_mirrors.conf file # - If set to 0, segget will use ONLY mirror list provided by portage # system, and will NOT use the list from network0_mirrors.conf file # In some cases it's necessary to make segget prefer local mirrors over @@ -211,7 +211,7 @@ proxy_off=1 # Specify IP addres of the proxy-fetcher # Default: # proxy_fetcher_ip=none -proxy_fetcher_ip=none +proxy_fetcher_ip=127.0.0.1 # PROXY_FETCHER_PORT # This option is active only when NETWORK_MODE=1, in other cases it's ignored. @@ -232,15 +232,6 @@ proxy_fetcher_port=3131 # 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 -# the list from network1_mirrors.conf -# - If set to 0, segget will use ONLY mirror list provided by portage system, -# 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 - # SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1 # If NETWORK_MODE=0 or NETWORK_MODE=1 this option will be ignored. # - If set to 1, segget will not use remote mirrors with equal or lower diff --git a/segget/network2.conf b/segget/network2.conf index e87b213..61cc37c 100644 --- a/segget/network2.conf +++ b/segget/network2.conf @@ -3,8 +3,8 @@ # 0 - remote mirrors (default) # 1 - proxy fetcher # 2 - local mirrors -# - If set to 2, segget will replace mirror list provided by portage -# system with the list from network0_mirrors.conf file +# - If set to 1 or 2, segget will replace mirror list provided by portage +# system with the list from network#_mirrors.conf file # - If set to 0, segget will use ONLY mirror list provided by portage # system, and will NOT use the list from network0_mirrors.conf file # In some cases it's necessary to make segget prefer local mirrors over @@ -232,15 +232,6 @@ proxy_fetcher_port=3131 # 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 -# the list from network1_mirrors.conf -# - If set to 0, segget will use ONLY mirror list provided by portage system, -# 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 - # SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1 # If NETWORK_MODE=0 or NETWORK_MODE=1 this option will be ignored. # - If set to 1, segget will not use remote mirrors with equal or lower diff --git a/segget/proxyfetcher.cpp b/segget/proxyfetcher.cpp index dc60afa..3a87730 100644 --- a/segget/proxyfetcher.cpp +++ b/segget/proxyfetcher.cpp @@ -82,7 +82,7 @@ void *run_proxy_fetcher_server(void * ){ //If it isn’t the server, it must be client activity. If close is received, the client has gone away, and you remove it from the descriptor set. Otherwise, you “serve” the client as in the previous examples. }else{ - debug("old client - read"); +// debug("old client - read"); ioctl(fd, FIONREAD, &nread); if(nread == 0) { close(fd); @@ -93,11 +93,10 @@ void *run_proxy_fetcher_server(void * ){ if (nread!=read(fd, &buffer, nread)){ error_log("Error in proxyfetcher.cpp : run_proxy_fetcher_server(): Not all data has been read from proxy-fetcher-client"); } - debug("serving client - read"); - debug("serving client on fd"+toString(fd)); +// debug("serving client - read"); +// debug("serving client on fd"+toString(fd)); string recv_msg=buffer; error_log("Received a msg from the client:"+recv_msg); - proxy_fetcher_pkg.push_back_distfile(json_tokener_parse(buffer)); } } diff --git a/segget/segget.cpp b/segget/segget.cpp index b8f2b5e..0754806 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -350,6 +350,11 @@ int main() { //error while loading settings } + try{ + init_connections(); + }catch(...){ + error_log("error while init_connections"); + } try{ launch_ui_server_thread(); }catch(...){ diff --git a/segget/str.cpp b/segget/str.cpp index 83eaa42..c45787a 100644 --- a/segget/str.cpp +++ b/segget/str.cpp @@ -31,6 +31,26 @@ string toString(uint t){ s << t; return s.str(); } +string toString(int t){ + stringstream s; + s << t; + return s.str(); +} +string toString(ulong t){ + stringstream s; + s << t; + return s.str(); +} +string toString(long t){ + stringstream s; + s << t; + return s.str(); +} +string toString(bool t){ + stringstream s; + s << t; + return s.str(); +} /* template string toString(T t){ stringstream s; diff --git a/segget/str.h b/segget/str.h index c88303a..cd34b9d 100644 --- a/segget/str.h +++ b/segget/str.h @@ -40,6 +40,10 @@ int lower_char(int c); string noupper(string s); string toString(uint t); +string toString(int t); +string toString(ulong t); +string toString(long t); +string toString(bool t); string field(string prefix,ulong t, int width); #endif \ No newline at end of file diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp index f18c399..8e4f2cd 100644 --- a/segget/ui_server.cpp +++ b/segget/ui_server.cpp @@ -54,7 +54,7 @@ void Tui_server::init(){ res=bind(server_sockfd, (struct sockaddr *)&server_address, server_len); if (res != 0){ error_log("Error: "+toString(res) - +" in ui_server.cpp binding socket address"+bind_address + +" in ui_server.cpp binding socket address "+bind_address +":"+toString(ntohs(server_address.sin_port))); } //Create a connection queue and initialize readfds to handle input from server_sockfd: -- cgit v1.2.3-65-gdbad