2003-06-14 20:03:10 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-09-26 18:11:06 +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-14 20:03:10 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-06-14 20:04:45 +00:00
|
|
|
//
|
2002-09-26 18:11:06 +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-14 20:04:45 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-06-14 20:03:10 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-06-14 20:04:45 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2004-07-13 12:23:47 +00:00
|
|
|
// A sample validator that grants credit if the majority of results are
|
|
|
|
// bit-wise identical.
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2003-06-14 20:03:08 +00:00
|
|
|
#include "sched_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2004-03-17 01:26:44 +00:00
|
|
|
#include "validate_util.h"
|
2004-07-13 14:18:47 +00:00
|
|
|
#include "md5_file.h"
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2004-07-13 14:18:47 +00:00
|
|
|
|
|
|
|
class FileCache {
|
|
|
|
mutable string _md5sum;
|
|
|
|
public:
|
|
|
|
const string filedata;
|
|
|
|
|
|
|
|
FileCache(string const& filedata0) : filedata(filedata0) {}
|
|
|
|
|
|
|
|
string const md5sum() const {
|
|
|
|
if (_md5sum.empty()) {
|
|
|
|
_md5sum = md5_string(filedata);
|
|
|
|
}
|
|
|
|
return _md5sum;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator ==(FileCache const& f1, FileCache const& f2)
|
|
|
|
{
|
|
|
|
return (f1.md5sum() == f2.md5sum() &&
|
|
|
|
f1.filedata == f2.filedata);
|
|
|
|
}
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2003-08-14 00:02:15 +00:00
|
|
|
// read file into memory
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2004-06-30 18:17:21 +00:00
|
|
|
int init_result_read_file(RESULT const & result, void*& data) {
|
2002-09-25 19:40:19 +00:00
|
|
|
int retval;
|
2003-08-14 00:02:15 +00:00
|
|
|
string path;
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2003-08-14 00:02:15 +00:00
|
|
|
retval = get_output_file_path(result, path);
|
2002-09-25 19:40:19 +00:00
|
|
|
if (retval) {
|
2003-08-07 21:40:17 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-14 00:02:15 +00:00
|
|
|
"[RESULT#%d %s] check_set: can't get output filename\n",
|
|
|
|
result.id, result.name
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
2002-09-25 19:40:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2004-07-13 14:18:47 +00:00
|
|
|
string filedata;
|
|
|
|
retval = read_file_string(path.c_str(), filedata);
|
2002-09-25 19:40:19 +00:00
|
|
|
if (retval) {
|
2003-08-07 21:40:17 +00:00
|
|
|
log_messages.printf(
|
2004-04-08 08:15:23 +00:00
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
2003-08-14 00:02:15 +00:00
|
|
|
"[RESULT#%d %s] Couldn't open %s\n",
|
|
|
|
result.id, result.name, path.c_str()
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
2002-09-25 19:40:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-07-13 14:18:47 +00:00
|
|
|
FileCache *f = new FileCache(filedata);
|
|
|
|
data = (void*) f;
|
2003-08-14 00:02:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-01 17:11:14 +00:00
|
|
|
int check_pair_initialized_identical(
|
|
|
|
RESULT const& /*r1*/, void* data1,
|
|
|
|
RESULT const& /*r2*/, void* data2,
|
|
|
|
bool& match
|
|
|
|
) {
|
2004-07-13 14:18:47 +00:00
|
|
|
FileCache const* f1 = (FileCache*) data1;
|
|
|
|
FileCache const* f2 = (FileCache*) data2;
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2004-07-13 14:18:47 +00:00
|
|
|
match = (*f1 == *f2);
|
2002-09-25 19:40:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2003-09-01 17:11:14 +00:00
|
|
|
int cleanup_result_string(RESULT const& /*result*/, void* data) {
|
2004-07-13 14:18:47 +00:00
|
|
|
delete (FileCache*) data;
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if there's a strict majority under equality.
|
|
|
|
//
|
2003-09-01 17:11:14 +00:00
|
|
|
int check_set(vector<RESULT>& results, int& canonicalid, double& credit) {
|
|
|
|
return generic_check_set_majority(
|
|
|
|
results, canonicalid, credit,
|
|
|
|
init_result_read_file,
|
|
|
|
check_pair_initialized_identical,
|
|
|
|
cleanup_result_string
|
|
|
|
);
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
|
2003-09-01 17:11:14 +00:00
|
|
|
int check_pair(RESULT const& r1, RESULT const& r2, bool& match) {
|
|
|
|
return generic_check_pair(
|
|
|
|
r1, r2, match,
|
|
|
|
init_result_read_file,
|
|
|
|
check_pair_initialized_identical,
|
|
|
|
cleanup_result_string
|
|
|
|
);
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
|