2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
#ifndef _CLIENT_STATE_
|
|
|
|
#define _CLIENT_STATE_
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <vector>
|
2002-07-31 19:05:15 +00:00
|
|
|
#include <time.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_types.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "file_xfer.h"
|
|
|
|
#include "hostinfo.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "http.h"
|
2003-05-29 23:25:15 +00:00
|
|
|
#include "language.h"
|
2002-12-09 23:51:55 +00:00
|
|
|
#include "message.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "net_stats.h"
|
|
|
|
#include "net_xfer.h"
|
2002-08-07 22:52:10 +00:00
|
|
|
#include "pers_file_xfer.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "prefs.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "scheduler_op.h"
|
2003-05-29 23:25:15 +00:00
|
|
|
#include "ss_logic.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "time_stats.h"
|
2002-12-19 00:37:19 +00:00
|
|
|
#include "file_names.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
// CLIENT_STATE is the global variables of the core client
|
|
|
|
// Most of the state is saved to and restored from "client_state.xml"
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
class CLIENT_STATE {
|
|
|
|
public:
|
|
|
|
vector<PROJECT*> projects;
|
|
|
|
vector<APP*> apps;
|
|
|
|
vector<FILE_INFO*> file_infos;
|
|
|
|
vector<APP_VERSION*> app_versions;
|
|
|
|
vector<WORKUNIT*> workunits;
|
|
|
|
vector<RESULT*> results;
|
|
|
|
|
|
|
|
NET_XFER_SET* net_xfers;
|
2002-08-07 22:52:10 +00:00
|
|
|
PERS_FILE_XFER_SET* pers_xfers;
|
2002-04-30 22:22:54 +00:00
|
|
|
HTTP_OP_SET* http_ops;
|
|
|
|
FILE_XFER_SET* file_xfers;
|
|
|
|
ACTIVE_TASK_SET active_tasks;
|
|
|
|
HOST_INFO host_info;
|
2002-09-29 00:32:11 +00:00
|
|
|
GLOBAL_PREFS global_prefs;
|
2002-08-26 22:57:17 +00:00
|
|
|
NET_STATS net_stats;
|
2003-05-09 20:33:57 +00:00
|
|
|
SS_LOGIC ss_logic;
|
2003-06-06 22:08:46 +00:00
|
|
|
LANGUAGE language;
|
2002-08-26 22:57:17 +00:00
|
|
|
|
|
|
|
CLIENT_STATE();
|
|
|
|
int init();
|
|
|
|
int restart_tasks();
|
2003-01-07 01:02:08 +00:00
|
|
|
int cleanup_and_exit();
|
2002-08-26 22:57:17 +00:00
|
|
|
bool do_something();
|
2003-02-18 03:31:47 +00:00
|
|
|
// Initiates and completes actions (file transfers, process executions)
|
|
|
|
// Never blocks.
|
|
|
|
// Returns true if it actually did something,
|
|
|
|
// in which case it should be called again immediately.
|
|
|
|
int net_sleep(double dt);
|
|
|
|
// sleeps until either dt seconds have elapsed,
|
|
|
|
// or until there's network activity.
|
2002-08-26 22:57:17 +00:00
|
|
|
void parse_cmdline(int argc, char** argv);
|
2002-12-19 00:00:43 +00:00
|
|
|
void parse_env_vars();
|
2002-08-26 22:57:17 +00:00
|
|
|
bool time_to_exit();
|
2003-05-30 17:59:14 +00:00
|
|
|
int set_nslots();
|
2003-04-01 03:28:37 +00:00
|
|
|
bool should_run_cpu_benchmarks();
|
|
|
|
int cpu_benchmarks();
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-04-01 03:28:37 +00:00
|
|
|
static DWORD WINAPI win_cpu_benchmarks(LPVOID);
|
|
|
|
HANDLE cpu_benchmarks_handle;
|
|
|
|
DWORD cpu_benchmarks_id;
|
2002-12-09 23:51:55 +00:00
|
|
|
#else
|
2003-04-01 03:28:37 +00:00
|
|
|
PROCESS_ID cpu_benchmarks_id;
|
2002-12-09 23:51:55 +00:00
|
|
|
#endif
|
2003-04-01 03:28:37 +00:00
|
|
|
unsigned int cpu_benchmarks_start;
|
|
|
|
int check_cpu_benchmarks();
|
2003-05-09 22:44:35 +00:00
|
|
|
void trunc_stderr_stdout();
|
2003-05-21 23:23:42 +00:00
|
|
|
double estimate_cpu_time(WORKUNIT&);
|
2002-12-19 00:37:19 +00:00
|
|
|
int project_disk_usage(PROJECT*, double&);
|
2002-12-06 07:33:45 +00:00
|
|
|
int current_disk_usage(double&);
|
|
|
|
// returns the total disk usage of BOINC on this host
|
|
|
|
int allowed_disk_usage(double&);
|
2003-03-16 21:59:11 +00:00
|
|
|
int file_xfer_giveup_period;
|
2002-11-19 22:57:05 +00:00
|
|
|
bool user_idle;
|
2002-12-09 03:07:36 +00:00
|
|
|
bool suspend_requested;
|
2003-03-11 00:49:07 +00:00
|
|
|
bool start_saver;
|
2003-01-07 01:02:08 +00:00
|
|
|
bool exit_when_idle;
|
2003-05-15 17:10:26 +00:00
|
|
|
bool show_projects;
|
2003-04-08 18:36:03 +00:00
|
|
|
bool requested_exit;
|
2002-12-19 00:00:43 +00:00
|
|
|
bool use_http_proxy;
|
|
|
|
bool use_socks_proxy;
|
2002-12-09 03:07:36 +00:00
|
|
|
int proxy_server_port;
|
2003-05-15 17:10:26 +00:00
|
|
|
char detach_project_url[256];
|
|
|
|
// stores URL for -detach_project option
|
|
|
|
char reset_project_url[256];
|
|
|
|
// stores URL for -reset_project option
|
|
|
|
char update_prefs_url[256];
|
|
|
|
// stores URL for -update_prefs option
|
2002-12-09 03:07:36 +00:00
|
|
|
char proxy_server_name[256];
|
2002-12-19 00:00:43 +00:00
|
|
|
char socks_user_name[256];
|
|
|
|
char socks_user_passwd[256];
|
2003-03-06 00:42:18 +00:00
|
|
|
char host_venue[256]; // venue, as reported by project that sent us
|
|
|
|
// most recent global prefs
|
2003-03-31 23:18:55 +00:00
|
|
|
bool exit_before_upload;
|
|
|
|
// exit when about to upload a file
|
2003-06-11 22:25:13 +00:00
|
|
|
// exponential backoff variables
|
|
|
|
int master_fetch_period, retry_base_period, retry_cap;
|
|
|
|
int master_fetch_retry_cap, master_fetch_interval;
|
|
|
|
int sched_retry_delay_min, sched_retry_delay_max;
|
|
|
|
int pers_retry_delay_min, pers_retry_delay_max, pers_giveup;
|
2002-12-09 23:51:55 +00:00
|
|
|
|
2002-08-12 22:26:32 +00:00
|
|
|
private:
|
2002-08-22 21:04:42 +00:00
|
|
|
bool client_state_dirty;
|
2003-06-05 23:07:38 +00:00
|
|
|
time_t last_write_state_file;
|
2002-04-30 22:22:54 +00:00
|
|
|
TIME_STATS time_stats;
|
2002-12-01 06:14:28 +00:00
|
|
|
int core_client_major_version;
|
|
|
|
int core_client_minor_version;
|
2003-05-15 17:10:26 +00:00
|
|
|
int old_major_version;
|
|
|
|
int old_minor_version;
|
2002-08-14 23:02:32 +00:00
|
|
|
char* platform_name;
|
2003-03-20 02:05:25 +00:00
|
|
|
int nslots;
|
2003-04-01 03:28:37 +00:00
|
|
|
bool skip_cpu_benchmarks;
|
|
|
|
// if set, use hardwired numbers rather than running benchmarks
|
|
|
|
bool run_cpu_benchmarks;
|
|
|
|
// if set, run benchmarks on client startup
|
2002-04-30 22:22:54 +00:00
|
|
|
bool activities_suspended;
|
2003-02-12 19:53:46 +00:00
|
|
|
int exit_after_app_start_secs;
|
|
|
|
// if nonzero, exit this many seconds after starting an app
|
2002-07-31 19:05:15 +00:00
|
|
|
time_t app_started;
|
2003-02-12 19:53:46 +00:00
|
|
|
// when the most recent app was started
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
int parse_account_files();
|
2002-04-30 22:22:54 +00:00
|
|
|
int parse_state_file();
|
|
|
|
int write_state_file();
|
|
|
|
int write_state_file_if_needed();
|
|
|
|
int link_app(PROJECT*, APP*);
|
|
|
|
int link_file_info(PROJECT*, FILE_INFO*);
|
2002-05-17 22:33:57 +00:00
|
|
|
int link_file_ref(PROJECT*, FILE_REF*);
|
2002-04-30 22:22:54 +00:00
|
|
|
int link_app_version(PROJECT*, APP_VERSION*);
|
|
|
|
int link_workunit(PROJECT*, WORKUNIT*);
|
|
|
|
int link_result(PROJECT*, RESULT*);
|
2002-07-29 00:39:45 +00:00
|
|
|
int latest_version_num(char*);
|
2002-04-30 22:22:54 +00:00
|
|
|
int check_suspend_activities();
|
|
|
|
int make_project_dirs();
|
|
|
|
int make_slot_dirs();
|
|
|
|
bool input_files_available(RESULT*);
|
|
|
|
int app_finished(ACTIVE_TASK&);
|
|
|
|
bool start_apps();
|
2003-05-22 20:47:56 +00:00
|
|
|
bool handle_finished_apps();
|
2002-08-21 19:12:42 +00:00
|
|
|
bool handle_pers_file_xfers();
|
2003-01-07 22:49:42 +00:00
|
|
|
void print_summary();
|
2002-04-30 22:22:54 +00:00
|
|
|
bool garbage_collect();
|
2002-08-12 21:54:19 +00:00
|
|
|
bool update_results();
|
2003-02-26 00:47:57 +00:00
|
|
|
void install_global_prefs();
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
// stuff related to scheduler RPCs
|
|
|
|
//
|
|
|
|
SCHEDULER_OP* scheduler_op;
|
|
|
|
bool contacted_sched_server;
|
|
|
|
void compute_resource_debts();
|
|
|
|
public:
|
2002-08-07 22:52:10 +00:00
|
|
|
bool start_new_file_xfer();
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* next_project(PROJECT*);
|
|
|
|
PROJECT* next_project_master_pending();
|
2003-02-27 09:21:22 +00:00
|
|
|
PROJECT* next_project_sched_rpc_pending();
|
2002-07-15 05:34:32 +00:00
|
|
|
double work_needed_secs();
|
|
|
|
int make_scheduler_request(PROJECT*, double);
|
2003-01-02 23:12:05 +00:00
|
|
|
int handle_scheduler_reply(PROJECT*, char* scheduler_url, int& nresults);
|
2002-08-22 21:29:58 +00:00
|
|
|
void set_client_state_dirty(char*);
|
2003-03-13 21:49:52 +00:00
|
|
|
int report_result_error(RESULT &res, int err_num, char *err_msg);
|
2002-12-19 22:43:38 +00:00
|
|
|
// flag a result as having an error
|
2003-02-06 01:02:56 +00:00
|
|
|
int add_project(char* master_url, char* authenticator);
|
2003-05-14 21:17:58 +00:00
|
|
|
int reset_project(PROJECT*);
|
|
|
|
int detach_project(PROJECT*);
|
2003-05-13 18:55:07 +00:00
|
|
|
//int change_project(int index, char* master_url, char* authenticator);
|
2003-05-14 21:17:58 +00:00
|
|
|
//int quit_project(PROJECT*);
|
2002-07-15 05:34:32 +00:00
|
|
|
private:
|
|
|
|
PROJECT* find_project_with_overdue_results();
|
|
|
|
bool some_project_rpc_ok();
|
|
|
|
bool scheduler_rpc_poll();
|
|
|
|
void update_avg_cpu(PROJECT*);
|
2002-06-06 23:43:05 +00:00
|
|
|
double estimate_duration(WORKUNIT*);
|
2003-02-26 00:47:57 +00:00
|
|
|
double current_work_buf_days();
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// the following could be eliminated by using map instead of vector
|
|
|
|
//
|
|
|
|
public:
|
|
|
|
PROJECT* lookup_project(char*);
|
|
|
|
APP* lookup_app(PROJECT*, char*);
|
|
|
|
FILE_INFO* lookup_file_info(PROJECT*, char* name);
|
|
|
|
RESULT* lookup_result(PROJECT*, char*);
|
|
|
|
WORKUNIT* lookup_workunit(PROJECT*, char*);
|
|
|
|
APP_VERSION* lookup_app_version(APP*, int);
|
2002-11-19 22:57:05 +00:00
|
|
|
ACTIVE_TASK* lookup_active_task_by_result(RESULT*);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CLIENT_STATE gstate;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
2003-06-03 23:23:05 +00:00
|
|
|
extern void msg_printf(PROJECT *p, int priority, char *fmt, ...);
|
2003-06-03 22:47:15 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
#endif
|