1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18 // sample_work_generator.C: an example BOINC work generator.
19 // This work generator has the following properties
20 // (you may need to change some or all of these):
22 // - Runs as a daemon, and creates an unbounded supply of work.
23 // It attempts to maintain a "cushion" of 100 unsent job instances.
24 // (your app may not work this way; e.g. you might create work in batches)
25 // - Creates work for the application "uppercase".
26 // - Creates a new input file for each job;
27 // the file (and the workunit names) contain a timestamp
28 // and sequence number, so that they're unique.
37 #include "error_numbers.h"
38 #include "backend_lib.h"
42 #include "sched_config.h"
43 #include "sched_util.h"
44 #include "sched_msgs.h"
47 #define int64 long long
48 // maintain at least this many unsent results
49 #define REPLICATION_FACTOR 2
65 char name[256], path[256], query[1024];
66 const char* infiles[1];
70 sprintf(query, "SELECT lookupid, hashroutine, charset, minletters, maxletters, `index`, hash FROM rainbowcrack_cracker_verificationqueue WHERE inuse = 0 LIMIT 1");
71 log_messages.printf(MSG_DEBUG, "%s\n", query);
72 retval = frt->do_query(query);
74 log_messages.printf(MSG_DEBUG, "Query returned %i\n", retval);
78 resp = mysql_store_result(frt->mysql);
79 if (!resp) return ERR_DB_NOT_FOUND;
80 row = mysql_fetch_row(resp);
81 mysql_free_result(resp);
82 if (!row) return ERR_DB_NOT_FOUND;
84 sprintf(query, "UPDATE rainbowcrack_cracker_verificationqueue SET inuse = 1 WHERE lookupid = %s", row[0]);
85 log_messages.printf(MSG_DEBUG, "%s\n", query);
86 retval = frt->do_query(query);
87 if(retval) return retval;
89 char command_line[256];
91 sprintf(command_line, "%s %s %s %s %s %s", row[1], row[2], row[3], row[4], row[5], row[6]);
93 // make a unique name (for the job and its input file)
95 sprintf(name, "%s_cc", row[0]);
96 retval = config.download_path(name, path);
97 if (retval) return retval;
98 log_messages.printf(MSG_DEBUG, "Path determined to be %s\n", path);
99 sprintf(filename, "/home/boincadm/chains/%s.chains", row[0]);
100 log_messages.printf(MSG_DEBUG, "Copying from %s to %s\n", filename, path);
101 retval = boinc_copy(filename, path);
102 if (retval) return retval;
103 log_messages.printf(MSG_DEBUG, "Removing old file %s\n", filename);
106 log_messages.printf(MSG_DEBUG, "%s\n", name);
108 read_file_malloc("../templates/chain_checker_input_template.xml", wu_template);
109 // Fill in the job parameters
113 strcpy(wu.name, name);
114 wu.rsc_fpops_est = 1e12;
115 wu.rsc_fpops_bound = 1e14;
116 wu.rsc_memory_bound = 1e8;
117 wu.rsc_disk_bound = 1e8;
118 wu.delay_bound = 86400;
120 wu.target_nresults = 2;
121 wu.max_error_results = 8;
122 wu.max_total_results = 10;
123 wu.max_success_results = 2;
124 // Register the job with BOINC
129 "templates/output_template.xml",
130 "../templates/output_template.xml",
142 check_stop_daemons();
144 retval = count_unsent_results(n, 0);
148 int njobs = (CUSHION-n)/REPLICATION_FACTOR;
149 log_messages.printf(MSG_DEBUG,
150 "Making %d jobs\n", njobs
152 for (int i=0; i<njobs; i++) {
155 log_messages.printf(MSG_CRITICAL,
156 "can't make job: %d\n", retval
161 // Now sleep for a few seconds to let the transitioner
162 // create instances for the jobs we just created.
163 // Otherwise we could end up creating an excess of jobs.
169 int main(int argc, char** argv) {
173 for (i=1; i<argc; i++) {
174 if (!strcmp(argv[i], "-d")) {
175 log_messages.set_debug_level(atoi(argv[++i]));
177 log_messages.printf(MSG_CRITICAL,
178 "bad cmdline arg: %s", argv[i]
183 if (config.parse_file("..")) {
184 log_messages.printf(MSG_CRITICAL,
185 "can't read config file\n"
189 retval = frt->open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
191 log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
195 retval = boinc_db.open(
196 config.db_name, config.db_host, config.db_user, config.db_passwd
199 log_messages.printf(MSG_CRITICAL, "can't open db\n");
202 if (app.lookup("where name='chain_checker'")) {
203 log_messages.printf(MSG_CRITICAL, "can't find app\n");
206 if (read_file_malloc("../templates/chain_checker_input_template.xml", wu_template)) {
207 log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
211 start_time = time(0);
214 log_messages.printf(MSG_NORMAL, "Starting\n");