2003-07-01 20:37:09 +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-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-07-03 00:48:43 +00:00
|
|
|
//
|
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
|
2003-07-03 00:48:43 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-07-03 00:48:43 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// If you change anything, make sure you also change:
|
|
|
|
// types.C (to write and parse it)
|
|
|
|
// client_state.C (to cross-link objects)
|
|
|
|
//
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
#ifndef _CLIENT_TYPES_
|
|
|
|
#define _CLIENT_TYPES_
|
2002-08-22 20:23:24 +00:00
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <stdio.h>
|
2003-07-03 05:01:29 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2004-04-18 18:40:13 +00:00
|
|
|
#include "md5_file.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "hostinfo.h"
|
2004-06-12 04:45:36 +00:00
|
|
|
#include "miofile.h"
|
2003-06-11 18:38:08 +00:00
|
|
|
#include "result_state.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-02-11 00:52:44 +00:00
|
|
|
#define MAX_BLOB_LEN 4096
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-07 22:52:10 +00:00
|
|
|
class PERS_FILE_XFER;
|
2003-11-02 22:51:49 +00:00
|
|
|
class PROJECT;
|
2002-07-22 23:07:14 +00:00
|
|
|
struct RESULT;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-06-10 06:14:18 +00:00
|
|
|
struct STRING256 {
|
|
|
|
char text[256];
|
|
|
|
};
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
// If the status is neither of these two,
|
|
|
|
// it will be an error code defined in error_numbers.h,
|
2004-03-25 22:24:33 +00:00
|
|
|
// indicating an unrecoverable error in the upload or download of the file,
|
|
|
|
// or that the file was too big and was deleted
|
2003-11-02 22:51:49 +00:00
|
|
|
//
|
|
|
|
#define FILE_NOT_PRESENT 0
|
|
|
|
#define FILE_PRESENT 1
|
|
|
|
|
|
|
|
class FILE_INFO {
|
|
|
|
public:
|
|
|
|
char name[256];
|
|
|
|
char md5_cksum[33];
|
|
|
|
double max_nbytes;
|
|
|
|
double nbytes;
|
|
|
|
double upload_offset;
|
|
|
|
bool generated_locally; // file is produced by app
|
|
|
|
int status;
|
|
|
|
bool executable; // change file protections to make executable
|
|
|
|
bool uploaded; // file has been uploaded
|
|
|
|
bool upload_when_present;
|
|
|
|
bool sticky; // don't delete unless instructed to do so
|
|
|
|
bool signature_required; // true iff associated with app version
|
|
|
|
bool is_user_file;
|
|
|
|
PERS_FILE_XFER* pers_file_xfer; // nonzero if in the process of being up/downloaded
|
|
|
|
RESULT* result; // for upload files (to authenticate)
|
|
|
|
PROJECT* project;
|
|
|
|
int ref_cnt;
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<STRING256> urls;
|
2003-11-02 22:51:49 +00:00
|
|
|
int start_url;
|
|
|
|
int current_url;
|
|
|
|
char signed_xml[MAX_BLOB_LEN];
|
|
|
|
char xml_signature[MAX_BLOB_LEN];
|
|
|
|
char file_signature[MAX_BLOB_LEN];
|
2004-06-30 18:17:21 +00:00
|
|
|
std::string error_msg; // if permanent error occurs during file xfer,
|
2003-11-02 22:51:49 +00:00
|
|
|
// it's recorded here
|
|
|
|
|
|
|
|
FILE_INFO();
|
|
|
|
~FILE_INFO();
|
|
|
|
int set_permissions();
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&, bool from_server);
|
|
|
|
int write(MIOFILE&, bool to_server);
|
2003-11-02 22:51:49 +00:00
|
|
|
int delete_file(); // attempt to delete the underlying file
|
2004-07-06 17:37:58 +00:00
|
|
|
char* get_init_url(bool);
|
2004-07-06 18:31:56 +00:00
|
|
|
char* get_next_url(bool);
|
|
|
|
char* get_current_url(bool);
|
|
|
|
bool is_correct_url_type(bool, STRING256);
|
2003-11-02 22:51:49 +00:00
|
|
|
bool had_failure(int& failnum);
|
2004-03-24 23:33:46 +00:00
|
|
|
bool verify_existing_file();
|
2004-07-06 18:31:56 +00:00
|
|
|
int merge_info(FILE_INFO&);
|
2003-11-02 22:51:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Describes a connection between a file and a workunit, result, or application.
|
|
|
|
// In the first two cases,
|
|
|
|
// the app will either use open() or fopen() to access the file
|
|
|
|
// (in which case "open_name" is the name it will use)
|
|
|
|
// or the app will be connected by the given fd (in which case fd is nonzero)
|
|
|
|
//
|
|
|
|
struct FILE_REF {
|
|
|
|
char file_name[256];
|
|
|
|
char open_name[256];
|
|
|
|
int fd;
|
|
|
|
bool main_program;
|
|
|
|
FILE_INFO* file_info;
|
2004-07-06 18:31:56 +00:00
|
|
|
bool copy_file; // if true, core client will copy the file instead of linking
|
2003-11-02 22:51:49 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&);
|
|
|
|
int write(MIOFILE&);
|
2003-11-02 22:51:49 +00:00
|
|
|
};
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
class PROJECT {
|
|
|
|
public:
|
2003-02-28 23:14:18 +00:00
|
|
|
// the following items come from the account file
|
2002-06-21 06:52:47 +00:00
|
|
|
// They are a function only of the user and the project
|
|
|
|
//
|
2002-07-15 23:37:55 +00:00
|
|
|
char master_url[256]; // url of site that contains scheduler tags
|
|
|
|
// for this project
|
2002-04-30 22:22:54 +00:00
|
|
|
char authenticator[256]; // user's authenticator on this project
|
2004-06-30 18:17:21 +00:00
|
|
|
std::string project_prefs;
|
2003-11-28 19:19:11 +00:00
|
|
|
// without the enclosing <project_preferences> tags.
|
|
|
|
// May include <venue> elements
|
|
|
|
// This field is used only briefly: between handling a
|
|
|
|
// scheduler RPC reply and writing the account file
|
2004-06-30 18:17:21 +00:00
|
|
|
std::string project_specific_prefs;
|
2003-11-28 19:19:11 +00:00
|
|
|
// without enclosing <project_specific> tags
|
|
|
|
// Does not include <venue> elements
|
|
|
|
double resource_share;
|
|
|
|
// project's resource share relative to other projects.
|
2002-06-21 06:52:47 +00:00
|
|
|
|
|
|
|
// the following items come from client_state.xml
|
|
|
|
// They may depend on the host as well as user and project
|
2003-05-13 18:55:07 +00:00
|
|
|
// NOTE: if you add anything, add it to copy_state_fields() also!!!
|
2002-06-21 06:52:47 +00:00
|
|
|
//
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<STRING256> scheduler_urls; // where to find scheduling servers
|
2002-06-21 06:52:47 +00:00
|
|
|
char project_name[256]; // descriptive. not unique
|
|
|
|
char user_name[256];
|
2003-02-24 21:25:16 +00:00
|
|
|
char team_name[256];
|
2004-04-18 18:40:13 +00:00
|
|
|
char email_hash[MD5_LEN];
|
|
|
|
char cross_project_id[MD5_LEN];
|
2002-11-19 22:57:05 +00:00
|
|
|
double user_total_credit; // as reported by server
|
|
|
|
double user_expavg_credit; // as reported by server
|
2002-10-22 21:44:16 +00:00
|
|
|
unsigned int user_create_time; // as reported by server
|
2002-04-30 22:22:54 +00:00
|
|
|
int rpc_seqno;
|
|
|
|
int hostid;
|
2002-10-22 21:44:16 +00:00
|
|
|
double host_total_credit; // as reported by server
|
|
|
|
double host_expavg_credit; // as reported by server
|
2003-07-03 00:48:43 +00:00
|
|
|
unsigned int host_create_time; // as reported by server
|
2004-04-07 07:21:35 +00:00
|
|
|
double exp_avg_cpu; // exponentially weighted CPU time
|
|
|
|
double exp_avg_mod_time; // last time average was changed
|
2002-07-15 05:34:32 +00:00
|
|
|
int nrpc_failures; // # of consecutive times we've failed to
|
|
|
|
// contact all scheduling servers
|
2003-02-28 23:14:18 +00:00
|
|
|
int master_fetch_failures;
|
2003-07-03 00:48:43 +00:00
|
|
|
time_t min_rpc_time; // earliest time to contact any server
|
|
|
|
// of this project (or zero)
|
|
|
|
time_t min_report_min_rpc_time; // when to next report on min_rpc_time
|
|
|
|
// (or zero)
|
2002-07-15 05:34:32 +00:00
|
|
|
bool master_url_fetch_pending;
|
|
|
|
// need to fetch and parse the master URL
|
2003-05-13 18:55:07 +00:00
|
|
|
bool sched_rpc_pending; // contact scheduling server for preferences
|
|
|
|
bool tentative; // master URL and account ID not confirmed
|
2004-07-06 18:31:56 +00:00
|
|
|
bool anonymous_platform; // app_versions.xml file found in project dir;
|
|
|
|
// use those apps rather then getting from server
|
|
|
|
bool send_file_list;
|
|
|
|
// send the list of permanent files associated with the
|
|
|
|
// project in the next scheduler reply for the project
|
2003-02-28 23:14:18 +00:00
|
|
|
char code_sign_key[MAX_BLOB_LEN];
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<FILE_REF> user_files;
|
2003-11-02 22:51:49 +00:00
|
|
|
int parse_preferences_for_user_files();
|
2004-06-30 01:10:22 +00:00
|
|
|
|
|
|
|
// the following fields used by CPU scheduler
|
|
|
|
double debt; // how much CPU time we owe this project (secs)
|
2003-02-28 23:14:18 +00:00
|
|
|
// the following items are transient; not saved in state file
|
2004-06-30 01:10:22 +00:00
|
|
|
double anticipated_debt; // expected debt by the end of the preemption period
|
|
|
|
double work_done_this_period; // how much CPU time has been devoted to this
|
|
|
|
// project in the current period (secs)
|
|
|
|
RESULT *next_runnable_result; // the next result to run for this project
|
2004-07-06 18:31:56 +00:00
|
|
|
|
|
|
|
// the following used by work-fetch algorithm
|
2004-06-30 01:10:22 +00:00
|
|
|
double work_request; // how much work a project needs (secs)
|
|
|
|
// the following soon to be deprecated
|
2003-02-28 23:14:18 +00:00
|
|
|
double resource_debt; // How much CPU time we owe this project
|
|
|
|
// (arbitrary scale)
|
|
|
|
int debt_order; // 0 == largest debt
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
PROJECT();
|
|
|
|
~PROJECT();
|
2003-06-23 22:05:14 +00:00
|
|
|
void init();
|
2002-06-21 06:52:47 +00:00
|
|
|
void copy_state_fields(PROJECT&);
|
2003-05-08 23:28:01 +00:00
|
|
|
char *get_project_name();
|
2003-05-13 18:55:07 +00:00
|
|
|
int write_account_file();
|
2002-09-26 05:57:10 +00:00
|
|
|
int parse_account(FILE*);
|
2003-11-02 22:51:49 +00:00
|
|
|
int parse_account_file();
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse_state(MIOFILE&);
|
|
|
|
int write_state(MIOFILE&);
|
2003-07-03 00:48:43 +00:00
|
|
|
|
|
|
|
// set min_rpc_time and have_reported_min_rpc_time
|
|
|
|
void set_min_rpc_time(time_t future_time);
|
|
|
|
// returns true if min_rpc_time > now; may print a message
|
|
|
|
bool waiting_until_min_rpc_time(time_t now);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct APP {
|
|
|
|
char name[256];
|
|
|
|
PROJECT* project;
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&);
|
|
|
|
int write(MIOFILE&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
struct APP_VERSION {
|
|
|
|
char app_name[256];
|
|
|
|
int version_num;
|
|
|
|
APP* app;
|
|
|
|
PROJECT* project;
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<FILE_REF> app_files;
|
2003-03-02 19:24:09 +00:00
|
|
|
int ref_cnt;
|
2002-05-17 22:33:57 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&);
|
|
|
|
int write(MIOFILE&);
|
2002-05-17 22:33:57 +00:00
|
|
|
};
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
struct WORKUNIT {
|
|
|
|
char name[256];
|
|
|
|
char app_name[256];
|
|
|
|
int version_num;
|
|
|
|
// This isn't sent from the server.
|
2002-07-29 00:39:45 +00:00
|
|
|
// Instead, the client picks the latest app version
|
2002-04-30 22:22:54 +00:00
|
|
|
char command_line[256];
|
|
|
|
char env_vars[256]; // environment vars in URL format
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<FILE_REF> input_files;
|
2002-04-30 22:22:54 +00:00
|
|
|
PROJECT* project;
|
|
|
|
APP* app;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
int ref_cnt;
|
2003-09-04 00:41:51 +00:00
|
|
|
double rsc_fpops_est;
|
|
|
|
double rsc_fpops_bound;
|
|
|
|
double rsc_memory_bound;
|
|
|
|
double rsc_disk_bound;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&);
|
|
|
|
int write(MIOFILE&);
|
2002-12-05 21:35:51 +00:00
|
|
|
bool had_failure(int& failnum);
|
2004-06-30 18:17:21 +00:00
|
|
|
void get_file_errors(std::string&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RESULT {
|
|
|
|
char name[256];
|
|
|
|
char wu_name[256];
|
2002-07-15 05:34:32 +00:00
|
|
|
int report_deadline;
|
2004-06-30 18:17:21 +00:00
|
|
|
std::vector<FILE_REF> output_files;
|
2004-06-30 01:10:22 +00:00
|
|
|
bool is_active;
|
|
|
|
// an app is currently running for this.
|
|
|
|
// this is false for preempted tasks!
|
2003-09-23 23:19:41 +00:00
|
|
|
bool ready_to_report;
|
|
|
|
// we're ready to report this result to the server;
|
|
|
|
// either computation is done and all the files have been uploaded
|
|
|
|
// or there was an error
|
|
|
|
bool got_server_ack;
|
|
|
|
// we're received the ack for this result from the server
|
2002-08-05 00:29:34 +00:00
|
|
|
double final_cpu_time;
|
2003-10-01 04:31:05 +00:00
|
|
|
int state; // state of this result, see lib/result_state.h
|
2002-08-12 21:54:19 +00:00
|
|
|
int exit_status; // return value from the application
|
2003-02-06 01:02:56 +00:00
|
|
|
int signal; // the signal caught by the active_task,
|
2003-01-07 01:02:08 +00:00
|
|
|
// defined only if active_task_state is PROCESS_SIGNALED
|
2002-12-05 21:35:51 +00:00
|
|
|
int active_task_state; // the state of the active task corresponding to this result
|
2004-06-30 18:17:21 +00:00
|
|
|
std::string stderr_out;
|
2003-12-30 23:14:34 +00:00
|
|
|
// the concatenation of:
|
|
|
|
//
|
|
|
|
// - if report_result_error() is called for this result:
|
|
|
|
// <message>x</message>
|
|
|
|
// <active_task_state>x</active_task_state>
|
|
|
|
// <exit_status>x</exit_status>
|
|
|
|
// <signal>x</signal>
|
|
|
|
// - if called in FILES_DOWNLOADED state:
|
|
|
|
// <couldnt_start>x</couldnt_start>
|
|
|
|
// - if called in NEW state:
|
|
|
|
// <download_error>x</download_error> for each failed download
|
|
|
|
// - if called in COMPUTE_DONE state:
|
|
|
|
// <upload_error>x</upload_error> for each failed upload
|
|
|
|
//
|
|
|
|
// - <stderr_txt>X</stderr_txt>, where X is the app's stderr output
|
2003-07-03 00:48:43 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
APP* app;
|
|
|
|
WORKUNIT* wup;
|
2003-09-23 23:19:41 +00:00
|
|
|
// this may be NULL after result is finished
|
2002-04-30 22:22:54 +00:00
|
|
|
PROJECT* project;
|
|
|
|
|
2004-06-30 01:10:22 +00:00
|
|
|
bool already_selected;
|
|
|
|
// used to keep cpu scheduler from scheduling a result twice
|
|
|
|
// (transient)
|
2002-07-05 05:33:40 +00:00
|
|
|
void clear();
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse_server(MIOFILE&);
|
|
|
|
int parse_state(MIOFILE&);
|
2002-07-05 05:33:40 +00:00
|
|
|
int parse_ack(FILE*);
|
2004-06-12 04:45:36 +00:00
|
|
|
int write(MIOFILE&, bool to_server);
|
2002-04-30 22:22:54 +00:00
|
|
|
bool is_upload_done(); // files uploaded?
|
2004-06-30 18:17:21 +00:00
|
|
|
void get_app_version_string(std::string&);
|
2004-07-06 18:31:56 +00:00
|
|
|
void reset_result_files();
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2002-08-07 22:52:10 +00:00
|
|
|
int verify_downloaded_file(char* pathname, FILE_INFO& file_info);
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#endif
|