2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
// NET_STATS estimates average network throughput,
|
|
|
|
// i.e. the average total throughput in both the up and down directions.
|
2007-08-17 18:05:39 +00:00
|
|
|
//
|
|
|
|
// NET_STATUS keeps track of whether we have a physical connection,
|
|
|
|
// and whether we need one
|
2003-02-26 00:47:57 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "cpp.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2007-08-17 18:05:39 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cmath>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2003-02-26 01:04:42 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "time.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2007-08-17 18:05:39 +00:00
|
|
|
#include "util.h"
|
2010-04-21 22:05:55 +00:00
|
|
|
#include "filesys.h"
|
2006-12-28 18:24:21 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2005-06-07 19:22:50 +00:00
|
|
|
#include "client_state.h"
|
2006-12-28 18:24:21 +00:00
|
|
|
#include "file_names.h"
|
2009-12-05 00:51:05 +00:00
|
|
|
#include "cs_proxy.h"
|
2003-07-03 05:01:29 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "net_stats.h"
|
|
|
|
|
2007-08-17 18:05:39 +00:00
|
|
|
#define NET_RATE_HALF_LIFE (7*86400)
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2010-04-21 22:05:55 +00:00
|
|
|
DAILY_XFER_HISTORY daily_xfer_history;
|
2006-07-17 22:18:17 +00:00
|
|
|
NET_STATUS net_status;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
NET_STATS::NET_STATS() {
|
2003-02-26 00:47:57 +00:00
|
|
|
memset(&up, 0, sizeof(up));
|
|
|
|
memset(&down, 0, sizeof(down));
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2007-08-17 18:05:39 +00:00
|
|
|
// called after file xfer to update rates
|
|
|
|
//
|
|
|
|
void NET_INFO::update(double nbytes, double dt) {
|
|
|
|
if (nbytes == 0 || dt==0) return;
|
|
|
|
double bytes_sec = nbytes/dt;
|
|
|
|
if (max_rate == 0) {
|
|
|
|
max_rate = bytes_sec; // first time
|
2006-01-06 19:27:12 +00:00
|
|
|
} else {
|
2007-08-17 18:05:39 +00:00
|
|
|
// somewhat arbitrary weighting formula
|
|
|
|
//
|
|
|
|
double w = log(nbytes)/500;
|
|
|
|
if (w>1) w = 1;
|
|
|
|
max_rate = w*bytes_sec + (1-w)*max_rate;
|
2003-02-26 00:47:57 +00:00
|
|
|
}
|
2007-08-17 18:05:39 +00:00
|
|
|
double start_time = gstate.now - dt;
|
|
|
|
update_average(
|
2010-10-29 23:41:34 +00:00
|
|
|
gstate.now,
|
2007-08-17 18:05:39 +00:00
|
|
|
start_time,
|
|
|
|
nbytes,
|
|
|
|
NET_RATE_HALF_LIFE,
|
|
|
|
avg_rate,
|
|
|
|
avg_time
|
2005-11-25 18:17:09 +00:00
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 21:08:26 +00:00
|
|
|
int NET_STATS::write(MIOFILE& out) {
|
2004-06-12 04:45:36 +00:00
|
|
|
out.printf(
|
2002-04-30 22:22:54 +00:00
|
|
|
"<net_stats>\n"
|
2007-08-17 18:05:39 +00:00
|
|
|
" <bwup>%f</bwup>\n"
|
|
|
|
" <avg_up>%f</avg_up>\n"
|
|
|
|
" <avg_time_up>%f</avg_time_up>\n"
|
|
|
|
" <bwdown>%f</bwdown>\n"
|
|
|
|
" <avg_down>%f</avg_down>\n"
|
|
|
|
" <avg_time_down>%f</avg_time_down>\n"
|
2003-02-26 00:47:57 +00:00
|
|
|
"</net_stats>\n",
|
2007-08-17 18:05:39 +00:00
|
|
|
up.max_rate,
|
|
|
|
up.avg_rate,
|
|
|
|
up.avg_time,
|
|
|
|
down.max_rate,
|
|
|
|
down.avg_rate,
|
|
|
|
down.avg_time
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-09 21:44:14 +00:00
|
|
|
int NET_STATS::parse(XML_PARSER& xp) {
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(this, 0, sizeof(NET_STATS));
|
2011-08-11 17:41:48 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/net_stats")) return 0;
|
|
|
|
if (xp.parse_double("bwup", up.max_rate)) continue;
|
|
|
|
if (xp.parse_double("avg_up", up.avg_rate)) continue;
|
|
|
|
if (xp.parse_double("avg_time_up", up.avg_time)) continue;
|
|
|
|
if (xp.parse_double("bwdown", down.max_rate)) continue;
|
|
|
|
if (xp.parse_double("avg_down", down.avg_rate)) continue;
|
|
|
|
if (xp.parse_double("avg_time_down", down.avg_time)) continue;
|
2007-08-17 18:05:39 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2011-08-11 17:41:48 +00:00
|
|
|
"[unparsed_xml] Unrecognized network statistics line: %s",
|
|
|
|
xp.parsed_tag
|
2007-08-17 18:05:39 +00:00
|
|
|
);
|
2003-02-26 00:47:57 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-01-30 22:19:19 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2006-07-17 22:18:17 +00:00
|
|
|
// Return:
|
2007-05-14 21:45:02 +00:00
|
|
|
// ONLINE if we have network connections open
|
|
|
|
// WANT_CONNECTION if we need a physical connection
|
|
|
|
// WANT_DISCONNECT if we don't have any connections, and don't need any
|
|
|
|
// LOOKUP_PENDING if a website lookup is pending (try again later)
|
2006-07-17 22:18:17 +00:00
|
|
|
//
|
|
|
|
// There's a 10-second slop factor;
|
|
|
|
// if we've done network comm in the last 10 seconds,
|
|
|
|
// we act as if we're doing it now.
|
2006-12-28 18:24:21 +00:00
|
|
|
// (so that polling mechanisms have a chance to start other xfers,
|
|
|
|
// in the case of a modem connection waiting to be closed by the mgr)
|
2006-07-17 22:18:17 +00:00
|
|
|
//
|
|
|
|
int NET_STATUS::network_status() {
|
2011-01-06 23:09:13 +00:00
|
|
|
int retval;
|
2006-07-17 22:18:17 +00:00
|
|
|
|
|
|
|
if (gstate.http_ops->nops()) {
|
|
|
|
last_comm_time = gstate.now;
|
|
|
|
}
|
2009-07-28 22:24:14 +00:00
|
|
|
if (need_to_contact_reference_site) {
|
|
|
|
retval = NETWORK_STATUS_LOOKUP_PENDING;
|
|
|
|
} else if (gstate.lookup_website_op.error_num == ERR_IN_PROGRESS) {
|
2006-12-28 18:24:21 +00:00
|
|
|
retval = NETWORK_STATUS_LOOKUP_PENDING;
|
2011-01-06 23:09:13 +00:00
|
|
|
} else if (gstate.now - last_comm_time < 10) {
|
2006-08-29 18:18:36 +00:00
|
|
|
retval = NETWORK_STATUS_ONLINE;
|
|
|
|
} else if (need_physical_connection) {
|
|
|
|
retval = NETWORK_STATUS_WANT_CONNECTION;
|
|
|
|
} else if (gstate.active_tasks.want_network()) {
|
|
|
|
retval = NETWORK_STATUS_WANT_CONNECTION;
|
2011-01-06 23:09:13 +00:00
|
|
|
} else {
|
|
|
|
have_sporadic_connection = false;
|
|
|
|
retval = NETWORK_STATUS_WANT_DISCONNECT;
|
|
|
|
}
|
|
|
|
if (log_flags.network_status_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[network_status] status: %s", network_status_string(retval));
|
|
|
|
}
|
|
|
|
return retval;
|
2006-07-17 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// There's now a network connection, after some period of disconnection.
|
|
|
|
// Do all communication that we can.
|
|
|
|
//
|
|
|
|
void NET_STATUS::network_available() {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
have_sporadic_connection = true;
|
|
|
|
for (i=0; i<gstate.pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
PERS_FILE_XFER* pfx = gstate.pers_file_xfers->pers_file_xfers[i];
|
|
|
|
pfx->next_request_time = 0;
|
|
|
|
}
|
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
|
|
|
p->min_rpc_time = 0;
|
2011-11-20 09:18:12 +00:00
|
|
|
p->upload_backoff.clear_temporary();
|
|
|
|
p->download_backoff.clear_temporary();
|
2006-07-17 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tell active tasks that network is available (for Folding@home)
|
|
|
|
//
|
|
|
|
gstate.active_tasks.network_available();
|
|
|
|
}
|
|
|
|
|
|
|
|
// An HTTP operation failed;
|
|
|
|
// it could be because there's no physical network connection.
|
2009-07-28 22:24:14 +00:00
|
|
|
// Find out for sure by trying to contact a reference site
|
2006-07-17 22:18:17 +00:00
|
|
|
//
|
|
|
|
void NET_STATUS::got_http_error() {
|
2010-07-30 20:51:08 +00:00
|
|
|
// Cause a round of proxy detections to occur
|
2010-08-03 16:57:18 +00:00
|
|
|
if (working_proxy_info.autodetect_proxy_supported) {
|
|
|
|
working_proxy_info.need_autodetect_proxy_settings = true;
|
|
|
|
working_proxy_info.have_autodetect_proxy_settings = false;
|
|
|
|
}
|
2010-07-30 20:51:08 +00:00
|
|
|
|
2009-07-28 22:24:14 +00:00
|
|
|
if (gstate.lookup_website_op.error_num == ERR_IN_PROGRESS) return;
|
2010-07-30 20:51:08 +00:00
|
|
|
|
|
|
|
// Don't spam the reference site when a project is down
|
2009-07-28 22:24:14 +00:00
|
|
|
if (need_physical_connection) return;
|
2010-07-30 20:51:08 +00:00
|
|
|
|
2009-07-28 22:24:14 +00:00
|
|
|
if (config.dont_contact_ref_site) return;
|
|
|
|
|
|
|
|
if (log_flags.network_status_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[network_status] got HTTP error - checking ref site"
|
2009-07-28 22:24:14 +00:00
|
|
|
);
|
2006-07-17 22:18:17 +00:00
|
|
|
}
|
2009-07-28 22:24:14 +00:00
|
|
|
need_to_contact_reference_site = true;
|
|
|
|
show_ref_message = true;
|
2006-07-17 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 02:00:02 +00:00
|
|
|
void NET_STATUS::http_op_succeeded() {
|
|
|
|
need_physical_connection = false;
|
|
|
|
}
|
|
|
|
|
2006-08-29 18:18:36 +00:00
|
|
|
void NET_STATUS::contact_reference_site() {
|
2011-01-06 23:09:13 +00:00
|
|
|
if (log_flags.network_status_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"[network_status] need_phys_conn %d; trying %s",
|
2008-10-14 23:07:40 +00:00
|
|
|
need_physical_connection, config.network_test_url.c_str()
|
2011-01-06 23:09:13 +00:00
|
|
|
);
|
|
|
|
}
|
2008-10-14 23:07:40 +00:00
|
|
|
gstate.lookup_website_op.do_rpc(config.network_test_url);
|
2011-01-06 23:09:13 +00:00
|
|
|
need_to_contact_reference_site = false;
|
2006-08-29 18:18:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 23:37:44 +00:00
|
|
|
static void show_fail_msg() {
|
2010-06-18 17:09:18 +00:00
|
|
|
msg_printf(0, MSG_USER_ALERT, NEED_NETWORK_MSG);
|
2010-06-08 23:37:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-28 18:24:21 +00:00
|
|
|
int LOOKUP_WEBSITE_OP::do_rpc(string& url) {
|
|
|
|
int retval;
|
|
|
|
|
2007-02-10 04:13:08 +00:00
|
|
|
if (net_status.show_ref_message) {
|
2009-07-24 19:09:37 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"Project communication failed: attempting access to reference site"
|
|
|
|
);
|
2007-02-10 04:13:08 +00:00
|
|
|
}
|
2011-06-12 20:58:43 +00:00
|
|
|
retval = gui_http->do_rpc(this, url.c_str(), LOOKUP_WEBSITE_FILENAME, true);
|
2006-12-28 18:24:21 +00:00
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
net_status.need_physical_connection = true;
|
2011-01-06 23:09:13 +00:00
|
|
|
net_status.last_comm_time = 0;
|
2009-08-07 18:16:21 +00:00
|
|
|
|
2010-06-08 23:37:44 +00:00
|
|
|
show_fail_msg();
|
2006-12-28 18:24:21 +00:00
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LOOKUP_WEBSITE_OP::handle_reply(int http_op_retval) {
|
|
|
|
error_num = http_op_retval;
|
|
|
|
|
|
|
|
// if we couldn't contact a reference web site,
|
|
|
|
// we can assume there's a problem that requires user attention
|
|
|
|
// (usually no physical network connection).
|
|
|
|
// Set a flag that will signal the Manager to that effect
|
|
|
|
//
|
|
|
|
if (http_op_retval) {
|
|
|
|
net_status.need_physical_connection = true;
|
2011-01-06 23:09:13 +00:00
|
|
|
net_status.last_comm_time = 0;
|
2010-06-08 23:37:44 +00:00
|
|
|
show_fail_msg();
|
2006-12-28 18:24:21 +00:00
|
|
|
} else {
|
2007-02-10 04:13:08 +00:00
|
|
|
if (net_status.show_ref_message) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2007-10-04 17:30:28 +00:00
|
|
|
"Internet access OK - project servers may be temporarily down."
|
2007-02-10 04:13:08 +00:00
|
|
|
);
|
|
|
|
}
|
2006-12-28 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-17 18:05:39 +00:00
|
|
|
void NET_STATUS::poll() {
|
2009-07-28 22:24:14 +00:00
|
|
|
// for 30 seconds after wakeup, the network system (DNS etc.)
|
|
|
|
// may still be coming up, so defer the reference site check;
|
|
|
|
// otherwise might show spurious "need connection" message
|
|
|
|
//
|
|
|
|
if (gstate.now < gstate.last_wakeup_time + 30) return;
|
2010-08-02 19:34:24 +00:00
|
|
|
// wait until after a round of automatic proxy detection
|
|
|
|
// before attempting to contact the reference site
|
|
|
|
//
|
2010-08-03 16:57:18 +00:00
|
|
|
if (working_proxy_info.autodetect_proxy_supported &&
|
|
|
|
working_proxy_info.need_autodetect_proxy_settings &&
|
|
|
|
!working_proxy_info.have_autodetect_proxy_settings) return;
|
2010-08-02 19:34:24 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
if (net_status.need_to_contact_reference_site && !gstate.gui_http.is_busy()) {
|
|
|
|
net_status.contact_reference_site();
|
|
|
|
}
|
2007-08-17 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 22:05:55 +00:00
|
|
|
int DAILY_XFER::parse(XML_PARSER& xp) {
|
2011-08-10 17:11:08 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/dx")) return 0;
|
|
|
|
if (xp.parse_int("when", when)) continue;
|
|
|
|
if (xp.parse_double("up", up)) continue;
|
|
|
|
if (xp.parse_double("down", down)) continue;
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2011-10-06 17:23:16 +00:00
|
|
|
void DAILY_XFER::write(MIOFILE& mf) {
|
|
|
|
mf.printf(
|
2010-04-21 22:05:55 +00:00
|
|
|
"<dx>\n"
|
2010-04-21 23:17:12 +00:00
|
|
|
" <when>%d</when>\n"
|
2010-04-21 22:05:55 +00:00
|
|
|
" <up>%f</up>\n"
|
|
|
|
" <down>%f</down>\n"
|
|
|
|
"</dx>\n",
|
|
|
|
when, up, down
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-05-03 17:20:44 +00:00
|
|
|
inline int current_day() {
|
2010-05-08 19:20:57 +00:00
|
|
|
return (int)((gstate.now + gstate.host_info.timezone)/86400);
|
2010-05-03 17:20:44 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 22:05:55 +00:00
|
|
|
DAILY_XFER* DAILY_XFER_HISTORY::today() {
|
2010-05-03 17:20:44 +00:00
|
|
|
int d = current_day();
|
2010-04-21 22:05:55 +00:00
|
|
|
for (unsigned int i=0; i<daily_xfers.size(); i++) {
|
|
|
|
DAILY_XFER& dx = daily_xfers[i];
|
|
|
|
if (dx.when == d) {
|
|
|
|
return &dx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DAILY_XFER dx;
|
|
|
|
dx.when = d;
|
|
|
|
daily_xfers.push_front(dx);
|
2010-04-21 22:51:05 +00:00
|
|
|
return &(daily_xfers.front());
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DAILY_XFER_HISTORY::add(size_t x, bool upload) {
|
|
|
|
DAILY_XFER* dxp = today();
|
|
|
|
if (upload) {
|
|
|
|
dxp->up += x;
|
|
|
|
} else {
|
|
|
|
dxp->down += x;
|
|
|
|
}
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DAILY_XFER_HISTORY::init() {
|
|
|
|
FILE* f = fopen(DAILY_XFER_HISTORY_FILENAME, "r");
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
2010-04-22 02:57:50 +00:00
|
|
|
mf.init_file(f);
|
2010-04-21 22:05:55 +00:00
|
|
|
|
2010-05-03 17:20:44 +00:00
|
|
|
int d = current_day();
|
2010-04-21 22:05:55 +00:00
|
|
|
|
|
|
|
if (!xp.parse_start("daily_xfers")) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-10 17:11:08 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (!xp.is_tag) continue;
|
|
|
|
if (xp.match_tag("dx")) {
|
2010-04-21 22:05:55 +00:00
|
|
|
DAILY_XFER dx;
|
|
|
|
int retval = dx.parse(xp);
|
2010-04-21 23:17:12 +00:00
|
|
|
if (!retval && d - dx.when < 365) {
|
2010-04-21 22:05:55 +00:00
|
|
|
// discard records after a year
|
|
|
|
daily_xfers.push_back(dx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-22 02:57:50 +00:00
|
|
|
fclose(f);
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DAILY_XFER_HISTORY::poll() {
|
|
|
|
static double last_time= 0;
|
|
|
|
|
|
|
|
if (!dirty) return;
|
|
|
|
if (gstate.now - last_time < DAILY_XFER_HISTORY_PERIOD) return;
|
|
|
|
last_time = gstate.now;
|
2011-10-06 17:23:16 +00:00
|
|
|
write_file();
|
2010-04-27 17:54:29 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 17:23:16 +00:00
|
|
|
int DAILY_XFER_HISTORY::write_xml(MIOFILE& out) {
|
|
|
|
out.printf("<daily_xfers>\n");
|
2010-04-21 22:05:55 +00:00
|
|
|
for (unsigned int i=0; i<daily_xfers.size(); i++) {
|
|
|
|
DAILY_XFER& dx = daily_xfers[i];
|
2011-10-06 17:23:16 +00:00
|
|
|
dx.write(out);
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
2011-10-06 17:23:16 +00:00
|
|
|
int n = out.printf("</daily_xfers>\n");
|
2011-10-06 17:39:13 +00:00
|
|
|
if (n <= 0) return ERR_FWRITE;
|
2011-10-06 17:23:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DAILY_XFER_HISTORY::write_file() {
|
|
|
|
FILE* f = fopen(TEMP_FILE_NAME, "w");
|
|
|
|
if (!f) return;
|
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
|
|
|
int retval = write_xml(mf);
|
2010-04-21 22:05:55 +00:00
|
|
|
fclose(f);
|
2011-10-06 17:39:13 +00:00
|
|
|
if (retval) {
|
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"failed to write xfer history: %s",
|
|
|
|
boincerror(retval)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
retval = boinc_rename(TEMP_FILE_NAME, DAILY_XFER_HISTORY_FILENAME);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"failed to rename xfer history file: %s",
|
|
|
|
boincerror(retval)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
dirty = false;
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-21 23:17:12 +00:00
|
|
|
|
2010-04-24 03:18:24 +00:00
|
|
|
void DAILY_XFER_HISTORY::totals(int ndays, double& up, double& down) {
|
2010-05-03 19:21:39 +00:00
|
|
|
int d = (current_day() - ndays);
|
2010-04-24 03:18:24 +00:00
|
|
|
up = down = 0;
|
2010-04-21 23:17:12 +00:00
|
|
|
for (unsigned int i=0; i<daily_xfers.size(); i++) {
|
|
|
|
DAILY_XFER& dx = daily_xfers[i];
|
2010-04-28 16:22:06 +00:00
|
|
|
if (dx.when <= d) break;
|
2010-04-24 03:18:24 +00:00
|
|
|
up += dx.up;
|
|
|
|
down += dx.down;
|
2010-04-21 23:17:12 +00:00
|
|
|
}
|
2010-04-24 03:18:24 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 17:54:29 +00:00
|
|
|
void DAILY_XFER_HISTORY::write_scheduler_request(MIOFILE& mf, int ndays) {
|
2010-04-24 03:18:24 +00:00
|
|
|
double up, down;
|
|
|
|
totals(ndays, up, down);
|
|
|
|
mf.printf(
|
|
|
|
"<daily_xfer_history>\n"
|
|
|
|
" <ndays>%d</ndays>\n"
|
|
|
|
" <up>%f</up>\n"
|
|
|
|
" <down>%f</down>\n"
|
|
|
|
"</daily_xfer_history>\n",
|
|
|
|
ndays, up, down
|
|
|
|
);
|
2010-04-21 23:17:12 +00:00
|
|
|
}
|