diff options
Diffstat (limited to 'segget')
-rw-r--r-- | segget/connection.cpp | 7 | ||||
-rw-r--r-- | segget/distfile.cpp | 6 | ||||
-rw-r--r-- | segget/distfile.h | 2 | ||||
-rw-r--r-- | segget/pkg.cpp | 3 | ||||
-rw-r--r-- | segget/requestserver.cpp | 22 | ||||
-rw-r--r-- | segget/segget.cpp | 6 | ||||
-rw-r--r-- | segget/ui_server.cpp | 41 | ||||
-rw-r--r-- | segget/ui_server.h | 5 |
8 files changed, 55 insertions, 37 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp index 2f8399c..274d9ca 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -45,7 +45,6 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme total_dld_bytes=0; bytes_per_last_interval=0; gettimeofday(&start_time,NULL); - active=true; debug("Connecting network"+toString(network_num)); segment->parent_distfile->active_connections_num++; @@ -76,7 +75,7 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme if (run_user_python_script(connection_num)){ return REJECTED_BY_USER_PYTHON_SCRIPT; } - + active=true; debug("aaaaa"); Pcurr_mirror->start(); debug("bbbbb"); @@ -153,7 +152,7 @@ void Tconnection::stop(CURLcode connection_result){ Pcurr_mirror=find_mirror(strip_mirror_name(segment->url)); } */ - + debug("before gettimeofday"); timeval now_time; gettimeofday(&now_time,NULL); @@ -161,7 +160,9 @@ void Tconnection::stop(CURLcode connection_result){ switch (network_array[network_num].network_mode){ case MODE_LOCAL:{ // prnt_distfile->network_distfile_brokers_array[network_num].mirror_fails_vector[mirror_num]=true; + debug("before setting mirror fail"); segment->parent_distfile->network_distfile_brokers_array[network_num].local_mirror_failed(mirror_num); + debug("after setting mirror fail"); // find_mirror(strip_mirror_name(segment->url)); break; } diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 4f56bbe..d8f8eda 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -209,6 +209,7 @@ bool Tdistfile::check_if_dld(){ bool Tdistfile::load_distfile_from_json(json_object* json_obj_distfile){ try{ + debug("Entered distfile.cpp: load_distfile_from_json()"); json_object* json_obj_buffer; json_obj_buffer=json_object_object_get(json_obj_distfile,"name"); if (json_obj_buffer){ @@ -664,8 +665,11 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){ void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){ try{ stats.inc_dld_size(current_segment->segment_size); - if (++dld_segments_count==segments_count) + dld_bytes+=current_segment->segment_size; + ui_server.send_distfile_progress_msg_to_all_clients(name+" "+toString(dld_segments_count)+" "+toString(segments_count)+" "+toString(dld_bytes)+" "+toString(size)); + if (++dld_segments_count==segments_count){ combine_segments(); + } stats.dld_segments_count++; }catch(...){ error_log("Error: distfile.cpp: inc_dld_segments_count()"); diff --git a/segget/distfile.h b/segget/distfile.h index 69f20c7..ebf2b4a 100644 --- a/segget/distfile.h +++ b/segget/distfile.h @@ -95,6 +95,7 @@ class Tdistfile{ bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num); public: uint dld_segments_count; + ulong dld_bytes; Tnetwork_distfile_broker network_distfile_brokers_array[MAX_NETWORKS]; string json_data; // bool downloaded; @@ -119,6 +120,7 @@ class Tdistfile{ uint segment_size; Tdistfile(): dld_segments_count(0), + dld_bytes(0), json_data(""), // downloaded(0), status(DNEW), diff --git a/segget/pkg.cpp b/segget/pkg.cpp index e3a0a41..20cf0c0 100644 --- a/segget/pkg.cpp +++ b/segget/pkg.cpp @@ -38,13 +38,14 @@ Tpkg request_server_pkg; int Tpkg::push_back_distfile(json_object* json_obj_distfile){ try{ - distfile_count++; Tdistfile * Pcur_distfile=new Tdistfile(); if (Pcur_distfile->load_distfile_from_json(json_obj_distfile)){ error_log("Error in pkg.cpp: push_back_distfile(): while loading distfile"); return R_PF_ERROR_ADDING_TO_PROXY_QUEUE; }else{ + debug("pkg.cpp: push_back_distfile(): json import ok - pushback distfile"); Pdistfile_list.push_back(Pcur_distfile); + distfile_count++; return R_PF_ADDED_TO_PROXY_QUEUE; } }catch(...){ diff --git a/segget/requestserver.cpp b/segget/requestserver.cpp index fd1111f..7fd76d3 100644 --- a/segget/requestserver.cpp +++ b/segget/requestserver.cpp @@ -61,13 +61,13 @@ void *run_request_server(void * ){ int nread; testfds = readfds; - debug("proxyfether is waiting for connections"); + debug("requestserver is waiting for connections"); result = select(FD_SETSIZE, &testfds, (fd_set *)0, (fd_set *)0, (struct timeval *) 0); // debug("proxyfether done waiting"); if(result < 1) { - error_log("Error in proxyfetcher.cpp : run"); + error_log("Error in requestserver.cpp : run"); exit(1); } @@ -78,12 +78,12 @@ void *run_request_server(void * ){ //If the activity is on server_sockfd, it must be a request for a new connection, and you add the associated client_sockfd to the descriptor set: if(fd == server_sockfd) { - debug("new client - read"); + debug("requestserver: new client - read"); client_len = sizeof(client_address); client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len); FD_SET(client_sockfd, &readfds); - debug("adding client on fd:"+toString(client_sockfd)); + debug("requestserver: adding client on fd:"+toString(client_sockfd)); //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{ @@ -92,27 +92,32 @@ void *run_request_server(void * ){ if(nread == 0) { close(fd); FD_CLR(fd, &readfds); - debug("removing client on fd:"+toString(fd)); + debug("requestserver: removing client on fd:"+toString(fd)); }else{ char buffer[100000]=""; 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"); + error_log("Error in requestserver.cpp : run_request_server(): Not all data has been read from proxy-fetcher-client"); } // 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); // char send_buffer[10]=""; + debug("trying to add distfile via requestserver"); json_object* json_obj_distfile=json_tokener_parse(buffer); string distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name")); int result=proxy_fetcher_pkg.find_distfile(distfile_name); + debug("search for distfile ended"); switch (result){ case R_PF_NOT_REQUESTED_YET: case R_PF_ERROR_ADDING_TO_PROXY_QUEUE: // if error - try with request_server { + debug("Search in proxy_fetcher distfiles list"); result=proxy_fetcher_pkg.find_distfile(distfile_name); + debug("ENDED search in proxy_fetcher distfiles list"); switch (result){ case R_PF_NOT_REQUESTED_YET:{ + debug("push_back distfile to the queue"); result=request_server_pkg.push_back_distfile(json_obj_distfile); break; } @@ -122,10 +127,11 @@ void *run_request_server(void * ){ } default: break; } + debug("Ended trying to add distfile"); string send_response=toString(result); // if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)msg.length()){ if (write(fd, send_response.c_str(), send_response.length())!=(int)send_response.length()){ - error_log("Error in proxyfetcher.cpp: run_proxy_fetcher_server(): response msg size and sent data size are different."); + error_log("Error in requestserver.cpp: run_request_server(): response msg size and sent data size are different."); }; } } @@ -133,7 +139,7 @@ void *run_request_server(void * ){ } } }catch(...){ - error_log("Error in proxyfetcher.cpp: run_proxy_fetcher_server()"); + error_log("Error in requestserver.cpp: run_request_server()"); return (void*)1; } } diff --git a/segget/segget.cpp b/segget/segget.cpp index 7160c60..6a0d1c4 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -100,8 +100,10 @@ int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num){ try{ uint distfile_num(0); uint segment_num(0); + debug("Entered pkg_choose_segment()"); while(distfile_num<cur_pkg->distfile_count){ // if (Ppkg_array[pkg_num]->distfile_vector[distfile_num].allows_new_actions()){ + debug("considering distfile:"+toString(distfile_num)); if (cur_pkg->Pdistfile_list[distfile_num]->allows_new_actions()){ debug("segment_num:"+toString(segment_num)); debug("segment_count:"+toString(cur_pkg->Pdistfile_list[distfile_num]->segments_count)); @@ -140,15 +142,18 @@ int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num){ int choose_segment(uint connection_num){ try{ + debug("Entered choose_segment()"); // for (uint pkg_num=0; pkg_num<stats.pkg_count; pkg_num++){ // debug("pkg_num:"+toString(pkg_num)); // if (0==pkg_choose_segment(Ppkg_array[pkg_num], connection_num)){ // return 0; // } // } + if (0==pkg_choose_segment(&request_server_pkg, connection_num)){ return 0; } + debug("choose_segment() goes for proxy-fetcher distfiles"); // download distfiles as a proxy-fetcher if (0==pkg_choose_segment(&proxy_fetcher_pkg, connection_num)){ return 0; @@ -217,6 +222,7 @@ int download_pkgs(){ }; debug("Exit connection activation sycle"); } + debug("After attempt to start connection activation cycle"); U=stats.active_connections_counter; debug("before multi_perform"); // while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(cm, &U)){}; diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp index dd68330..29eb5f4 100644 --- a/segget/ui_server.cpp +++ b/segget/ui_server.cpp @@ -61,24 +61,8 @@ void Tui_server::init(){ FD_SET(server_sockfd, &readfds); send_to_fd_busy=false; } -//prevent simultaneous writes -string Tui_server::encode_connection_msg(uint y, string msg){ -// if (send_to_fd_idle) { - string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>"; - return message; -} -string Tui_server::encode_log_msg(string msg){ -// if (send_to_fd_idle) { - string message="<m>l<t>"+msg+"<.>"; - return message; -} - -string Tui_server::encode_error_log_msg(string msg){ -// if (send_to_fd_idle) { - string message="<m>e<t>"+msg+"<.>"; - return message; -} +//prevent simultaneous writes ulong Tui_server::send_to_fd(uint fd, string msg){ // if (send_to_fd_idle) { @@ -98,21 +82,36 @@ ulong Tui_server::send_to_fd(uint fd, string msg){ return 0; } +void Tui_server::send_connection_msg_to_fd(uint fd, uint y, string msg){ + string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>"; + send_to_fd(fd, message); +} + void Tui_server::send_connection_msg_to_all_clients(uint y, string msg){ + string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>"; for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ - send_to_fd(fd, encode_connection_msg(y, msg)); + send_to_fd(fd, message); } } void Tui_server::send_log_msg_to_all_clients(string msg){ + string message="<m>l<t>"+msg+"<.>"; for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ - send_to_fd(fd, encode_log_msg(msg)); + send_to_fd(fd, message); } } void Tui_server::send_error_log_msg_to_all_clients(string msg){ + string message="<m>e<t>"+msg+"<.>"; + for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ + send_to_fd(fd, message); + } +} + +void Tui_server::send_distfile_progress_msg_to_all_clients(string msg){ + string message="<m>d<t>"+msg+"<.>"; for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ - send_to_fd(fd, encode_error_log_msg(msg)); + send_to_fd(fd, message); } } @@ -151,7 +150,7 @@ void *run_ui_server(void * ){ // Get this info to catch up! for (uint line_num=0; line_num<=max_published_screenline_num;line_num++){ - ui_server.send_to_fd(client_sockfd, ui_server.encode_connection_msg(line_num, screenlines[line_num])); + ui_server.send_connection_msg_to_fd(client_sockfd, line_num, screenlines[line_num]); debug_no_msg("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]); // ui_server.send(line_num,screenlines[line_num]); } diff --git a/segget/ui_server.h b/segget/ui_server.h index db67e13..21dbc9e 100644 --- a/segget/ui_server.h +++ b/segget/ui_server.h @@ -53,13 +53,12 @@ class Tui_server{ uint max_fd_num; fd_set readfds, testfds; void init(); - string encode_connection_msg(uint y, string msg); - string encode_log_msg(string msg); - string encode_error_log_msg(string msg); ulong send_to_fd(uint fd, string msg); + void send_connection_msg_to_fd(uint fd, uint y, string msg); void send_connection_msg_to_all_clients(uint y, string msg); void send_log_msg_to_all_clients(string msg); void send_error_log_msg_to_all_clients(string msg); + void send_distfile_progress_msg_to_all_clients(string msg); }; extern Tui_server ui_server; |