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
|
|
|
|
|
|
|
// keep track of the network performance of this host,
|
|
|
|
// namely exponentially weighted averages of upload and download speeds
|
|
|
|
//
|
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
#ifndef _NET_STATS_
|
|
|
|
#define _NET_STATS_
|
|
|
|
|
2010-04-21 22:05:55 +00:00
|
|
|
#include <deque>
|
|
|
|
using std::deque;
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "miofile.h"
|
2003-02-26 00:47:57 +00:00
|
|
|
|
2010-06-18 17:09:18 +00:00
|
|
|
#define NEED_NETWORK_MSG _("BOINC can't access Internet - check network connection or proxy configuration.")
|
|
|
|
|
2007-02-21 22:27:35 +00:00
|
|
|
class FILE_XFER_SET;
|
|
|
|
class HTTP_OP_SET;
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// there's one of these each for upload and download
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
struct NET_INFO {
|
2007-08-17 18:05:39 +00:00
|
|
|
double max_rate;
|
2010-04-01 05:54:29 +00:00
|
|
|
// estimate of max transfer rate; computed as an average of
|
|
|
|
// the rates of recent file transfers, weighted by file size.
|
|
|
|
// This ignores concurrency of transfers.
|
2008-10-04 23:44:24 +00:00
|
|
|
double avg_rate;
|
2010-04-01 05:54:29 +00:00
|
|
|
// recent average transfer rate
|
2011-11-16 19:47:40 +00:00
|
|
|
// i.e. over all time, not just when transfers are active
|
2008-10-04 23:44:24 +00:00
|
|
|
double avg_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// when avg_rate was last updated
|
2007-08-17 18:05:39 +00:00
|
|
|
void update(double nbytes, double dt);
|
2010-04-01 05:54:29 +00:00
|
|
|
// updates the above vars
|
2007-08-17 18:05:39 +00:00
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
};
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
class NET_STATS {
|
|
|
|
public:
|
2003-02-26 00:47:57 +00:00
|
|
|
NET_INFO up;
|
|
|
|
NET_INFO down;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
NET_STATS();
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2004-09-22 21:08:26 +00:00
|
|
|
int write(MIOFILE&);
|
2011-08-09 21:44:14 +00:00
|
|
|
int parse(XML_PARSER&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
2005-06-07 19:22:50 +00:00
|
|
|
|
2006-07-17 22:18:17 +00:00
|
|
|
class NET_STATUS {
|
|
|
|
public:
|
2013-04-03 00:23:37 +00:00
|
|
|
bool need_to_contact_reference_site;
|
|
|
|
// contact the reference site as soon as GUI_HTTP is idle
|
|
|
|
// polled from NET_STATS::poll(), for want of a better place
|
|
|
|
void contact_reference_site();
|
2007-02-10 04:13:08 +00:00
|
|
|
bool show_ref_message;
|
2006-07-17 22:18:17 +00:00
|
|
|
bool need_physical_connection;
|
2010-04-01 05:54:29 +00:00
|
|
|
// client wants to do network comm and no physical connection exists.
|
|
|
|
// Initially false; set whenever a Curl operation
|
|
|
|
// returns CURLE_COULDNT_RESOLVE_HOST,
|
|
|
|
// and a subsequent request to a highly-available site
|
|
|
|
// also returns CURLE_COULDNT_RESOLVE_HOST.
|
|
|
|
// cleared whenever we transfer data,
|
|
|
|
// or an operation returns some other value
|
2006-07-17 22:18:17 +00:00
|
|
|
bool have_sporadic_connection;
|
2010-04-01 05:54:29 +00:00
|
|
|
// we have a network connection, but it's likely to go away soon,
|
|
|
|
// so do as much network comm as possible
|
|
|
|
// (e.g. report completed results)
|
2013-04-03 00:23:37 +00:00
|
|
|
double last_comm_time;
|
2007-02-10 04:13:08 +00:00
|
|
|
|
2006-07-17 22:18:17 +00:00
|
|
|
int network_status();
|
|
|
|
void network_available();
|
|
|
|
void got_http_error();
|
2011-02-18 02:00:02 +00:00
|
|
|
void http_op_succeeded();
|
2006-07-17 22:18:17 +00:00
|
|
|
NET_STATUS() {
|
|
|
|
need_physical_connection = false;
|
|
|
|
have_sporadic_connection = false;
|
2013-04-03 00:23:37 +00:00
|
|
|
need_to_contact_reference_site = false;
|
2007-02-10 04:13:08 +00:00
|
|
|
show_ref_message = false;
|
2013-04-03 00:23:37 +00:00
|
|
|
last_comm_time = 0;
|
2006-12-28 18:24:21 +00:00
|
|
|
}
|
2007-08-17 18:05:39 +00:00
|
|
|
void poll();
|
2006-12-28 18:24:21 +00:00
|
|
|
};
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// This is used to access a reference website (like yahoo or google)
|
|
|
|
// that is assumed to be 100% available.
|
|
|
|
// It is used ONLY from the HTTP code, when a transaction fails
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2006-12-28 18:24:21 +00:00
|
|
|
struct LOOKUP_WEBSITE_OP: public GUI_HTTP_OP {
|
|
|
|
int error_num;
|
|
|
|
|
|
|
|
virtual ~LOOKUP_WEBSITE_OP(){}
|
|
|
|
int do_rpc(std::string&);
|
|
|
|
virtual void handle_reply(int http_op_retval);
|
2007-09-27 21:28:32 +00:00
|
|
|
LOOKUP_WEBSITE_OP(GUI_HTTP* p){
|
2006-12-28 18:24:21 +00:00
|
|
|
error_num = BOINC_SUCCESS;
|
2007-09-27 21:28:32 +00:00
|
|
|
gui_http = p;
|
2006-07-17 22:18:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-21 22:05:55 +00:00
|
|
|
struct DAILY_XFER {
|
2010-04-21 23:17:12 +00:00
|
|
|
int when;
|
2010-04-21 22:05:55 +00:00
|
|
|
double up;
|
|
|
|
double down;
|
|
|
|
DAILY_XFER() {
|
2010-04-21 23:17:12 +00:00
|
|
|
when = 0;
|
|
|
|
up = down = 0;
|
2010-04-21 22:05:55 +00:00
|
|
|
}
|
|
|
|
int parse(XML_PARSER&);
|
2011-10-06 17:23:16 +00:00
|
|
|
void write(MIOFILE&);
|
2010-04-21 22:05:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DAILY_XFER_HISTORY {
|
|
|
|
deque<DAILY_XFER> daily_xfers;
|
|
|
|
bool dirty;
|
|
|
|
|
|
|
|
DAILY_XFER* today();
|
|
|
|
void add(size_t, bool upload);
|
|
|
|
void init();
|
|
|
|
void poll();
|
2010-04-24 03:18:24 +00:00
|
|
|
void totals(int ndays, double& up, double& down);
|
2011-10-06 17:23:16 +00:00
|
|
|
int write_xml(MIOFILE&);
|
|
|
|
void write_file();
|
2010-04-27 17:54:29 +00:00
|
|
|
void write_scheduler_request(MIOFILE&, int ndays);
|
2010-04-21 22:05:55 +00:00
|
|
|
DAILY_XFER_HISTORY() {
|
|
|
|
dirty = false;
|
|
|
|
}
|
2011-10-06 01:14:21 +00:00
|
|
|
void clear() {
|
|
|
|
daily_xfers.clear();
|
|
|
|
}
|
2010-04-21 22:05:55 +00:00
|
|
|
};
|
|
|
|
|
2006-07-17 22:18:17 +00:00
|
|
|
extern NET_STATUS net_status;
|
2010-04-21 22:05:55 +00:00
|
|
|
extern DAILY_XFER_HISTORY daily_xfer_history;
|
2006-07-17 22:18:17 +00:00
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
#endif
|