mirror of https://github.com/BOINC/boinc.git
- sample bitwise validator: make it work for binary files
fixes #886, #887 svn path=/trunk/boinc/; revision=17966
This commit is contained in:
parent
59f57dc6e6
commit
ad6a61a3a6
|
@ -4260,3 +4260,13 @@ Rom 30 Apr 2009
|
||||||
|
|
||||||
David 1 May 2009
|
David 1 May 2009
|
||||||
- removed outdated translation files; updated template
|
- removed outdated translation files; updated template
|
||||||
|
|
||||||
|
David 1 May 2009
|
||||||
|
- sample bitwise validator: make it work for binary files
|
||||||
|
fixes #886, #887
|
||||||
|
|
||||||
|
lib/
|
||||||
|
md5_file.h
|
||||||
|
util.cpp,h
|
||||||
|
sched/
|
||||||
|
sample_bitwise_validator.cpp
|
||||||
|
|
|
@ -28,8 +28,7 @@ extern int md5_block(const unsigned char* data, int nbytes, char* output);
|
||||||
|
|
||||||
extern std::string md5_string(const unsigned char* data, int nbytes);
|
extern std::string md5_string(const unsigned char* data, int nbytes);
|
||||||
|
|
||||||
inline std::string md5_string(std::string const& data)
|
inline std::string md5_string(std::string const& data) {
|
||||||
{
|
|
||||||
return md5_string((const unsigned char*) data.c_str(), (int)data.size());
|
return md5_string((const unsigned char*) data.c_str(), (int)data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -306,8 +306,8 @@ void boinc_crash() {
|
||||||
|
|
||||||
// read file (at most max_len chars, if nonzero) into malloc'd buf
|
// read file (at most max_len chars, if nonzero) into malloc'd buf
|
||||||
//
|
//
|
||||||
int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
|
int read_file_malloc(const char* path, char*& buf, size_t max_len, bool tail) {
|
||||||
int retval, isize;
|
int retval;
|
||||||
double size;
|
double size;
|
||||||
|
|
||||||
retval = file_size(path, size);
|
retval = file_size(path, size);
|
||||||
|
@ -328,7 +328,7 @@ int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
|
||||||
size = max_len;
|
size = max_len;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
isize = (int) size;
|
size_t isize = size;
|
||||||
buf = (char*)malloc(isize+1);
|
buf = (char*)malloc(isize+1);
|
||||||
size_t n = fread(buf, 1, isize, f);
|
size_t n = fread(buf, 1, isize, f);
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
|
@ -338,7 +338,7 @@ int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
|
||||||
|
|
||||||
// read file (at most max_len chars, if nonzero) into string
|
// read file (at most max_len chars, if nonzero) into string
|
||||||
//
|
//
|
||||||
int read_file_string(const char* path, string& result, int max_len, bool tail) {
|
int read_file_string(const char* path, string& result, size_t max_len, bool tail) {
|
||||||
result.erase();
|
result.erase();
|
||||||
int retval;
|
int retval;
|
||||||
char* buf;
|
char* buf;
|
||||||
|
|
14
lib/util.h
14
lib/util.h
|
@ -70,9 +70,19 @@ extern int boinc_calling_thread_cpu_time(double&);
|
||||||
//
|
//
|
||||||
extern void mysql_timestamp(double, char*);
|
extern void mysql_timestamp(double, char*);
|
||||||
|
|
||||||
|
// fake a crash
|
||||||
|
//
|
||||||
extern void boinc_crash();
|
extern void boinc_crash();
|
||||||
extern int read_file_malloc(const char* path, char*&, int max_len=0, bool tail=false);
|
|
||||||
extern int read_file_string(const char* path, std::string&, int max_len=0, bool tail=false);
|
// read files into memory.
|
||||||
|
// Use only for non-binary files; returns null-terminated string.
|
||||||
|
//
|
||||||
|
extern int read_file_malloc(
|
||||||
|
const char* path, char*& result, size_t max_len=0, bool tail=false
|
||||||
|
);
|
||||||
|
extern int read_file_string(
|
||||||
|
const char* path, std::string& result, size_t max_len=0, bool tail=false
|
||||||
|
);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// A sample validator that grants credit if the majority of results are
|
// A sample validator that requires a majority of results to be
|
||||||
// bitwise identical.
|
// bitwise identical.
|
||||||
// This is useful only if either
|
// This is useful only if either
|
||||||
// 1) your application does no floating-point math, or
|
// 1) your application does no floating-point math, or
|
||||||
|
@ -31,24 +31,15 @@
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
struct FILE_CKSUM {
|
|
||||||
string md5sum;
|
|
||||||
|
|
||||||
FILE_CKSUM(string& filedata) {
|
|
||||||
md5sum = md5_string(filedata);
|
|
||||||
}
|
|
||||||
~FILE_CKSUM(){}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FILE_CKSUM_LIST {
|
struct FILE_CKSUM_LIST {
|
||||||
vector<FILE_CKSUM> files;
|
vector<string> files; // list of MD5s of files
|
||||||
~FILE_CKSUM_LIST(){}
|
~FILE_CKSUM_LIST(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool files_match(FILE_CKSUM_LIST& f1, FILE_CKSUM_LIST& f2) {
|
bool files_match(FILE_CKSUM_LIST& f1, FILE_CKSUM_LIST& f2) {
|
||||||
if (f1.files.size() != f2.files.size()) return false;
|
if (f1.files.size() != f2.files.size()) return false;
|
||||||
for (unsigned int i=0; i<f1.files.size(); i++) {
|
for (unsigned int i=0; i<f1.files.size(); i++) {
|
||||||
if (f1.files[i].md5sum != f2.files[i].md5sum) return false;
|
if (f1.files[i] != f2.files[i]) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +48,8 @@ int init_result(RESULT& result, void*& data) {
|
||||||
int retval;
|
int retval;
|
||||||
FILE_CKSUM_LIST* fcl = new FILE_CKSUM_LIST;
|
FILE_CKSUM_LIST* fcl = new FILE_CKSUM_LIST;
|
||||||
vector<FILE_INFO> files;
|
vector<FILE_INFO> files;
|
||||||
|
char md5_buf[MD5_LEN];
|
||||||
|
double nbytes;
|
||||||
|
|
||||||
retval = get_output_file_infos(result, files);
|
retval = get_output_file_infos(result, files);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
|
@ -67,14 +60,14 @@ int init_result(RESULT& result, void*& data) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
string filedata;
|
|
||||||
for (unsigned int i=0; i<files.size(); i++) {
|
for (unsigned int i=0; i<files.size(); i++) {
|
||||||
FILE_INFO& fi = files[i];
|
FILE_INFO& fi = files[i];
|
||||||
if (fi.no_validate) continue;
|
if (fi.no_validate) continue;
|
||||||
retval = read_file_string(fi.path.c_str(), filedata);
|
retval = md5_file(fi.path.c_str(), md5_buf, nbytes);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
if (fi.optional) {
|
if (fi.optional) {
|
||||||
filedata = "";
|
strcpy(md5_buf, "");
|
||||||
|
// indicate file is missing; not the same as md5("")
|
||||||
} else {
|
} else {
|
||||||
log_messages.printf(MSG_CRITICAL,
|
log_messages.printf(MSG_CRITICAL,
|
||||||
"[RESULT#%d %s] Couldn't open %s\n",
|
"[RESULT#%d %s] Couldn't open %s\n",
|
||||||
|
@ -83,8 +76,7 @@ int init_result(RESULT& result, void*& data) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FILE_CKSUM fc(filedata);
|
fcl->files.push_back(string(md5_buf));
|
||||||
fcl->files.push_back(fc);
|
|
||||||
}
|
}
|
||||||
data = (void*) fcl;
|
data = (void*) fcl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue