2004-12-05 21:53:32 +00:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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
|
2003-06-11 23:36:50 +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-06-11 23:36:50 +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.
|
2003-06-11 23:36:48 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-06-11 23:36:50 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-12-03 18:57:40 +00:00
|
|
|
// Handle a scheduling server RPC
|
|
|
|
|
2004-08-03 21:51:30 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
2002-09-26 23:12:13 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2004-08-03 21:51:30 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <cmath>
|
2002-09-26 23:12:13 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "backend_lib.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-04-03 18:35:40 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "server_types.h"
|
2003-06-11 23:36:40 +00:00
|
|
|
#include "sched_util.h"
|
2002-10-04 20:35:56 +00:00
|
|
|
#include "main.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "handle_request.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2004-04-04 01:59:47 +00:00
|
|
|
#include "sched_send.h"
|
2004-08-05 22:14:23 +00:00
|
|
|
#include "sched_config.h"
|
2003-08-09 00:11:32 +00:00
|
|
|
|
2004-07-03 21:38:22 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// Look up the host and its user, and make sure the authenticator matches.
|
|
|
|
// If no host ID is supplied, or if RPC seqno mismatch,
|
|
|
|
// create a new host record and return its ID
|
|
|
|
//
|
2004-09-27 19:44:40 +00:00
|
|
|
// POSTCONDITION:
|
|
|
|
// If this returns zero, then:
|
|
|
|
// - reply.host contains a valid host record (possibly new)
|
|
|
|
// - reply.user contains a valid user record
|
|
|
|
// - if user has team, reply.team contains team record
|
|
|
|
//
|
2002-08-26 22:57:17 +00:00
|
|
|
int authenticate_user(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2003-01-17 18:51:39 +00:00
|
|
|
char buf[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
if (sreq.hostid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.lookup_id(sreq.hostid);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message, "Can't find host record");
|
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d?] can't find host\n",
|
|
|
|
sreq.hostid
|
|
|
|
);
|
2003-04-30 22:08:16 +00:00
|
|
|
sreq.hostid = 0;
|
2004-01-08 00:40:53 +00:00
|
|
|
goto lookup_user_and_make_new_host;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.host = host;
|
|
|
|
|
|
|
|
retval = user.lookup_id(reply.host.userid);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2004-01-08 00:40:53 +00:00
|
|
|
// this should never happen - means inconsistent DB
|
|
|
|
//
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message, "Can't find user record");
|
|
|
|
strcpy(reply.message_priority, "low");
|
2004-07-03 19:42:59 +00:00
|
|
|
reply.request_delay = 3600;
|
2003-04-30 22:02:53 +00:00
|
|
|
reply.nucleus_only = true;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [USER#%d?] can't find user record\n",
|
|
|
|
host.id, reply.host.userid
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.user = user;
|
2002-08-26 22:57:17 +00:00
|
|
|
if (strcmp(sreq.authenticator, reply.user.authenticator)) {
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message,
|
2004-12-06 22:41:19 +00:00
|
|
|
"Invalid or missing account key. "
|
|
|
|
"Visit this project's web site to get an account key."
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2004-07-03 19:42:59 +00:00
|
|
|
reply.request_delay = 3600;
|
2003-04-30 22:02:53 +00:00
|
|
|
reply.nucleus_only = true;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [USER#%d] Bad authenticator '%s'\n",
|
|
|
|
host.id, user.id, sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the seqno from the host is less than what we expect,
|
|
|
|
// the user must have copied the state file to a different host.
|
|
|
|
// Make a new host record.
|
2004-05-03 02:18:35 +00:00
|
|
|
//
|
2002-08-26 22:57:17 +00:00
|
|
|
if (sreq.rpc_seqno < reply.host.rpc_seqno) {
|
2002-04-30 22:22:54 +00:00
|
|
|
sreq.hostid = 0;
|
2004-01-08 00:09:26 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2004-01-08 00:09:26 +00:00
|
|
|
"[HOST#%d] [USER#%d] RPC seqno %d less than expected %d; creating new host\n",
|
|
|
|
reply.host.id, user.id, sreq.rpc_seqno, reply.host.rpc_seqno
|
|
|
|
);
|
2004-01-08 00:40:53 +00:00
|
|
|
goto make_new_host;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-08-26 22:57:17 +00:00
|
|
|
reply.host.rpc_seqno = sreq.rpc_seqno;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2004-01-08 00:40:53 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
// here no hostid was given; we'll have to create a new host record
|
|
|
|
//
|
2004-01-08 00:40:53 +00:00
|
|
|
lookup_user_and_make_new_host:
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(
|
2003-06-04 17:21:26 +00:00
|
|
|
user.authenticator, sreq.authenticator,
|
|
|
|
sizeof(user.authenticator)
|
2002-09-22 23:27:14 +00:00
|
|
|
);
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where authenticator='%s'", user.authenticator);
|
|
|
|
retval = user.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-10-15 07:41:33 +00:00
|
|
|
strcpy(reply.message,
|
2004-12-06 22:41:19 +00:00
|
|
|
"Invalid or missing account key. "
|
|
|
|
"Visit this project's web site to get an account key."
|
2003-03-02 19:24:09 +00:00
|
|
|
);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2004-07-03 19:42:59 +00:00
|
|
|
reply.request_delay = 3600;
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#<none>] Bad authenticator '%s'\n",
|
|
|
|
sreq.authenticator
|
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_AUTHENTICATOR;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
reply.user = user;
|
2004-01-08 00:40:53 +00:00
|
|
|
make_new_host:
|
2002-08-28 21:50:51 +00:00
|
|
|
// reply.user is filled in and valid at this point
|
|
|
|
//
|
2003-06-04 17:21:26 +00:00
|
|
|
host = sreq.host;
|
|
|
|
host.id = 0;
|
|
|
|
host.create_time = time(0);
|
|
|
|
host.userid = reply.user.id;
|
|
|
|
host.rpc_seqno = 0;
|
|
|
|
strcpy(host.venue, reply.user.venue);
|
2004-01-19 01:12:53 +00:00
|
|
|
host.fix_nans();
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.insert();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2004-01-19 01:12:53 +00:00
|
|
|
strcpy(reply.message, "Couldn't create host record in database");
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2003-09-05 21:26:21 +00:00
|
|
|
boinc_db.print_error("host.insert()");
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "host.insert() failed\n");
|
2003-10-21 04:06:55 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-09-05 21:26:21 +00:00
|
|
|
host.id = boinc_db.insert_id();
|
2003-06-04 17:21:26 +00:00
|
|
|
|
|
|
|
reply.host = host;
|
2002-08-28 21:50:51 +00:00
|
|
|
reply.hostid = reply.host.id;
|
|
|
|
// this tells client to updates its host ID
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
|
|
|
|
// have user record in reply.user at this point
|
|
|
|
//
|
|
|
|
|
2003-02-24 21:31:36 +00:00
|
|
|
if (reply.user.teamid) {
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = team.lookup_id(reply.user.teamid);
|
2003-02-24 21:31:36 +00:00
|
|
|
if (!retval) reply.team = team;
|
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
|
|
|
|
// compute email hash
|
|
|
|
//
|
|
|
|
md5_block(
|
|
|
|
(unsigned char*)reply.user.email_addr,
|
|
|
|
strlen(reply.user.email_addr),
|
|
|
|
reply.email_hash
|
|
|
|
);
|
|
|
|
|
2004-08-27 22:46:12 +00:00
|
|
|
// see if new cross-project ID (i.e., greater than the one we have)
|
2004-05-03 02:18:35 +00:00
|
|
|
//
|
|
|
|
if (strlen(sreq.cross_project_id)) {
|
2004-08-27 22:46:12 +00:00
|
|
|
if (strcmp(sreq.cross_project_id, reply.user.cross_project_id) > 0) {
|
2004-05-03 02:18:35 +00:00
|
|
|
strcpy(reply.user.cross_project_id, sreq.cross_project_id);
|
|
|
|
reply.update_user_record = true;
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// somewhat arbitrary formula for credit as a function of CPU time.
|
|
|
|
// Could also include terms for RAM size, network speed etc.
|
|
|
|
//
|
2004-05-26 23:34:27 +00:00
|
|
|
static void compute_credit_rating(HOST& host, SCHEDULER_REQUEST& sreq) {
|
2004-08-21 17:35:02 +00:00
|
|
|
double cobblestone_factor = 100;
|
2003-06-11 23:36:45 +00:00
|
|
|
host.credit_per_cpu_sec =
|
2004-05-19 20:53:00 +00:00
|
|
|
(fabs(host.p_fpops)/1e9 + fabs(host.p_iops)/1e9)
|
2004-05-26 23:34:27 +00:00
|
|
|
* cobblestone_factor / (2 * SECONDS_PER_DAY);
|
2002-09-26 05:57:10 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 18:13:00 +00:00
|
|
|
// modify host struct based on request.
|
2002-04-30 22:22:54 +00:00
|
|
|
// Copy all fields that are determined by the client.
|
|
|
|
//
|
2004-05-30 21:47:11 +00:00
|
|
|
static int modify_host_struct(SCHEDULER_REQUEST& sreq, HOST& host) {
|
2002-04-30 22:22:54 +00:00
|
|
|
host.timezone = sreq.host.timezone;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.domain_name, sreq.host.domain_name, sizeof(host.domain_name));
|
|
|
|
strncpy(host.serialnum, sreq.host.serialnum, sizeof(host.serialnum));
|
2002-04-30 22:22:54 +00:00
|
|
|
if (strcmp(host.last_ip_addr, sreq.host.last_ip_addr)) {
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.last_ip_addr, sreq.host.last_ip_addr, sizeof(host.last_ip_addr));
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
host.nsame_ip_addr++;
|
|
|
|
}
|
|
|
|
host.on_frac = sreq.host.on_frac;
|
|
|
|
host.connected_frac = sreq.host.connected_frac;
|
|
|
|
host.active_frac = sreq.host.active_frac;
|
|
|
|
host.p_ncpus = sreq.host.p_ncpus;
|
2003-03-02 19:24:09 +00:00
|
|
|
strncpy(host.p_vendor, sreq.host.p_vendor, sizeof(host.p_vendor));
|
|
|
|
// unlikely this will change
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.p_model, sreq.host.p_model, sizeof(host.p_model));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.p_fpops = sreq.host.p_fpops;
|
|
|
|
host.p_iops = sreq.host.p_iops;
|
|
|
|
host.p_membw = sreq.host.p_membw;
|
2002-06-21 18:31:32 +00:00
|
|
|
host.p_calculated = sreq.host.p_calculated;
|
2002-09-22 23:27:14 +00:00
|
|
|
strncpy(host.os_name, sreq.host.os_name, sizeof(host.os_name));
|
|
|
|
strncpy(host.os_version, sreq.host.os_version, sizeof(host.os_version));
|
2002-04-30 22:22:54 +00:00
|
|
|
host.m_nbytes = sreq.host.m_nbytes;
|
|
|
|
host.m_cache = sreq.host.m_cache;
|
|
|
|
host.m_swap = sreq.host.m_swap;
|
|
|
|
host.d_total = sreq.host.d_total;
|
|
|
|
host.d_free = sreq.host.d_free;
|
|
|
|
host.n_bwup = sreq.host.n_bwup;
|
|
|
|
host.n_bwdown = sreq.host.n_bwdown;
|
2004-01-19 01:12:53 +00:00
|
|
|
host.fix_nans();
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2004-05-26 23:34:27 +00:00
|
|
|
compute_credit_rating(host, sreq);
|
2004-05-27 18:13:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2004-05-27 18:13:00 +00:00
|
|
|
static int update_host_record(HOST& xhost) {
|
|
|
|
DB_HOST host;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
host = xhost;
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.update();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "host.update() failed: %d\n", retval);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-23 03:59:32 +00:00
|
|
|
// Decide which global prefs to use,
|
|
|
|
// (from request msg, or if absent then from user record)
|
|
|
|
// and parse them into the request message global_prefs field.
|
|
|
|
// Decide whether to send global prefs in reply msg
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2002-09-27 20:36:03 +00:00
|
|
|
int handle_global_prefs(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2002-09-29 00:32:11 +00:00
|
|
|
reply.send_global_prefs = false;
|
2004-03-23 03:59:32 +00:00
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(sreq.global_prefs_xml)) {
|
2003-07-26 01:35:48 +00:00
|
|
|
unsigned req_mod_time=0, db_mod_time=0;
|
2004-05-03 02:18:35 +00:00
|
|
|
bool same_account = !strcmp(
|
|
|
|
sreq.global_prefs_source_email_hash, reply.email_hash
|
|
|
|
);
|
|
|
|
bool update_prefs = false;
|
|
|
|
|
2003-07-26 01:35:48 +00:00
|
|
|
parse_int(sreq.global_prefs_xml, "<mod_time>", (int&)req_mod_time);
|
2002-09-29 00:32:11 +00:00
|
|
|
if (strlen(reply.user.global_prefs)) {
|
2003-07-26 01:35:48 +00:00
|
|
|
parse_int(reply.user.global_prefs, "<mod_time>", (int&)db_mod_time);
|
2004-03-23 03:59:32 +00:00
|
|
|
|
|
|
|
// if user record has more recent prefs,
|
|
|
|
// use them and arrange to return in reply msg
|
|
|
|
//
|
|
|
|
if (req_mod_time < db_mod_time) {
|
|
|
|
strcpy(sreq.global_prefs_xml, reply.user.global_prefs);
|
2002-09-29 00:32:11 +00:00
|
|
|
reply.send_global_prefs = true;
|
2004-05-03 02:18:35 +00:00
|
|
|
} else {
|
|
|
|
if (same_account) update_prefs = true;
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
2004-05-03 02:18:35 +00:00
|
|
|
} else {
|
|
|
|
if (same_account) update_prefs = true;
|
|
|
|
}
|
|
|
|
if (update_prefs) {
|
|
|
|
strcpy(reply.user.global_prefs, sreq.global_prefs_xml);
|
|
|
|
reply.update_user_record = true;
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-03-23 03:59:32 +00:00
|
|
|
// request message has no global prefs;
|
|
|
|
// copy from user record, and send them in reply
|
|
|
|
//
|
2002-09-29 00:32:11 +00:00
|
|
|
if (strlen(reply.user.global_prefs)) {
|
2004-03-23 03:59:32 +00:00
|
|
|
strcpy(sreq.global_prefs_xml, reply.user.global_prefs);
|
2002-09-29 00:32:11 +00:00
|
|
|
reply.send_global_prefs = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-03 22:52:10 +00:00
|
|
|
sreq.global_prefs.parse(sreq.global_prefs_xml, reply.host.venue);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-06 21:44:59 +00:00
|
|
|
|
2004-08-05 22:14:23 +00:00
|
|
|
// New handle completed results
|
|
|
|
//
|
2002-09-26 05:57:10 +00:00
|
|
|
int handle_results(
|
2004-05-30 21:47:11 +00:00
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
|
2002-09-26 05:57:10 +00:00
|
|
|
) {
|
2004-07-06 18:30:22 +00:00
|
|
|
DB_SCHED_RESULT_ITEM_SET result_handler;
|
2004-07-27 22:42:06 +00:00
|
|
|
SCHED_RESULT_ITEM* srip;
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
RESULT* rp;
|
2004-12-05 21:53:32 +00:00
|
|
|
|
2004-07-21 23:48:56 +00:00
|
|
|
if (sreq.results.size() == 0) return 0;
|
2004-12-05 21:53:32 +00:00
|
|
|
|
2004-07-21 23:48:56 +00:00
|
|
|
// read all results the user is reporting
|
2004-07-06 18:30:22 +00:00
|
|
|
//
|
2004-07-21 23:48:56 +00:00
|
|
|
for (i=0; i<sreq.results.size(); i++) {
|
|
|
|
result_handler.add_result(sreq.results[i].name);
|
|
|
|
}
|
2004-12-05 21:53:32 +00:00
|
|
|
|
|
|
|
// read all results with the same name from the database into
|
|
|
|
// memory
|
|
|
|
//
|
2004-07-21 23:48:56 +00:00
|
|
|
retval = result_handler.enumerate();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[HOST#%d] Batch query failed\n",
|
|
|
|
reply.host.id
|
|
|
|
);
|
2004-07-06 18:30:22 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-12-05 21:53:32 +00:00
|
|
|
|
|
|
|
// loop over all results that came back from the host
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sreq.results.size(); i++) {
|
2004-12-05 21:53:32 +00:00
|
|
|
|
|
|
|
// a pointer to the current result from the host
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
rp = &sreq.results[i];
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2002-10-09 04:56:41 +00:00
|
|
|
// acknowledge the result even if we couldn't find it --
|
|
|
|
// don't want it to keep coming back
|
|
|
|
//
|
|
|
|
reply.result_acks.push_back(*rp);
|
|
|
|
|
2004-12-05 21:53:32 +00:00
|
|
|
// get the result with the same name that came back from the
|
|
|
|
// database and point srip to it. Quantities that MUST be
|
|
|
|
// read from the DB are those where srip appears as an rval.
|
|
|
|
// These are: id, name, server_state, received_time, hostid.
|
|
|
|
// // Quantities that must be WRITTEN to the DB are those for
|
|
|
|
// which srip appears as an lval. These are:
|
|
|
|
// hostid,
|
|
|
|
// teamid, received_time, client_state, cpu_time, exit_status,
|
|
|
|
// app_version_num, claimed_credit, server_state, stderr_out,
|
|
|
|
// xml_doc_out, outcome, validate_state
|
|
|
|
|
2004-07-27 23:29:27 +00:00
|
|
|
retval = result_handler.lookup_result(rp->name, &srip);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [RESULT#? %s] can't find result\n",
|
2004-05-30 21:47:11 +00:00
|
|
|
reply.host.id, rp->name
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2004-12-05 21:53:32 +00:00
|
|
|
// no need to skip when updating DB, since it's not there!
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-23 08:07:48 +00:00
|
|
|
|
2003-06-15 00:09:05 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL, "[HOST#%d] [RESULT#%d %s] got result\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name
|
2003-06-15 00:09:05 +00:00
|
|
|
);
|
|
|
|
|
2004-12-05 21:53:32 +00:00
|
|
|
// Comment -- In the sanity checks that follow, should we
|
|
|
|
// verify that the results validate_state is consistent with
|
|
|
|
// this being a newly arrived result? What happens if a
|
|
|
|
// workunit was canceled after a result was sent? When it
|
|
|
|
// gets back in, do we want to leave the validate state 'as
|
|
|
|
// is'? Probably yes, which is as the code currently behaves.
|
2004-07-27 22:42:06 +00:00
|
|
|
if (srip->server_state == RESULT_SERVER_STATE_UNSENT) {
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-06-14 17:46:08 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got unexpected result: server state is %d\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, srip->server_state
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2004-12-05 21:53:32 +00:00
|
|
|
srip->id=0; // mark to skip when updating DB
|
2003-01-07 22:49:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-13 00:37:00 +00:00
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if (srip->received_time) {
|
2004-01-08 00:51:13 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2004-01-08 00:51:13 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got result twice\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name
|
2004-01-08 00:51:13 +00:00
|
|
|
);
|
2004-12-05 21:53:32 +00:00
|
|
|
srip->id=0; // mark to skip when updating DB
|
2004-01-08 00:51:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if (srip->hostid != sreq.hostid) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] got result from wrong host; expected [HOST#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, srip->hostid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
DB_HOST result_host;
|
2004-07-27 22:42:06 +00:00
|
|
|
int retval = result_host.lookup_id(srip->hostid);
|
2003-06-14 17:46:09 +00:00
|
|
|
|
|
|
|
if (retval) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[RESULT#%d %s] Can't lookup [HOST#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name, srip->hostid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2004-12-05 21:53:32 +00:00
|
|
|
srip->id=0; // mark to skip when updating DB
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
2004-05-30 21:47:11 +00:00
|
|
|
} else if (result_host.userid != reply.host.userid) {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[USER#%d] [HOST#%d] [RESULT#%d %s] Not even the same user; expected [USER#%d]\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.userid, reply.host.id, srip->id, srip->name, result_host.userid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2004-12-05 21:53:32 +00:00
|
|
|
srip->id=0; // mark to skip when updating DB
|
2003-06-14 17:46:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2003-08-02 00:40:44 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-02 00:40:44 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] Allowing result because same USER#%d\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
reply.host.id, srip->id, srip->name, reply.host.userid
|
2003-08-02 00:40:44 +00:00
|
|
|
);
|
2003-06-14 17:46:09 +00:00
|
|
|
}
|
2004-12-05 21:53:32 +00:00
|
|
|
} // hostids do not match
|
2002-09-22 23:27:14 +00:00
|
|
|
|
2004-12-05 21:53:32 +00:00
|
|
|
// modify the result record in the in-memory copy obtained
|
|
|
|
// from the DB earlier. If we found a problem above, we have
|
|
|
|
// continued and skipped this modify
|
2003-08-15 20:35:44 +00:00
|
|
|
//
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->hostid = reply.host.id;
|
|
|
|
srip->teamid = reply.user.teamid;
|
|
|
|
srip->received_time = time(0);
|
|
|
|
srip->client_state = rp->client_state;
|
|
|
|
srip->cpu_time = rp->cpu_time;
|
|
|
|
srip->exit_status = rp->exit_status;
|
|
|
|
srip->app_version_num = rp->app_version_num;
|
2004-12-05 21:53:32 +00:00
|
|
|
srip->claimed_credit = rp->cpu_time * reply.host.credit_per_cpu_sec;
|
2004-05-30 21:47:11 +00:00
|
|
|
#if 1
|
2004-05-28 20:36:17 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::DEBUG,
|
2004-07-27 22:42:06 +00:00
|
|
|
"cpu %f cpcs %f, cc %f\n", srip->cpu_time, reply.host.credit_per_cpu_sec, srip->claimed_credit
|
2004-05-28 20:36:17 +00:00
|
|
|
);
|
2004-05-30 21:47:11 +00:00
|
|
|
#endif
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->server_state = RESULT_SERVER_STATE_OVER;
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2004-11-29 22:26:34 +00:00
|
|
|
safe_strncpy(srip->stderr_out, rp->stderr_out, sizeof(srip->stderr_out));
|
|
|
|
safe_strncpy(srip->xml_doc_out, rp->xml_doc_out, sizeof(srip->xml_doc_out));
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2004-04-11 20:20:32 +00:00
|
|
|
// look for exit status and app version in stderr_out
|
2004-03-31 06:07:17 +00:00
|
|
|
// (historical - can be deleted at some point)
|
2004-01-22 01:35:09 +00:00
|
|
|
//
|
2004-07-27 22:42:06 +00:00
|
|
|
parse_int(srip->stderr_out, "<exit_status>", srip->exit_status);
|
|
|
|
parse_int(srip->stderr_out, "<app_version>", srip->app_version_num);
|
2004-01-22 01:35:09 +00:00
|
|
|
|
2004-07-27 22:42:06 +00:00
|
|
|
if ((srip->client_state == RESULT_FILES_UPLOADED) && (srip->exit_status == 0)) {
|
|
|
|
srip->outcome = RESULT_OUTCOME_SUCCESS;
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::DEBUG,
|
2004-02-15 18:34:10 +00:00
|
|
|
"[RESULT#%d %s]: setting outcome SUCCESS\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name
|
2004-02-15 18:34:10 +00:00
|
|
|
);
|
2004-01-30 22:25:33 +00:00
|
|
|
} else {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::DEBUG,
|
2004-02-15 18:34:10 +00:00
|
|
|
"[RESULT#%d %s]: client_state %d exit_status %d; setting outcome ERROR\n",
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->id, srip->name, srip->client_state, srip->exit_status
|
2004-02-15 18:34:10 +00:00
|
|
|
);
|
2004-07-27 22:42:06 +00:00
|
|
|
srip->outcome = RESULT_OUTCOME_CLIENT_ERROR;
|
|
|
|
srip->validate_state = VALIDATE_STATE_INVALID;
|
2004-01-30 22:25:33 +00:00
|
|
|
}
|
2004-12-05 21:53:32 +00:00
|
|
|
} // end of loop over all incoming results
|
2004-01-30 22:25:33 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-12-05 21:53:32 +00:00
|
|
|
// update all the results we have kept in memory, by storing to
|
|
|
|
// database.
|
2004-07-06 18:30:22 +00:00
|
|
|
//
|
2004-08-04 10:34:33 +00:00
|
|
|
if (config.use_transactions) {
|
|
|
|
retval = boinc_db.start_transaction();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[HOST#%d] result_handler.start_transaction() == %d\n",
|
|
|
|
reply.host.id, retval
|
|
|
|
);
|
|
|
|
}
|
2004-07-06 18:30:22 +00:00
|
|
|
}
|
2004-07-13 10:36:18 +00:00
|
|
|
|
2004-07-06 18:30:22 +00:00
|
|
|
for (i=0; i<result_handler.results.size(); i++) {
|
2004-12-05 21:53:32 +00:00
|
|
|
// skip items that we previously marked to skip!
|
2004-07-21 23:48:56 +00:00
|
|
|
if (result_handler.results[i].id > 0) {
|
2004-07-06 18:30:22 +00:00
|
|
|
retval = result_handler.update_result(result_handler.results[i]);
|
2003-08-15 20:35:44 +00:00
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2004-07-06 18:30:22 +00:00
|
|
|
"[HOST#%d] [RESULT#%d %s] can't update result: %s\n",
|
2004-07-13 10:36:18 +00:00
|
|
|
reply.host.id, result_handler.results[i].id, result_handler.results[i].name,
|
2004-07-06 18:30:22 +00:00
|
|
|
boinc_db.error_string()
|
|
|
|
);
|
|
|
|
}
|
2003-08-15 20:35:44 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-07-27 22:42:06 +00:00
|
|
|
|
2004-07-21 23:48:56 +00:00
|
|
|
// trigger the transition handle for the results' WUs
|
|
|
|
//
|
|
|
|
retval = result_handler.update_workunits();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[HOST#%d] can't update WUs: %d\n",
|
|
|
|
reply.host.id, retval
|
|
|
|
);
|
|
|
|
}
|
2004-07-06 18:30:22 +00:00
|
|
|
|
2004-08-04 10:34:33 +00:00
|
|
|
if (config.use_transactions) {
|
|
|
|
retval = boinc_db.commit_transaction();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"[HOST#%d] result_handler.commit_transaction() == %d\n",
|
|
|
|
reply.host.id, retval
|
|
|
|
);
|
|
|
|
}
|
2004-07-06 18:30:22 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-06 21:44:59 +00:00
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
// if the client has an old code sign public key,
|
2002-07-07 20:39:24 +00:00
|
|
|
// send it the new one, with a signature based on the old one.
|
|
|
|
// If they don't have a code sign key, send them one
|
|
|
|
//
|
|
|
|
void send_code_sign_key(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, char* code_sign_key
|
|
|
|
) {
|
|
|
|
char* oldkey, *signature;
|
|
|
|
int i, retval;
|
|
|
|
char path[256];
|
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(sreq.code_sign_key)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
if (strcmp(sreq.code_sign_key, code_sign_key)) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::NORMAL, "received old code sign key\n");
|
2003-04-03 18:35:40 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// look for a signature file
|
|
|
|
//
|
|
|
|
for (i=0; ; i++) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/old_key_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, oldkey);
|
|
|
|
if (retval) {
|
|
|
|
strcpy(reply.message,
|
2004-08-04 15:30:52 +00:00
|
|
|
"You may have an outdated code verification key. "
|
|
|
|
"This may prevent you from accepting new executables. "
|
|
|
|
"If the problem persists, detach/attach the project. "
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strcmp(oldkey, sreq.code_sign_key)) {
|
2002-10-04 20:35:56 +00:00
|
|
|
sprintf(path, "%s/signature_%d", config.key_dir, i);
|
2002-07-07 20:39:24 +00:00
|
|
|
retval = read_file_malloc(path, signature);
|
|
|
|
if (retval) {
|
|
|
|
strcpy(reply.message,
|
2004-08-04 15:30:52 +00:00
|
|
|
"You may have an outdated code verification key. "
|
|
|
|
"This may prevent you from accepting new executables. "
|
|
|
|
"If the problem persists, detach/attach the project. "
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
|
|
|
safe_strcpy(reply.code_sign_key_signature, signature);
|
|
|
|
free(signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(oldkey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(reply.code_sign_key, code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
bool wrong_major_version(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2003-06-11 23:36:51 +00:00
|
|
|
// char buf[256];
|
2004-07-13 10:36:18 +00:00
|
|
|
if (sreq.core_client_major_version != BOINC_MAJOR_VERSION) {
|
2004-05-05 00:50:33 +00:00
|
|
|
//reply.nucleus_only = true;
|
2003-08-15 22:39:56 +00:00
|
|
|
// TODO: check for user-agent not empty and not BOINC
|
|
|
|
reply.probable_user_browser = true;
|
2002-12-02 04:29:40 +00:00
|
|
|
sprintf(reply.message,
|
|
|
|
"To participate in this project, "
|
|
|
|
"you must use major version %d of the BOINC core client. "
|
|
|
|
"Your core client is major version %d.",
|
2004-07-13 10:36:18 +00:00
|
|
|
BOINC_MAJOR_VERSION,
|
2002-12-02 04:29:40 +00:00
|
|
|
sreq.core_client_major_version
|
|
|
|
);
|
2003-05-12 20:46:21 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2003-09-21 22:33:43 +00:00
|
|
|
"[HOST#%d] [auth %s] Wrong major version from user: wanted %d, got %d\n",
|
|
|
|
sreq.hostid, sreq.authenticator,
|
2004-07-13 10:36:18 +00:00
|
|
|
BOINC_MAJOR_VERSION, sreq.core_client_major_version
|
2003-06-14 17:46:08 +00:00
|
|
|
);
|
2004-04-30 18:26:20 +00:00
|
|
|
reply.request_delay = 3600*24;
|
2002-12-02 04:29:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-22 21:44:16 +00:00
|
|
|
|
2003-09-21 22:33:43 +00:00
|
|
|
inline static const char* get_remote_addr() {
|
2003-07-29 01:05:13 +00:00
|
|
|
const char * r = getenv("REMOTE_ADDR");
|
|
|
|
return r ? r : "?.?.?.?";
|
2003-07-25 20:48:29 +00:00
|
|
|
}
|
|
|
|
|
2004-06-24 21:00:13 +00:00
|
|
|
void handle_msgs_from_host(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2004-01-08 00:27:59 +00:00
|
|
|
unsigned int i;
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_FROM_HOST mfh;
|
2004-01-08 00:27:59 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-06-24 21:00:13 +00:00
|
|
|
for (i=0; i<sreq.msgs_from_host.size(); i++) {
|
|
|
|
reply.send_msg_ack = true;
|
|
|
|
MSG_FROM_HOST_DESC& md = sreq.msgs_from_host[i];
|
2004-06-22 22:56:50 +00:00
|
|
|
mfh.clear();
|
|
|
|
mfh.create_time = time(0);
|
2004-07-06 04:10:51 +00:00
|
|
|
safe_strcpy(mfh.variety, md.variety);
|
2004-06-22 22:56:50 +00:00
|
|
|
mfh.hostid = reply.host.id;
|
|
|
|
mfh.handled = false;
|
2004-06-24 21:00:13 +00:00
|
|
|
safe_strcpy(mfh.xml, md.msg_text.c_str());
|
2004-07-06 04:10:51 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"got msg from host; variety %s text %s\n",
|
|
|
|
mfh.variety, mfh.xml
|
|
|
|
);
|
2004-06-22 22:56:50 +00:00
|
|
|
retval = mfh.insert();
|
2004-03-17 01:26:44 +00:00
|
|
|
if (retval) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL,
|
2004-06-24 21:00:13 +00:00
|
|
|
"[HOST#%d] message insert failed: %d\n",
|
2004-05-13 04:48:19 +00:00
|
|
|
reply.host.id, retval
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-24 21:00:13 +00:00
|
|
|
void handle_msgs_to_host(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
|
2004-06-22 22:56:50 +00:00
|
|
|
DB_MSG_TO_HOST mth;
|
2004-03-17 01:26:44 +00:00
|
|
|
char buf[256];
|
2004-07-10 00:11:20 +00:00
|
|
|
sprintf(buf, "where hostid = %d and handled = %d", reply.host.id, 0);
|
2004-06-22 22:56:50 +00:00
|
|
|
while (!mth.enumerate(buf)) {
|
|
|
|
reply.msgs_to_host.push_back(mth);
|
|
|
|
mth.handled = true;
|
|
|
|
mth.update();
|
2004-06-24 21:00:13 +00:00
|
|
|
|
2004-01-08 00:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-24 20:17:52 +00:00
|
|
|
void notify_if_newer_core_version(
|
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
|
|
|
|
PLATFORM& platform, SCHED_SHMEM& ss
|
|
|
|
) {
|
|
|
|
CORE_VERSION* cvp;
|
|
|
|
int req_version;
|
|
|
|
|
|
|
|
if (sreq.core_client_major_version != BOINC_MAJOR_VERSION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req_version = sreq.core_client_major_version*100 + sreq.core_client_minor_version;
|
|
|
|
cvp = ss.lookup_core_version(platform.id);
|
|
|
|
if (cvp && cvp->version_num > req_version) {
|
|
|
|
sprintf(reply.message,
|
2004-09-24 20:48:07 +00:00
|
|
|
"A new version (%d.%02d) of the BOINC core client is available from this project's web site.",
|
2004-09-24 20:17:52 +00:00
|
|
|
cvp->version_num/100,
|
|
|
|
cvp->version_num%100
|
|
|
|
);
|
|
|
|
strcpy(reply.message_priority, "low");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
void process_request(
|
2002-07-07 20:39:24 +00:00
|
|
|
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss,
|
|
|
|
char* code_sign_key
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
|
|
|
PLATFORM* platform;
|
2002-06-21 18:31:32 +00:00
|
|
|
int retval;
|
2003-12-23 19:21:52 +00:00
|
|
|
double last_rpc_time;
|
2004-05-30 10:21:19 +00:00
|
|
|
struct tm *rpc_time_tm;
|
2004-05-30 10:16:57 +00:00
|
|
|
int last_rpc_dayofyear;
|
|
|
|
int current_rpc_dayofyear;
|
2004-07-04 18:55:31 +00:00
|
|
|
bool ok_to_send_work = true;
|
2004-07-24 00:09:28 +00:00
|
|
|
bool have_no_work;
|
2004-05-29 21:49:03 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// if different major version of BOINC, just send a message
|
|
|
|
//
|
2004-05-03 19:30:01 +00:00
|
|
|
if (wrong_major_version(sreq, reply)) {
|
2004-07-04 18:55:31 +00:00
|
|
|
ok_to_send_work = false;
|
|
|
|
|
|
|
|
// if no results, return without accessing DB
|
|
|
|
//
|
|
|
|
if (sreq.results.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there's no work, and client isn't returning results,
|
2004-07-15 18:54:17 +00:00
|
|
|
// this isn't an initial RPC,
|
2004-07-04 18:55:31 +00:00
|
|
|
// and client is requesting work, return without accessing DB
|
|
|
|
//
|
2004-07-24 00:09:28 +00:00
|
|
|
lock_sema();
|
|
|
|
have_no_work = ss.no_work(g_pid);
|
|
|
|
unlock_sema();
|
|
|
|
|
2004-07-04 18:55:31 +00:00
|
|
|
if ((sreq.work_req_seconds > 0)
|
2004-07-24 00:09:28 +00:00
|
|
|
&& have_no_work
|
2004-07-04 18:55:31 +00:00
|
|
|
&& (sreq.results.size() == 0)
|
2004-07-15 18:54:17 +00:00
|
|
|
&& (sreq.hostid != 0)
|
2004-07-04 18:55:31 +00:00
|
|
|
) {
|
|
|
|
strcat(reply.message, "No work available");
|
|
|
|
strcpy(reply.message_priority, "low");
|
|
|
|
reply.request_delay = 3600;
|
2004-08-12 13:36:05 +00:00
|
|
|
if (!config.msg_to_host) {
|
2004-08-05 22:14:23 +00:00
|
|
|
log_messages.printf(
|
2004-08-12 13:36:05 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL, "No work - skipping DB access\n"
|
2004-08-05 22:14:23 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-03 19:30:01 +00:00
|
|
|
}
|
2003-06-11 23:36:45 +00:00
|
|
|
|
2004-07-24 00:09:28 +00:00
|
|
|
// FROM HERE ON DON'T RETURN; goto leave instead
|
2004-08-12 13:36:05 +00:00
|
|
|
// because we've tagged an entry in the work array with our process ID
|
2004-07-24 00:09:28 +00:00
|
|
|
|
2004-04-30 18:26:20 +00:00
|
|
|
// now open the database
|
|
|
|
//
|
|
|
|
retval = open_database();
|
|
|
|
if (retval) {
|
2004-06-16 23:06:47 +00:00
|
|
|
send_message("Server can't open database", 3600);
|
2004-07-24 00:09:28 +00:00
|
|
|
goto leave;
|
2004-04-30 18:26:20 +00:00
|
|
|
}
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
retval = authenticate_user(sreq, reply);
|
2004-07-24 00:09:28 +00:00
|
|
|
if (retval) goto leave;
|
2004-01-10 01:08:50 +00:00
|
|
|
if (reply.user.id == 0) {
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "No user ID!\n");
|
2004-01-10 01:08:50 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-06-02 00:02:01 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"Processing request from [USER#%d] [HOST#%d] [IP %s] [RPC#%d] core client version %d.%02d\n",
|
|
|
|
reply.user.id, reply.host.id, get_remote_addr(), sreq.rpc_seqno,
|
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
|
|
|
);
|
|
|
|
++log_messages;
|
|
|
|
|
2003-12-23 19:21:52 +00:00
|
|
|
last_rpc_time = reply.host.rpc_time;
|
2004-05-30 10:16:57 +00:00
|
|
|
rpc_time_tm = localtime((const time_t*)&reply.host.rpc_time);
|
|
|
|
last_rpc_dayofyear = rpc_time_tm->tm_yday;
|
2004-05-29 21:21:35 +00:00
|
|
|
|
2004-05-29 21:56:21 +00:00
|
|
|
reply.host.rpc_time = time(0);
|
2004-05-30 10:21:19 +00:00
|
|
|
rpc_time_tm = localtime((const time_t*)&reply.host.rpc_time);
|
2004-05-30 10:16:57 +00:00
|
|
|
current_rpc_dayofyear = rpc_time_tm->tm_yday;
|
2004-05-29 21:49:03 +00:00
|
|
|
|
2004-05-30 10:16:57 +00:00
|
|
|
if (last_rpc_dayofyear != current_rpc_dayofyear) {
|
2004-06-02 00:06:31 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::DEBUG, "[HOST#%d] Resetting nresults_today\n", reply.host.id);
|
2004-05-27 18:13:00 +00:00
|
|
|
reply.host.nresults_today = 0;
|
|
|
|
}
|
|
|
|
retval = modify_host_struct(sreq, reply.host);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// look up the client's platform in the DB
|
|
|
|
//
|
2002-05-24 04:29:10 +00:00
|
|
|
platform = ss.lookup_platform(sreq.platform_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!platform) {
|
2003-07-29 01:09:53 +00:00
|
|
|
sprintf(reply.message, "platform '%s' not found", sreq.platform_name);
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(reply.message_priority, "low");
|
2003-06-14 17:46:08 +00:00
|
|
|
log_messages.printf(
|
2004-06-02 00:06:31 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL, "[HOST#%d] platform '%s' not found\n",
|
2003-06-14 17:46:08 +00:00
|
|
|
reply.host.id, sreq.platform_name
|
|
|
|
);
|
2004-09-21 20:04:56 +00:00
|
|
|
reply.request_delay = 3600*24;
|
2004-07-24 00:09:28 +00:00
|
|
|
goto leave;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-09-24 20:17:52 +00:00
|
|
|
|
|
|
|
notify_if_newer_core_version(sreq, reply, *platform, ss);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-27 20:36:03 +00:00
|
|
|
handle_global_prefs(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-09-24 20:17:52 +00:00
|
|
|
#if 0
|
2004-08-05 22:14:23 +00:00
|
|
|
reply.deletion_policy_priority = config.deletion_policy_priority;
|
|
|
|
reply.deletion_policy_expire = config.deletion_policy_expire;
|
2004-09-24 20:17:52 +00:00
|
|
|
#endif
|
2004-08-05 22:14:23 +00:00
|
|
|
|
2004-05-03 02:18:35 +00:00
|
|
|
if (reply.update_user_record) {
|
|
|
|
DB_USER user;
|
|
|
|
user = reply.user;
|
|
|
|
user.update();
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
handle_results(sreq, reply);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-12-31 23:09:21 +00:00
|
|
|
// if last RPC was within config.min_sendwork_interval, don't send work
|
2003-12-23 19:21:52 +00:00
|
|
|
//
|
2004-07-24 00:09:28 +00:00
|
|
|
if (!have_no_work && ok_to_send_work && sreq.work_req_seconds > 0) {
|
2004-05-13 04:48:19 +00:00
|
|
|
if (config.min_sendwork_interval) {
|
|
|
|
double diff = dtime() - last_rpc_time;
|
|
|
|
if (diff < config.min_sendwork_interval) {
|
2004-07-04 18:55:31 +00:00
|
|
|
ok_to_send_work = false;
|
2004-05-13 04:48:19 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"Not sending work - last RPC too recent: %f\n", diff
|
|
|
|
);
|
|
|
|
sprintf(reply.message,
|
|
|
|
"Not sending work - last RPC too recent: %d sec", (int)diff
|
|
|
|
);
|
|
|
|
strcpy(reply.message_priority, "low");
|
|
|
|
reply.request_delay = config.min_sendwork_interval;
|
|
|
|
}
|
|
|
|
}
|
2004-07-04 18:55:31 +00:00
|
|
|
if (ok_to_send_work) {
|
2004-05-13 04:48:19 +00:00
|
|
|
send_work(sreq, reply, *platform, ss);
|
2003-12-31 23:09:21 +00:00
|
|
|
}
|
2003-12-23 19:21:52 +00:00
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
|
|
|
send_code_sign_key(sreq, reply, code_sign_key);
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2004-08-18 01:49:46 +00:00
|
|
|
handle_msgs_from_host(sreq, reply);
|
2004-06-24 21:00:13 +00:00
|
|
|
if (config.msg_to_host) {
|
|
|
|
handle_msgs_to_host(sreq, reply);
|
2004-03-17 01:26:44 +00:00
|
|
|
}
|
2004-05-27 18:13:00 +00:00
|
|
|
|
|
|
|
update_host_record(reply.host);
|
2004-07-24 00:09:28 +00:00
|
|
|
|
|
|
|
leave:
|
|
|
|
if (!have_no_work) {
|
|
|
|
ss.restore_work(g_pid);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
void handle_request(
|
|
|
|
FILE* fin, FILE* fout, SCHED_SHMEM& ss, char* code_sign_key
|
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REQUEST sreq;
|
|
|
|
SCHEDULER_REPLY sreply;
|
2002-08-20 00:30:13 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(&sreq, 0, sizeof(sreq));
|
2004-03-23 01:44:13 +00:00
|
|
|
|
2004-03-20 07:57:34 +00:00
|
|
|
if (sreq.parse(fin) == 0){
|
2004-03-23 01:44:13 +00:00
|
|
|
log_messages.printf(
|
2004-09-13 18:05:54 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
|
|
|
"Handling request: IP %s, auth %s, host %d, platform %s, version %d.%02d\n",
|
2004-08-05 20:58:26 +00:00
|
|
|
get_remote_addr(), sreq.authenticator, sreq.hostid, sreq.platform_name,
|
2004-03-23 01:44:13 +00:00
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
|
|
|
);
|
|
|
|
process_request(sreq, sreply, ss, code_sign_key);
|
2004-03-20 07:57:34 +00:00
|
|
|
} else {
|
2004-03-23 03:59:32 +00:00
|
|
|
log_messages.printf(
|
2004-05-13 04:48:19 +00:00
|
|
|
SCHED_MSG_LOG::NORMAL,
|
2004-06-01 23:30:31 +00:00
|
|
|
"Incomplete request received from IP %s, auth %s, platform %s, version %d.%02d\n",
|
2004-05-13 04:48:19 +00:00
|
|
|
get_remote_addr(), sreq.authenticator, sreq.platform_name,
|
|
|
|
sreq.core_client_major_version, sreq.core_client_minor_version
|
2004-03-23 01:44:13 +00:00
|
|
|
);
|
|
|
|
strcpy(sreply.message, "Incomplete request received.");
|
|
|
|
strcpy(sreply.message_priority, "low");
|
2004-05-13 04:48:19 +00:00
|
|
|
sreply.nucleus_only = true;
|
2004-03-20 07:57:34 +00:00
|
|
|
}
|
2004-06-24 21:00:13 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
sreply.write(fout);
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
static volatile const char __attribute__((unused)) *BOINCrcsid="$Id$";
|
|
|
|
#else
|
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
|
|
|
#endif
|