// if project is using more than its share of disk space, // remove some chunks and mark vda_files for update // static int enforce_quota(CHUNK_LIST& chunks) { if (!g_request->host.d_boinc_max) return 0; double x = g_request->host.d_boinc_used_project; if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] share: %f used: %f\n", g_request->host.d_boinc_max, x ); } CHUNK_LIST::iterator it = chunks.begin(); while (x > g_request->host.d_boinc_max && it != chunks.end()) { DB_VDA_CHUNK_HOST& ch = it->second; if (!ch.found) continue; FILE_INFO fi; strcpy(fi.name, ch.physical_file_name); if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] deleting: %s\n", ch.physical_file_name ); } DB_VDA_FILE vf; vf.lookup_id(ch.vda_file_id); x -= vf.chunk_size; g_reply->file_deletes.push_back(fi); it++; } return 0; }
// for each vda_chunk_host not in file list: // - delete from DB // - mark vda_file for update // static int process_chunks_missing_on_client(CHUNK_LIST& chunks) { CHUNK_LIST::iterator it; for (it = chunks.begin(); it != chunks.end(); it++) { DB_VDA_CHUNK_HOST& ch = it->second; if (!ch.present_on_host && ch.transfer_in_progress) continue; if (!ch.found) { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] in DB but not on client: %s\n", ch.physical_file_name ); } char buf[256]; sprintf(buf, "host_id=%d and vda_file_id=%d and physical_file_name='%s'", ch.host_id, ch.vda_file_id, ch.physical_file_name ); int retval = ch.delete_from_db_multi(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "VDA: failed to delete %s\n", buf ); } ch.transfer_in_progress = false; mark_for_update(ch.vda_file_id); } } return 0; }
// for each vda_chunk_host not in file list: // - delete from DB // - mark vda_file for update // static int process_missing_chunks(CHUNK_LIST& chunks) { CHUNK_LIST::iterator it; for (it = chunks.begin(); it != chunks.end(); it++) { DB_VDA_CHUNK_HOST& ch = it->second; if (!ch.present_on_host && ch.transfer_in_progress) continue; if (!ch.found) { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] in DB but not on client: %s\n", ch.name ); } ch.delete_from_db(); ch.transfer_in_progress = false; mark_for_update(ch.vda_file_id); } } return 0; }
// issue upload and download commands // static int issue_transfer_commands(CHUNK_LIST& chunks) { char xml_buf[8192], chunk_name[256], file_name[1024]; int retval; char url[1024], buf[1024]; CHUNK_LIST::iterator it; for (it = chunks.begin(); it != chunks.end(); it++) { vector<const char*> urls; DB_VDA_CHUNK_HOST& ch = it->second; if (!ch.transfer_in_progress) continue; if (!ch.transfer_wait) continue; DB_VDA_FILE vf; retval = vf.lookup_id(ch.vda_file_id); if (retval) return retval; if (ch.present_on_host) { // upload // sprintf(buf, "upload_%s", ch.physical_file_name); if (result_already_on_host(buf)) { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] upload of %s already in progress\n", ch.physical_file_name ); } continue; } if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] sending command to upload %s\n", ch.physical_file_name ); } urls.push_back(config.upload_url); R_RSA_PRIVATE_KEY key; retval = get_file_xml( ch.physical_file_name, urls, vf.chunk_size, dtime() + VDA_HOST_TIMEOUT, false, key, xml_buf ); } else { // download // sprintf(buf, "download_%s", ch.physical_file_name); if (result_already_on_host(buf)) { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] download of %s already in progress\n", ch.physical_file_name ); } continue; } char md5[64], chunk_dir[1024]; int hostid; if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] sending command to download %s\n", ch.physical_file_name ); } parse_physical_filename( ch.physical_file_name, hostid, chunk_name, file_name ); get_chunk_url(vf, chunk_name, url); urls.push_back(url); get_chunk_dir(vf, chunk_name, chunk_dir); retval = get_chunk_md5(chunk_dir, md5); if (retval) return retval; retval = put_file_xml( ch.physical_file_name, urls, md5, vf.chunk_size, dtime() + VDA_HOST_TIMEOUT, xml_buf ); } g_reply->file_transfer_requests.push_back(string(xml_buf)); } return 0; }
// issue upload and download commands // static int issue_transfer_commands(CHUNK_LIST& chunks) { char xml_buf[8192], file_name[1024]; int retval; char url[1024]; CHUNK_LIST::iterator it; for (it = chunks.begin(); it != chunks.end(); it++) { vector<const char*> urls; DB_VDA_CHUNK_HOST& ch = it->second; if (!ch.transfer_in_progress) continue; if (!ch.transfer_wait) continue; DB_VDA_FILE vf; retval = vf.lookup_id(ch.vda_file_id); if (retval) return retval; if (ch.present_on_host) { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] sending upload command: %s\n", ch.name ); } // upload // sprintf(file_name, "%d_%s__%s", g_reply->host.id, ch.name, vf.name); urls.push_back(config.upload_url); R_RSA_PRIVATE_KEY key; retval = get_file_xml( file_name, urls, ch.size, dtime() + VDA_HOST_TIMEOUT, false, key, xml_buf ); } else { if (config.debug_vda) { log_messages.printf(MSG_NORMAL, "[vda] sending download command: %s\n", ch.name ); } // download // char md5[64], chunk_dir[1024]; sprintf(file_name, "%s__%s", ch.name, vf.name); get_chunk_url(vf, ch.name, url); urls.push_back(url); get_chunk_dir(vf, ch.name, chunk_dir); retval = get_chunk_md5(chunk_dir, md5); if (retval) return retval; retval = put_file_xml( file_name, urls, md5, ch.size, dtime() + VDA_HOST_TIMEOUT, xml_buf ); } g_reply->file_transfer_requests.push_back(string(xml_buf)); } return 0; }