2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// 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
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// 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-06-21 06:52:47 +00:00
|
|
|
// This file contains high-level logic for communicating with
|
2002-07-15 05:34:32 +00:00
|
|
|
// scheduling servers,
|
|
|
|
// and for merging the result of a scheduler RPC into the client state
|
2002-06-21 06:52:47 +00:00
|
|
|
|
|
|
|
// Note: code for actually doing a scheduler RPC is elsewhere,
|
|
|
|
// namely scheduler_op.C
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2002-06-07 22:59:24 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#undef _USING_FCGI_
|
|
|
|
#endif
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "log_flags.h"
|
2002-05-17 22:33:57 +00:00
|
|
|
#include "message.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "scheduler_op.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
// quantities like avg CPU time decay by a factor of e every week
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
#define EXP_DECAY_RATE (1./(3600*24*7))
|
2002-07-11 01:09:53 +00:00
|
|
|
#define SECONDS_IN_DAY 86400
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// estimate the days of work remaining
|
2002-06-06 23:43:05 +00:00
|
|
|
//
|
|
|
|
double CLIENT_STATE::current_water_days() {
|
|
|
|
unsigned int i;
|
2002-07-15 05:34:32 +00:00
|
|
|
RESULT* rp;
|
2002-06-06 23:43:05 +00:00
|
|
|
double seconds_remaining=0;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2002-07-15 05:34:32 +00:00
|
|
|
rp = results[i];
|
2002-06-06 23:43:05 +00:00
|
|
|
if (rp->is_compute_done) continue;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (rp->cpu_time > 0) {
|
2002-06-21 18:31:32 +00:00
|
|
|
seconds_remaining += (rp->wup->seconds_to_complete - rp->cpu_time);
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
2002-06-21 18:31:32 +00:00
|
|
|
seconds_remaining += rp->wup->seconds_to_complete;
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-11 01:09:53 +00:00
|
|
|
return (seconds_remaining * SECONDS_IN_DAY);
|
2002-06-06 23:43:05 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// seconds of work needed to come up to high-water mark
|
|
|
|
//
|
|
|
|
double CLIENT_STATE::work_needed_secs() {
|
|
|
|
double x = current_water_days();
|
|
|
|
if (x > prefs->high_water_days) return 0;
|
|
|
|
return (prefs->high_water_days - x)*86400;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// update exponentially-averaged CPU times of all projects
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void CLIENT_STATE::update_avg_cpu(PROJECT* p) {
|
2002-07-15 05:34:32 +00:00
|
|
|
time_t now = time(0);
|
2002-04-30 22:22:54 +00:00
|
|
|
double deltat = now - p->exp_avg_mod_time;
|
|
|
|
if (deltat > 0) {
|
|
|
|
if (p->exp_avg_cpu != 0) {
|
|
|
|
p->exp_avg_cpu *= exp(deltat*EXP_DECAY_RATE);
|
|
|
|
}
|
|
|
|
p->exp_avg_mod_time = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// find a project that needs its master file parsed
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::next_project_master_pending() {
|
|
|
|
unsigned int i;
|
|
|
|
PROJECT* p;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->min_rpc_time > now ) continue;
|
|
|
|
if (p->master_url_fetch_pending) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the next project after "old", in debt order,
|
|
|
|
// that is eligible for a scheduler RPC
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::next_project(PROJECT* old) {
|
|
|
|
PROJECT* p, *pbest;
|
|
|
|
int best = 999;
|
|
|
|
time_t now = time(0);
|
|
|
|
unsigned int i;
|
|
|
|
pbest = 0;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->min_rpc_time > now ) continue;
|
|
|
|
if (old && p->debt_order <= old->debt_order) continue;
|
|
|
|
if (p->debt_order < best) {
|
|
|
|
pbest = p;
|
|
|
|
best = p->debt_order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pbest;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2002-04-30 22:22:54 +00:00
|
|
|
// choose a project to ask for work
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::choose_project() {
|
|
|
|
PROJECT* p, *bestp;
|
|
|
|
unsigned int i;
|
|
|
|
double best_ratio, ratio;
|
|
|
|
|
|
|
|
// update the average CPU times of all projects
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
update_avg_cpu(projects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// pick the project for which share/avg is largest
|
|
|
|
// (and we have permission to contact it)
|
|
|
|
//
|
|
|
|
best_ratio = 0;
|
|
|
|
bestp = 0;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (time(0) < p->next_request_time) continue;
|
|
|
|
if (p->exp_avg_cpu == 0) return p;
|
|
|
|
ratio = p->resource_share/p->exp_avg_cpu;
|
2002-06-21 06:52:47 +00:00
|
|
|
if (ratio >= best_ratio) {
|
2002-04-30 22:22:54 +00:00
|
|
|
best_ratio = ratio;
|
|
|
|
bestp = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bestp;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Compute the "resource debt" of each project. This is used
|
|
|
|
// to determine what project we will focus on next, based on
|
|
|
|
// the user specified resource share
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
void CLIENT_STATE::compute_resource_debts() {
|
|
|
|
unsigned int i, j;
|
|
|
|
PROJECT* p, *pbest;
|
|
|
|
double best;
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
update_avg_cpu(p);
|
|
|
|
if (p->exp_avg_cpu == 0) {
|
|
|
|
p->resource_debt = p->resource_share;
|
|
|
|
} else {
|
|
|
|
p->resource_debt = p->resource_share/p->exp_avg_cpu;
|
|
|
|
}
|
|
|
|
p->debt_order = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put in decreasing order. Should use qsort or some stdlib thang
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
best = -2;
|
|
|
|
for (j=0; j<projects.size(); j++) {
|
|
|
|
p = projects[j];
|
|
|
|
if (p->debt_order >= 0) continue;
|
|
|
|
if (p->resource_debt > best) {
|
|
|
|
best = p->resource_debt;
|
|
|
|
pbest = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pbest->debt_order = i;
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Prepare the scheduler request. This writes the request in XML to a
|
|
|
|
// file (SCHED_OP_REQUEST_FILE) which is later sent to the scheduling
|
|
|
|
// server
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
int CLIENT_STATE::make_scheduler_request(PROJECT* p, double work_req) {
|
2002-06-21 00:22:59 +00:00
|
|
|
FILE* f = fopen(SCHED_OP_REQUEST_FILE, "wb");
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
RESULT* rp;
|
2002-07-11 01:09:53 +00:00
|
|
|
if(p==NULL) {
|
|
|
|
fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: unexpected NULL pointer p\n");
|
|
|
|
return ERR_NULL;
|
|
|
|
}
|
|
|
|
if(work_req<0) {
|
|
|
|
fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: negative work_req\n");
|
|
|
|
return ERR_NEG;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
fprintf(f,
|
|
|
|
"<scheduler_request>\n"
|
|
|
|
" <authenticator>%s</authenticator>\n"
|
|
|
|
" <hostid>%d</hostid>\n"
|
|
|
|
" <rpc_seqno>%d</rpc_seqno>\n"
|
|
|
|
" <platform_name>%s</platform_name>\n"
|
|
|
|
" <core_client_version>%d</core_client_version>\n"
|
2002-07-15 05:34:32 +00:00
|
|
|
" <work_req_seconds>%f</work_req_seconds>\n",
|
2002-04-30 22:22:54 +00:00
|
|
|
p->authenticator,
|
|
|
|
p->hostid,
|
|
|
|
p->rpc_seqno,
|
2002-05-17 22:33:57 +00:00
|
|
|
platform_name,
|
|
|
|
version,
|
2002-04-30 22:22:54 +00:00
|
|
|
work_req
|
|
|
|
);
|
2002-07-07 20:39:24 +00:00
|
|
|
if (p->code_sign_key) {
|
|
|
|
fprintf(f, "<code_sign_key>\n%s</code_sign_key>\n", p->code_sign_key);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
FILE* fprefs = fopen(PREFS_FILE_NAME, "r");
|
2002-07-15 05:34:32 +00:00
|
|
|
if (!fprefs) return ERR_FOPEN;
|
2002-06-21 06:52:47 +00:00
|
|
|
copy_stream(fprefs, f);
|
|
|
|
fclose(fprefs);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
time_stats.write(f, true);
|
|
|
|
net_stats.write(f, true);
|
|
|
|
host_info.write(f);
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
rp = results[i];
|
|
|
|
if (rp->project == p && !rp->is_server_ack) {
|
|
|
|
if (rp->is_upload_done()) {
|
|
|
|
rp->write(f, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f, "</scheduler_request>\n");
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// find a project with results that are overdue to report,
|
|
|
|
// and which we're allowed to contact.
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::find_project_with_overdue_results() {
|
|
|
|
unsigned int i;
|
|
|
|
RESULT* r;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
r = results[i];
|
|
|
|
if (r->is_compute_done && r->is_upload_done() && !r->is_server_ack) {
|
|
|
|
if (r->project->min_rpc_time < now) {
|
|
|
|
return r->project;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if we're allowed to do a scheduler RPC to at least one project
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::some_project_rpc_ok() {
|
|
|
|
unsigned int i;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
if (projects[i]->min_rpc_time < now) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called from the client's polling loop.
|
|
|
|
// initiate scheduler RPC activity if needed and possible
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::scheduler_rpc_poll() {
|
|
|
|
double work_secs;
|
|
|
|
PROJECT* p;
|
|
|
|
bool action, below_low_water;
|
|
|
|
|
|
|
|
switch(scheduler_op->state) {
|
|
|
|
case SCHEDULER_OP_STATE_IDLE:
|
|
|
|
below_low_water = (current_water_days() <= prefs->low_water_days);
|
|
|
|
if (below_low_water && some_project_rpc_ok()) {
|
|
|
|
compute_resource_debts();
|
|
|
|
scheduler_op->init_get_work();
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
p = find_project_with_overdue_results();
|
|
|
|
if (p) {
|
|
|
|
compute_resource_debts();
|
|
|
|
if (p->debt_order == 0) {
|
|
|
|
work_secs = work_needed_secs();
|
|
|
|
} else {
|
|
|
|
work_secs = 0;
|
|
|
|
}
|
|
|
|
scheduler_op->init_return_results(p, work_secs);
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scheduler_op->poll();
|
|
|
|
if (scheduler_op->state == SCHEDULER_OP_STATE_IDLE) {
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2002-06-21 06:52:47 +00:00
|
|
|
// manage the task of maintaining an adequate supply of work.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
bool CLIENT_STATE::get_work() {
|
2002-06-21 06:52:47 +00:00
|
|
|
PROJECT* project;
|
|
|
|
int retval, work_secs;
|
2002-04-30 22:22:54 +00:00
|
|
|
bool action=false;
|
|
|
|
|
|
|
|
if (need_work()) {
|
2002-06-21 06:52:47 +00:00
|
|
|
switch(scheduler_op->state) {
|
|
|
|
case SCHEDULER_OP_STATE_IDLE:
|
2002-04-30 22:22:54 +00:00
|
|
|
// if no scheduler request pending, start one
|
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
project = choose_project();
|
|
|
|
if (!project) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("all projects temporarily backed off\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
work_secs =
|
|
|
|
(int) (prefs->high_water_days - current_water_days())*86400;
|
|
|
|
retval = make_scheduler_request(project, work_secs);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "make_scheduler_request: %d\n", retval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduler_op->start_op(project);
|
2002-04-30 22:22:54 +00:00
|
|
|
action = true;
|
2002-06-21 06:52:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scheduler_op->poll();
|
|
|
|
if (scheduler_op->state == SCHEDULER_OP_STATE_DONE) {
|
|
|
|
scheduler_op->state = SCHEDULER_OP_STATE_IDLE;
|
2002-04-30 22:22:54 +00:00
|
|
|
action = true;
|
2002-06-21 06:52:47 +00:00
|
|
|
if (scheduler_op->scheduler_op_retval) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"scheduler RPC to %s failed: %d\n",
|
|
|
|
scheduler_op->project->master_url,
|
|
|
|
scheduler_op->scheduler_op_retval
|
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (log_flags.sched_ops) {
|
|
|
|
printf("HTTP work request failed: %d\n", retval);
|
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
handle_scheduler_reply(*scheduler_op);
|
|
|
|
client_state_dirty = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// see whether a new preferences set, obtained from the given
|
|
|
|
// project, looks "reasonable". This is to prevent accidental or
|
|
|
|
// intentional preferences corruption
|
2002-06-21 06:52:47 +00:00
|
|
|
// Currently this is primitive: just make sure there's at least 1 project
|
2002-07-15 23:21:20 +00:00
|
|
|
// TODO: figure out what else to look for here
|
2002-06-21 06:52:47 +00:00
|
|
|
bool PREFS::looks_reasonable(PROJECT& project) {
|
|
|
|
if (projects.size() > 0) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse the reply from a scheduler and configure internal structures
|
|
|
|
// appropriately
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
void CLIENT_STATE::handle_scheduler_reply(
|
|
|
|
PROJECT* project, char* scheduler_url
|
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REPLY sr;
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
unsigned int i;
|
2002-06-21 06:52:47 +00:00
|
|
|
char prefs_backup[256];
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT *pp, *sp;
|
2002-06-21 06:52:47 +00:00
|
|
|
PREFS* new_prefs;
|
2002-07-07 20:39:24 +00:00
|
|
|
bool signature_valid;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
contacted_sched_server = true;
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
f = fopen(SCHED_OP_RESULT_FILE, "r");
|
|
|
|
printf("------------- SCHEDULER REPLY ----------\n");
|
|
|
|
copy_stream(f, stdout);
|
|
|
|
fclose(f);
|
|
|
|
printf("------------- END ----------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
f = fopen(SCHED_OP_RESULT_FILE, "r");
|
|
|
|
retval = sr.parse(f);
|
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
if (strlen(sr.message)) {
|
|
|
|
show_message(sr.message, sr.message_priority);
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (sr.request_delay) {
|
2002-07-15 05:34:32 +00:00
|
|
|
project->min_rpc_time = time(0) + sr.request_delay;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
if (sr.hostid) {
|
|
|
|
project->hostid = sr.hostid;
|
|
|
|
project->rpc_seqno = 0;
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
// if the scheduler reply includes preferences
|
|
|
|
// that are newer than what we have on disk, then
|
|
|
|
// - verify that the new prefs look reasonable;
|
|
|
|
// they should include at least one project.
|
|
|
|
// - rename the current prefs file
|
|
|
|
// - copy new preferences to prefs.xml
|
|
|
|
// - copy any new projects into the CLIENT_STATE structure
|
|
|
|
// - update the preferences info of projects already in CLIENT_STATE
|
|
|
|
//
|
|
|
|
// There may be projects in CLIENT_STATE that are not in the new prefs;
|
|
|
|
// i.e. the user has dropped out of these projects.
|
|
|
|
// We'll continue with any ongoing work for these projects,
|
|
|
|
// but they'll be dropped the next time the client starts up.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (sr.prefs_mod_time > prefs->mod_time) {
|
|
|
|
f = fopen(PREFS_TEMP_FILE_NAME, "w");
|
|
|
|
fprintf(f,
|
|
|
|
"<preferences>\n"
|
|
|
|
" <prefs_mod_time>%d</prefs_mod_time>\n"
|
|
|
|
" <from_project>%s</from_project>\n"
|
|
|
|
" <from_scheduler>%s</from_scheduler>\n",
|
|
|
|
sr.prefs_mod_time,
|
|
|
|
project->master_url,
|
2002-07-15 05:34:32 +00:00
|
|
|
scheduler_url
|
2002-06-21 06:52:47 +00:00
|
|
|
);
|
|
|
|
fputs(sr.prefs_xml, f);
|
|
|
|
fprintf(f,
|
|
|
|
"</preferences>\n"
|
|
|
|
);
|
|
|
|
fclose(f);
|
|
|
|
f = fopen(PREFS_TEMP_FILE_NAME, "r");
|
|
|
|
new_prefs = new PREFS;
|
|
|
|
new_prefs->parse(f);
|
|
|
|
fclose(f);
|
|
|
|
if (new_prefs->looks_reasonable(*project)) {
|
|
|
|
make_prefs_backup_name(*prefs, prefs_backup);
|
|
|
|
rename(PREFS_FILE_NAME, prefs_backup);
|
|
|
|
rename(PREFS_TEMP_FILE_NAME, PREFS_FILE_NAME);
|
|
|
|
for (i=0; i<new_prefs->projects.size(); i++) {
|
|
|
|
pp = new_prefs->projects[i];
|
|
|
|
sp = lookup_project(pp->master_url);
|
|
|
|
if (sp) {
|
|
|
|
sp->copy_prefs_fields(*pp);
|
|
|
|
} else {
|
|
|
|
projects.push_back(pp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete prefs;
|
|
|
|
prefs = new_prefs;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "New preferences don't look reasonable, ignoring\n");
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// if the scheduler reply includes a code-signing key,
|
|
|
|
// accept it if we don't already have one from the project.
|
|
|
|
// Otherwise verify its signature, using the key we already have.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (sr.code_sign_key) {
|
|
|
|
if (!project->code_sign_key) {
|
|
|
|
project->code_sign_key = strdup(sr.code_sign_key);
|
|
|
|
} else {
|
|
|
|
retval = verify_string2(
|
|
|
|
sr.code_sign_key, sr.code_sign_key_signature,
|
|
|
|
project->code_sign_key, signature_valid
|
|
|
|
);
|
|
|
|
if (!retval && signature_valid) {
|
|
|
|
free(project->code_sign_key);
|
|
|
|
project->code_sign_key = strdup(sr.code_sign_key);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"New code signing key from %s doesn't validate\n",
|
|
|
|
project->project_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy new entities to client state
|
|
|
|
//
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sr.apps.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.apps[i].name);
|
|
|
|
if (app) {
|
2002-07-04 21:53:13 +00:00
|
|
|
//*app = sr.apps[i];
|
|
|
|
retval = link_app(project,app); // not sure about this
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
app = new APP;
|
|
|
|
*app = sr.apps[i];
|
|
|
|
retval = link_app(project, app);
|
|
|
|
if (!retval) apps.push_back(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.file_infos.size(); i++) {
|
|
|
|
if (!lookup_file_info(project, sr.file_infos[i].name)) {
|
|
|
|
FILE_INFO* fip = new FILE_INFO;
|
|
|
|
*fip = sr.file_infos[i];
|
|
|
|
retval = link_file_info(project, fip);
|
|
|
|
if (!retval) file_infos.push_back(fip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.app_versions.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.app_versions[i].app_name);
|
|
|
|
if (!lookup_app_version(app, sr.app_versions[i].version_num)) {
|
|
|
|
APP_VERSION* avp = new APP_VERSION;
|
|
|
|
*avp = sr.app_versions[i];
|
|
|
|
retval = link_app_version(project, avp);
|
|
|
|
if (!retval) app_versions.push_back(avp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.workunits.size(); i++) {
|
|
|
|
if (!lookup_workunit(project, sr.workunits[i].name)) {
|
|
|
|
WORKUNIT* wup = new WORKUNIT;
|
|
|
|
*wup = sr.workunits[i];
|
|
|
|
retval = link_workunit(project, wup);
|
|
|
|
if (!retval) workunits.push_back(wup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.results.size(); i++) {
|
|
|
|
if (!lookup_result(project, sr.results[i].name)) {
|
|
|
|
RESULT* rp = new RESULT;
|
|
|
|
*rp = sr.results[i];
|
|
|
|
retval = link_result(project, rp);
|
|
|
|
if (!retval) results.push_back(rp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update records for ack'ed results
|
|
|
|
//
|
|
|
|
for (i=0; i<sr.result_acks.size(); i++) {
|
|
|
|
RESULT* rp = lookup_result(project, sr.result_acks[i].name);
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("got ack for result %s\n", sr.result_acks[i].name);
|
|
|
|
}
|
|
|
|
if (rp) {
|
|
|
|
rp->is_server_ack = true;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: got ack for result %s, can't find\n",
|
|
|
|
sr.result_acks[i].name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("State after handle_scheduler_reply():\n");
|
|
|
|
print_counts();
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|