diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-26 14:26:14 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-26 14:26:14 +0300 |
commit | 32145bcd99eee1306597f4e355db21437fe12891 (patch) | |
tree | ed81bc6c2ccba269ed7b6156212905b94c5194eb | |
parent | Add request tool. (diff) | |
download | idfetch-32145bcd99eee1306597f4e355db21437fe12891.tar.gz idfetch-32145bcd99eee1306597f4e355db21437fe12891.tar.bz2 idfetch-32145bcd99eee1306597f4e355db21437fe12891.zip |
Implement checks for both (proxy_fetcher and request_server) queues.
There're 2 queues: proxy_fetcher queue and request_server queue.
Note: Segget processes request_server queue first and if no segment was
chosen switches to proxy_fetcher queue.
Before adding a distifile to any of the queues it's necessary to
check both queues, since distfile may already be in one of them.
-rw-r--r-- | segget/pkg.cpp | 49 | ||||
-rw-r--r-- | segget/pkg.h | 3 | ||||
-rw-r--r-- | segget/proxyfetcher.cpp | 27 | ||||
-rw-r--r-- | segget/requestserver.cpp | 22 | ||||
-rw-r--r-- | segget/segget.cpp | 19 |
5 files changed, 63 insertions, 57 deletions
diff --git a/segget/pkg.cpp b/segget/pkg.cpp index b2bf8e9..a6c9887 100644 --- a/segget/pkg.cpp +++ b/segget/pkg.cpp @@ -52,66 +52,31 @@ int Tpkg::push_back_distfile(json_object* json_obj_distfile){ } } -int Tpkg::try_adding_distfile_to_proxy_fetchers_queue(json_object* json_obj_distfile){ - string distfile_name; - try{ - distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name")); - if (is_symlink_restricted(distfile_name)!=-1){ - debug("PROXY_FETCHER: distfile: "+distfile_name+" restricted (name matches restriting pattern"); - return R_PF_REJECTED; - } - for (ulong distfile_num=0; distfile_num<distfile_count; distfile_num++){ - if (Pdistfile_list[distfile_num]->name==distfile_name){ - switch (Pdistfile_list[distfile_num]->status){ - case DDOWNLOADED: { - debug("PROXY_FETCHER: distfile: "+distfile_name+" was downloaded"); - return R_PF_DOWNLOADED; - }; - case DFAILED:{ - debug("PROXY_FETCHER: Failed to download distfile: "+distfile_name); - return R_PF_FAILED; - } - default:{ - debug("PROXY_FETCHER: distfile: "+distfile_name+" was already in queue"); - return R_PF_ALREADY_WAS_IN_QUEUE; - } - } - } - } - return push_back_distfile(json_obj_distfile); - }catch(...){ - error_log("Error in pkg.cpp: pushback_distfile()"); - } - debug("PROXY_FETCHER: Error adding distfile: "+distfile_name+" to proxy-fetcher's queue"); - return R_PF_ERROR_ADDING_TO_PROXY_QUEUE; -} - -int Tpkg::try_adding_distfile_to_request_server_queue(json_object* json_obj_distfile){ - string distfile_name; +int Tpkg::find_distfile(string distfile_name){ try{ for (ulong distfile_num=0; distfile_num<distfile_count; distfile_num++){ if (Pdistfile_list[distfile_num]->name==distfile_name){ switch (Pdistfile_list[distfile_num]->status){ case DDOWNLOADED: { - debug("REQUEST_SERVER: distfile: "+distfile_name+" was downloaded"); + debug("find_distfile(): distfile: "+distfile_name+" was downloaded"); return R_PF_DOWNLOADED; }; case DFAILED:{ - debug("REQUEST_SERVER: Failed to download distfile: "+distfile_name); + debug("find_distfile(): failed to download distfile: "+distfile_name); return R_PF_FAILED; } default:{ - debug("REQUEST_SERVER: distfile: "+distfile_name+" was already in queue"); + debug("find_distfile(): distfile: "+distfile_name+" was already in queue"); return R_PF_ALREADY_WAS_IN_QUEUE; } } } } - return push_back_distfile(json_obj_distfile); + return R_PF_NOT_REQUESTED_YET; }catch(...){ - error_log("Error in pkg.cpp: pushback_distfile()"); + error_log("Error in pkg.cpp: find_distfile()"); } - debug("REQUEST_SERVER: Error adding distfile: "+distfile_name+" to seggets's queue"); + debug("Error in pkg.cpp: find_distfile(): distfile: "+distfile_name); return R_PF_ERROR_ADDING_TO_PROXY_QUEUE; } diff --git a/segget/pkg.h b/segget/pkg.h index 9446baf..a5a6f7b 100644 --- a/segget/pkg.h +++ b/segget/pkg.h @@ -58,8 +58,7 @@ class Tpkg{ Tpkg & operator=(const Tpkg &L); ~Tpkg(); int push_back_distfile(json_object* json_obj_distfile); - int try_adding_distfile_to_request_server_queue(json_object* json_obj_distfile); - int try_adding_distfile_to_proxy_fetchers_queue(json_object* json_obj_distfile); + int find_distfile(string distfile_name); void load_pkg_from_json(json_object* json_obj_pkg); }; diff --git a/segget/proxyfetcher.cpp b/segget/proxyfetcher.cpp index 31e9547..0895729 100644 --- a/segget/proxyfetcher.cpp +++ b/segget/proxyfetcher.cpp @@ -104,7 +104,32 @@ void *run_proxy_fetcher_server(void * ){ error_log("Received a msg from the client:"+recv_msg); string send_response; // char send_buffer[10]=""; - send_response=toString(proxy_fetcher_pkg.try_adding_distfile_to_proxy_fetchers_queue(json_tokener_parse(buffer))); + + 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=request_server_pkg.find_distfile(distfile_name); + switch (result){ + case R_PF_NOT_REQUESTED_YET: + case R_PF_ERROR_ADDING_TO_PROXY_QUEUE: // if error - try with proxy_fetcher + { + result=proxy_fetcher_pkg.find_distfile(distfile_name); + switch (result){ + case R_PF_NOT_REQUESTED_YET:{ + if (is_symlink_restricted(distfile_name)!=-1){ + debug("PROXY_FETCHER: distfile: "+distfile_name+" restricted (name matches restriting pattern"); + result=R_PF_REJECTED; + }else{ + result=proxy_fetcher_pkg.push_back_distfile(json_obj_distfile); + break; + } + } + default: break; + } + break; + } + default: break; + } + 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."); diff --git a/segget/requestserver.cpp b/segget/requestserver.cpp index b53197f..74e214b 100644 --- a/segget/requestserver.cpp +++ b/segget/requestserver.cpp @@ -102,9 +102,27 @@ void *run_request_server(void * ){ // debug("serving client on fd"+toString(fd)); string recv_msg=buffer; error_log("Received a msg from the client:"+recv_msg); - string send_response; // char send_buffer[10]=""; - send_response=toString(request_server_pkg.try_adding_distfile_to_request_server_queue(json_tokener_parse(buffer))); + 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); + switch (result){ + case R_PF_NOT_REQUESTED_YET: + case R_PF_ERROR_ADDING_TO_PROXY_QUEUE: // if error - try with request_server + { + result=proxy_fetcher_pkg.find_distfile(distfile_name); + switch (result){ + case R_PF_NOT_REQUESTED_YET:{ + result=request_server_pkg.push_back_distfile(json_obj_distfile); + break; + } + default: break; + } + break; + } + default: break; + } + 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."); diff --git a/segget/segget.cpp b/segget/segget.cpp index 678a54f..09e8eb3 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -27,7 +27,6 @@ #include "segget.h" int load_pkgs(){ - debug("uuuuuuuuuuuuuummmmmmmmmmmmmmmm"); try{ ifstream json_pkg_list_file; @@ -141,12 +140,12 @@ int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num){ int choose_segment(uint connection_num){ try{ - for (uint pkg_num=0; pkg_num<stats.pkg_count; pkg_num++){ +// 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(Ppkg_array[pkg_num], connection_num)){ +// return 0; +// } +// } if (0==pkg_choose_segment(&request_server_pkg, connection_num)){ return 0; } @@ -400,11 +399,11 @@ int routine(){ }catch(...){ error_log_no_msg("Error in segget.cpp launch_tui_theread() failed"); } - try{ - load_pkgs(); - }catch(...){ +// try{ +// load_pkgs(); +// }catch(...){ //error while loading pkgs - } +// } try{ //show_pkgs(); stats.show_totals(); |