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.
36 #include "error_numbers.h"
37 #include "backend_lib.h"
41 #include "sched_config.h"
42 #include "sched_util.h"
43 #include "sched_msgs.h"
46 #define int64 long long
47 // maintain at least this many unsent results
48 #define REPLICATION_FACTOR 2
64 char name[256], path[256], query[1024];
65 const char* infiles[1];
68 // frt->do_query("SELECT lookupid, hashroutine, charset, minletters, maxletters, `index`, chainlength, hash WHERE inuse = 0 LIMIT 1;");
70 sprintf(query, "SELECT rcl.lookupid, rchl.hashroutine, rcts.charset, rcts.minletters, rcts.maxletters, rct.`index`, rcts.chainlength, rchl.hash FROM rainbowcrack_cracker_lookups rcl INNER JOIN rainbowcrack_cracker_hashlist rchl ON rchl.hashid = rcl.hashid INNER JOIN rainbowcrack_cracker_tables rct ON rcl.tableid = rct.tableid INNER JOIN rainbowcrack_cracker_tablesets rcts ON rcts.tablesetid = rct.tablesetid INNER JOIN rainbowcrack_cracker_requests rcr ON rcr.hashid = rcl.hashid WHERE rchl.password IS NULL AND hasindices = 0 AND rchl.hashid = 139192 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;
85 sprintf(query, "UPDATE rainbowcrack_cracker_lookupqueue SET inuse = 1 WHERE lookupid = %s", row[0]);
86 log_messages.printf(MSG_DEBUG, "%s\n", query);
87 retval = frt->do_query(query);
88 if(retval) return retval;
90 sprintf(query, "UPDATE rainbowcrack_cracker_lookups SET hasindices = 1 WHERE lookupid = %s", row[0]);
91 log_messages.printf(MSG_DEBUG, "%s\n", query);
92 retval = frt->do_query(query);
93 if(retval) return retval;
95 char command_line[256];
97 sprintf(command_line, "%s %s %s %s %s %s %s", row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
99 // make a unique name (for the job and its input file)
101 sprintf(name, "%s %s_%s#%s-%s_%s_%s", row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
102 // sprintf(filename, "%s.txt", row[0]);
103 log_messages.printf(MSG_DEBUG, "%s\n", name);
105 read_file_malloc("../templates/index_calculator_input_template.xml", wu_template);
106 // Fill in the job parameters
110 strcpy(wu.name, name);
111 wu.rsc_fpops_est = 1e12;
112 wu.rsc_fpops_bound = 1e14;
113 wu.rsc_memory_bound = 1e8;
114 wu.rsc_disk_bound = 1e8;
115 wu.delay_bound = 86400;
117 wu.target_nresults = 2;
118 wu.max_error_results = 8;
119 wu.max_total_results = 10;
120 wu.max_success_results = 2;
121 // Register the job with BOINC
126 "templates/output_template.xml",
127 "../templates/output_template.xml",
139 check_stop_daemons();
141 retval = count_unsent_results(n, 0);
145 int njobs = (CUSHION-n)/REPLICATION_FACTOR;
146 log_messages.printf(MSG_DEBUG,
147 "Making %d jobs\n", njobs
149 for (int i=0; i<njobs; i++) {
152 log_messages.printf(MSG_CRITICAL,
153 "can't make job: %d\n", retval
158 // Now sleep for a few seconds to let the transitioner
159 // create instances for the jobs we just created.
160 // Otherwise we could end up creating an excess of jobs.
166 int main(int argc, char** argv) {
170 for (i=1; i<argc; i++) {
171 if (!strcmp(argv[i], "-d")) {
172 log_messages.set_debug_level(atoi(argv[++i]));
174 log_messages.printf(MSG_CRITICAL,
175 "bad cmdline arg: %s", argv[i]
180 if (config.parse_file("..")) {
181 log_messages.printf(MSG_CRITICAL,
182 "can't read config file\n"
186 retval = frt->open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
188 log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
192 retval = boinc_db.open(
193 config.db_name, config.db_host, config.db_user, config.db_passwd
196 log_messages.printf(MSG_CRITICAL, "can't open db\n");
199 if (app.lookup("where name='index_calculator'")) {
200 log_messages.printf(MSG_CRITICAL, "can't find app\n");
203 if (read_file_malloc("../templates/index_calculator_input_template.xml", wu_template)) {
204 log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
208 start_time = time(0);
211 log_messages.printf(MSG_NORMAL, "Starting\n");