~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to sched/sample_bitwise_validator.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
 
// A sample validator that grants credit if the majority of results are
 
18
// A sample validator that requires a majority of results to be
19
19
// bitwise identical.
20
20
// This is useful only if either
21
21
// 1) your application does no floating-point math, or
31
31
using std::string;
32
32
using std::vector;
33
33
 
34
 
struct FILE_CKSUM {
35
 
    string md5sum;
36
 
 
37
 
    FILE_CKSUM(string& filedata) {
38
 
        md5sum = md5_string(filedata);
39
 
    }
40
 
    ~FILE_CKSUM(){}
41
 
};
42
 
 
43
34
struct FILE_CKSUM_LIST {
44
 
    vector<FILE_CKSUM> files;
 
35
    vector<string> files;   // list of MD5s of files
45
36
    ~FILE_CKSUM_LIST(){}
46
37
};
47
38
 
48
39
bool files_match(FILE_CKSUM_LIST& f1, FILE_CKSUM_LIST& f2) {
49
40
    if (f1.files.size() != f2.files.size()) return false;
50
41
    for (unsigned int i=0; i<f1.files.size(); i++) {
51
 
        if (f1.files[i].md5sum != f2.files[i].md5sum) return false;
 
42
        if (f1.files[i] != f2.files[i]) return false;
52
43
    }
53
44
    return true;
54
45
}
57
48
    int retval;
58
49
    FILE_CKSUM_LIST* fcl = new FILE_CKSUM_LIST;
59
50
    vector<FILE_INFO> files;
 
51
    char md5_buf[MD5_LEN];
 
52
    double nbytes;
60
53
 
61
54
    retval = get_output_file_infos(result, files);
62
55
    if (retval) {
67
60
        return retval;
68
61
    }
69
62
 
70
 
    string filedata;
71
63
    for (unsigned int i=0; i<files.size(); i++) {
72
64
        FILE_INFO& fi = files[i];
73
65
        if (fi.no_validate) continue;
74
 
        retval = read_file_string(fi.path.c_str(), filedata);
 
66
        retval = md5_file(fi.path.c_str(), md5_buf, nbytes);
75
67
        if (retval) {
76
68
            if (fi.optional) {
77
 
                filedata = "";
 
69
                strcpy(md5_buf, "");
 
70
                    // indicate file is missing; not the same as md5("")
78
71
            } else {
79
72
                log_messages.printf(MSG_CRITICAL,
80
73
                    "[RESULT#%d %s] Couldn't open %s\n",
83
76
                return retval;
84
77
            }
85
78
        }
86
 
        FILE_CKSUM fc(filedata);
87
 
        fcl->files.push_back(fc);
 
79
        fcl->files.push_back(string(md5_buf));
88
80
    }
89
81
    data = (void*) fcl;
90
82
    return 0;
107
99
    return 0;
108
100
}
109
101
 
110
 
double compute_granted_credit(WORKUNIT& wu, vector<RESULT>& results) {
111
 
    return median_mean_credit(wu, results);
112
 
}
113
 
 
114
 
const char *BOINC_RCSID_7ab2b7189c = "$Id: sample_bitwise_validator.cpp 16069 2008-09-26 18:20:24Z davea $";
 
102
const char *BOINC_RCSID_7ab2b7189c = "$Id: sample_bitwise_validator.cpp 21735 2010-06-12 22:08:15Z davea $";