make_work

svn path=/trunk/boinc/; revision=496
This commit is contained in:
David Anderson 2002-10-14 23:10:12 +00:00
parent fd789bc2d9
commit 7f3da8dcbf
13 changed files with 155 additions and 94 deletions

View File

@ -2140,3 +2140,28 @@ Eric October 14, 2002
boinc.pbproj/
project.pbxproj
David Oct 14 2002
- Change make_work so that it generates results with
valid file upload signatures.
Instead of directly creating new DB.result records,
it now calls create_result() to do the work.
- Changed create_result() to take a name suffix
- Factored key parsing into a function
- Removed random-WU-name feature from create_work;
names should be generated at a higher level
- added a key-generation function to test.inc
lib/
parse.C
sched/
Makefile.in
config.C,h
make_work.C
test/
test.inc
test_loop.php
tools/
add.C
backend_lib.C,h
create_work.C
process_result_template.C

View File

@ -144,3 +144,18 @@ int read_file_malloc(char* pathname, char*& str) {
fclose(f);
return 0;
}
#if 0
// replace XML element contents. not currently used
//
void replace_element(char* buf, char* start, char* end, char* replacement) {
char temp[MAX_BLOB_SIZE], *p, *q;
p = strstr(buf, start);
p += strlen(start);
q = strstr(p, end);
strcpy(temp, q);
strcpy(p, replacement);
strcat(p, temp);
}
#endif

View File

@ -71,7 +71,13 @@ MAKE_WORK_OBJS = \
config.o \
../db/db_mysql.o \
../db/mysql_util.o \
../lib/parse.o
../tools/backend_lib.o \
../tools/process_result_template.o \
../lib/parse.o \
../lib/md5_file.o \
../lib/md5.o \
../lib/crypt.o \
../RSAEuro/source/rsaeuro.a
FCGI_OBJS = \
handle_request.fcgi.o \

View File

@ -16,6 +16,8 @@ int CONFIG::parse(FILE* in) {
else if (parse_str(buf, "<db_passwd>", db_passwd, sizeof(db_passwd))) continue;
else if (parse_int(buf, "<shmem_key>", shmem_key)) continue;
else if (parse_str(buf, "<key_dir>", key_dir, sizeof(key_dir))) continue;
else if (parse_str(buf, "<download_url>", download_url, sizeof(download_url))) continue;
else if (parse_str(buf, "<upload_url>", upload_url, sizeof(upload_url))) continue;
else if (parse_str(buf, "<upload_dir>", upload_dir, sizeof(upload_dir))) continue;
else if (parse_str(buf, "<user_name>", user_name, sizeof(user_name))) continue;
}

View File

@ -9,6 +9,8 @@ public:
char db_passwd[256];
int shmem_key;
char key_dir[256];
char download_url[256];
char upload_url[256];
char upload_dir[256];
char user_name[256];

View File

@ -1,10 +1,9 @@
// make_work.C
//
// make_work -wu_name name -result_template filename [ -cushion n ]
//
// Create result records as needed to maintain a pool to send
//
// This reads a result record from the DB, then makes clones of it.
// Assumes the result has a single output file,
// so overwrites the first <name> element with a new name
#include <stdio.h>
#include <stdlib.h>
@ -13,32 +12,27 @@
#include <time.h>
#include "db.h"
#include "crypt.h"
#include "backend_lib.h"
#include "config.h"
#define TRIGGER_FILENAME "stop_server"
int cushion = 10;
char wu_name[256], result_template_file[256];
void check_trigger() {
FILE* f = fopen(TRIGGER_FILENAME, "r");
if (!f) return;
exit(0);
}
void replace_element(char* buf, char* start, char* end, char* replacement) {
char temp[MAX_BLOB_SIZE], *p, *q;
p = strstr(buf, start);
p += strlen(start);
q = strstr(p, end);
strcpy(temp, q);
strcpy(p, replacement);
strcat(p, temp);
}
void make_work() {
CONFIG config;
RESULT result;
int retval, i=time(0), n;
char buf[256];
int retval, i, start_time=time(0), n;
char keypath[256], suffix[256];
R_RSA_PRIVATE_KEY key;
WORKUNIT wu;
retval = config.parse_file();
if (retval) {
@ -52,9 +46,17 @@ void make_work() {
exit(1);
}
retval = db_result(1, result);
strcpy(wu.name, wu_name);
retval = db_workunit_lookup_name(wu);
if (retval) {
fprintf(stderr, "make_work: can't read result\n");
fprintf(stderr, "make_work: can't find wu %s\n", wu_name);
exit(1);
}
sprintf(keypath, "%s/upload_private", config.key_dir);
retval = read_key_file(keypath, key);
if (retval) {
fprintf(stderr, "make_work: can't read key\n");
exit(1);
}
@ -66,22 +68,16 @@ void make_work() {
exit(1);
}
printf("make_work: %d results\n", n);
if (n > 10) {
if (n > cushion) {
sleep(1);
continue;
}
result.id = 0;
result.create_time = time(0);
sprintf(result.name, "result_%d", i++);
result.state = RESULT_STATE_UNSENT;
result.validate_state = VALIDATE_STATE_INITIAL;
replace_element(result.xml_doc_in, "<name>", "</name>", result.name);
replace_element(result.xml_doc_in, "<file_name>", "</file_name>", result.name);
retval = db_result_new(result);
if (retval) {
fprintf(stderr, "make_work: can't create result\n");
exit(1);
}
sprintf(suffix, "%d_%d", start_time, i++);
create_result(
wu, result_template_file, suffix, key,
config.upload_url, config.download_url
);
printf("make_work: added a result\n");
}
}
@ -94,9 +90,24 @@ int main(int argc, char** argv) {
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-asynch")) {
asynch = true;
} else if (!strcmp(argv[i], "-cushion")) {
cushion = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-result_template")) {
strcpy(result_template_file, argv[++i]);
} else if (!strcmp(argv[i], "-wu_name")) {
strcpy(wu_name, argv[++i]);
}
}
if (!strlen(result_template_file)) {
fprintf(stderr, "make_work: missing -result_template\n");
exit(1);
}
if (!strlen(wu_name)) {
fprintf(stderr, "make_work: missing -wu_name\n");
exit(1);
}
if (asynch) {
if (!fork()) {
make_work();

View File

@ -57,6 +57,13 @@ function run_tool($cmd) {
PassThru($cmd);
}
function create_keys() {
$key_dir = get_env_var("BOINC_KEY_DIR");
$lib_dir = get_env_var("BOINC_SRC_DIR")."/lib";
PassThru("$lib_dir/crypt_prog -genkey 1024 $key_dir/upload_private $key_dir/upload_public");
PassThru("$lib_dir/crypt_prog -genkey 1024 $key_dir/code_sign_private $key_dir/code_sign_public");
}
class App {
var $name;
@ -205,6 +212,8 @@ class Project {
fputs($f, " <db_passwd>$this->db_passwd</db_passwd>\n");
fputs($f, " <shmem_key>$this->shmem_key</shmem_key>\n");
fputs($f, " <key_dir>$this->key_dir</key_dir>\n");
fputs($f, " <download_url>$this->download_url</download_url>\n");
fputs($f, " <upload_url>$this->upload_url</upload_url>\n");
fputs($f, " <upload_dir>$this->project_dir/upload</upload_dir>\n");
fputs($f, " <user_name>$this->user_name</user_name>\n");
fputs($f, "</config>\n");
@ -254,8 +263,9 @@ class Project {
PassThru("cd $this->project_dir/cgi; feeder -asynch > feeder_out");
}
function start_make_work(){
PassThru("cd $this->project_dir/cgi; make_work -asynch > make_work_out");
function start_make_work($work){
$result_template_path = realpath($work->result_template);
PassThru("cd $this->project_dir/cgi; make_work -asynch -result_template $result_template_path -wu_name $work->wu_template > make_work_out");
}
function stop() {
@ -418,7 +428,6 @@ class Work {
var $result_template;
var $nresults;
var $input_files;
var $randomize_name;
var $rsc_iops;
var $rsc_fpops;
var $rsc_disk;
@ -429,7 +438,6 @@ class Work {
$this->rcs_iops = 180000000000;
$this->rcs_fpops = 100000000000;
$this->rcs_disk = 1000000;
$this->randomize_name = false;
}
function install($project) {
@ -438,12 +446,7 @@ class Work {
$x = $this->input_files[$i];
PassThru("cp $x $project->project_dir/download");
}
$cmd = "create_work -db_name $project->db_name -download_dir $project->project_dir/download -upload_url $project->upload_url -download_url $project->download_url/ -keyfile $project->key_dir/upload_private -appname $app->name -rsc_iops $this->rcs_iops -rsc_fpops $this->rsc_fpops -rsc_disk $this->rsc_disk -wu_template $this->wu_template -result_template $this->result_template -nresults $this->nresults ";
if ($this->randomize_name) {
$cmd = $cmd." -wu_name_rand ".$this->wu_template;
} else {
$cmd = $cmd." -wu_name ".$this->wu_template;
}
$cmd = "create_work -db_name $project->db_name -download_dir $project->project_dir/download -upload_url $project->upload_url -download_url $project->download_url/ -keyfile $project->key_dir/upload_private -appname $app->name -rsc_iops $this->rcs_iops -rsc_fpops $this->rsc_fpops -rsc_disk $this->rsc_disk -wu_template $this->wu_template -result_template $this->result_template -nresults $this->nresults -wu_name $this->wu_template";
for ($i=0; $i<sizeof($this->input_files); $i++) {
$x = $this->input_files[$i];
$cmd = $cmd." ".$x;

View File

@ -30,7 +30,7 @@
$work->install($project);
$project->start_feeder();
$project->start_make_work();
$project->start_make_work($work);
$host->run("");
//$project->stop();

View File

@ -104,15 +104,9 @@ int sign_executable(char* path, char* signature_text) {
DATA_BLOCK signature;
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
R_RSA_PRIVATE_KEY code_sign_key;
FILE* fkey = fopen(code_sign_keyfile, "r");
if (!fkey) {
fprintf(stderr, "add: can't open key file (%s)\n", code_sign_keyfile);
exit(1);
}
retval = scan_key_hex(fkey, (KEY*)&code_sign_key, sizeof(code_sign_key));
fclose(fkey);
retval = read_key_file(code_sign_keyfile, code_sign_key);
if (retval) {
fprintf(stderr, "add: can't parse key\n");
fprintf(stderr, "add: can't read key\n");
exit(1);
}
signature.data = signature_buf;

View File

@ -53,6 +53,22 @@ int read_filename(char* path, char* buf) {
return retval;
}
int read_key_file(char* keyfile, R_RSA_PRIVATE_KEY& key) {
int retval;
FILE* fkey = fopen(keyfile, "r");
if (!fkey) {
fprintf(stderr, "can't open key file (%s)\n", keyfile);
return -1;
}
retval = scan_key_hex(fkey, (KEY*)&key, sizeof(key));
fclose(fkey);
if (retval) {
fprintf(stderr, "can't parse key\n");
return -1;
}
return 0;
}
// replace INFILE_x with filename from array,
// MD5_x with checksum of file,
//
@ -125,7 +141,8 @@ static int process_wu_template(
}
int create_result(
WORKUNIT& wu, char* result_template_filename, int i, R_RSA_PRIVATE_KEY& key,
WORKUNIT& wu, char* result_template_filename,
char* result_name_suffix, R_RSA_PRIVATE_KEY& key,
char* upload_url, char* download_url
) {
RESULT r;
@ -142,7 +159,7 @@ int create_result(
r.workunitid = wu.id;
r.state = RESULT_STATE_UNSENT;
r.validate_state = VALIDATE_STATE_INITIAL;
sprintf(r.name, "%s_%d", wu.name, i);
sprintf(r.name, "%s_%s", wu.name, result_name_suffix);
sprintf(base_outfile_name, "%s_", r.name);
result_template_file = fopen(result_template_filename, "r");
@ -177,6 +194,7 @@ int create_work(
char* upload_url, char* download_url
) {
int i, retval;
char suffix[256];
assert(wu_template!=NULL);
assert(result_template_file!=NULL);
assert(nresults>=0);
@ -207,8 +225,10 @@ int create_work(
if (!wu.dynamic_results) {
for (i=0; i<nresults; i++) {
sprintf(suffix, "%d", i);
create_result(
wu, result_template_file, i, key, upload_url, download_url
wu, result_template_file, suffix,
key, upload_url, download_url
);
}
}

View File

@ -29,6 +29,13 @@ extern int process_result_template(
extern int read_file(FILE*, char* buf);
extern int read_filename(char* path, char* buf);
extern int read_key_file(char* keyfile, R_RSA_PRIVATE_KEY& key);
extern int create_result(
WORKUNIT& wu, char* result_template_filename, char* suffix,
R_RSA_PRIVATE_KEY& key, char* upload_url, char* download_url
);
extern int create_work(
WORKUNIT& wu,
char* wu_template,
@ -41,5 +48,3 @@ extern int create_work(
char* upload_url,
char* download_url
);
extern int grant_credit(int resultid, double cobblestones);

View File

@ -62,8 +62,6 @@ int main(int argc, char** argv) {
char download_dir[256], db_name[256], db_passwd[256];
char upload_url[256], download_url[256];
srand(time(NULL));
strcpy(wu_template_file, "");
strcpy(result_template_file, "");
strcpy(app.name, "");
strcpy(db_passwd, "");
@ -74,8 +72,7 @@ int main(int argc, char** argv) {
memset(&wu, 0, sizeof(wu));
while (i < argc) {
if (!strcmp(argv[i], "-appname")) {
i++;
strcpy(app.name, argv[i]);
strcpy(app.name, argv[++i]);
} else if (!strcmp(argv[i], "-db_name")) {
strcpy(db_name, argv[++i]);
} else if (!strcmp(argv[i], "-db_passwd")) {
@ -87,37 +84,25 @@ int main(int argc, char** argv) {
} else if (!strcmp(argv[i], "-download_dir")) {
strcpy(download_dir, argv[++i]);
} else if (!strcmp(argv[i], "-wu_name")) {
i++;
strcpy(wu.name, argv[i]);
strcpy(wu.name, argv[++i]);
} else if (!strcmp(argv[i], "-wu_template")) {
i++;
strcpy(wu_template_file, argv[i]);
strcpy(wu_template_file, argv[++i]);
} else if (!strcmp(argv[i], "-result_template")) {
i++;
strcpy(result_template_file, argv[i]);
strcpy(result_template_file, argv[++i]);
} else if (!strcmp(argv[i], "-dynamic_results")) {
wu.dynamic_results = true;
} else if (!strcmp(argv[i], "-nresults")) {
i++;
nresults = atoi(argv[i]);
nresults = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_fpops")) {
i++;
wu.rsc_fpops = atof(argv[i]);
wu.rsc_fpops = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_iops")) {
i++;
wu.rsc_iops = atof(argv[i]);
wu.rsc_iops = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_memory")) {
i++;
wu.rsc_memory = atof(argv[i]);
wu.rsc_memory = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_disk")) {
i++;
wu.rsc_disk = atof(argv[i]);
wu.rsc_disk = atof(argv[++i]);
} else if (!strcmp(argv[i], "-keyfile")) {
i++;
strcpy(keyfile, argv[i]);
} else if (!strcmp(argv[i], "-wu_name_rand")) {
i++;
sprintf(wu.name, "%s_%d", argv[i], rand());
strcpy(keyfile, argv[++i]);
} else {
infiles = argv+i;
ninfiles = argc - i;
@ -156,16 +141,9 @@ int main(int argc, char** argv) {
wu.appid = app.id;
FILE* fkey = fopen(keyfile, "r");
if (!fkey) {
fprintf(stderr, "create_work: can't open key file (%s)\n", keyfile);
exit(1);
}
rewind(fkey);
retval = scan_key_hex(fkey, (KEY*)&key, sizeof(key));
fclose(fkey);
retval = read_key_file(keyfile, key);
if (retval) {
fprintf(stderr, "create_work: can't parse key\n");
fprintf(stderr, "create_work: can't read key");
exit(1);
}

View File

@ -18,11 +18,11 @@
//
// macro-substitute a result template file:
// - replace OUTFILE_x with base_filename_x,
// - WU_NAME with WU name
// - RESULT_NAME with result name
// - replace OUTFILE_x with base_filename_x, etc.
// - At the end of every <file_info> element, add a signature
// of its contents up to that point.
//
// TODO - have this work in memory instead of using disk files
#include <string.h>
#include <stdlib.h>