- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIClient.java
More file actions
Latest commit
60 lines (50 loc) · 1.85 KB
/
Copy pathIClient.java
File metadata and controls
60 lines (50 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
packagemerkle;
importmerkle.implementation.MerkleTree;
importjava.io.File;
importjava.util.List;
importjava.util.concurrent.ThreadLocalRandom;
/**
* This is the client
* DO NOT UPLOAD THIS FILE
*/
publicabstractclassIClient {
privateIServerserver;
protectedStringmasterHash;
privateintnumberOfNodes;
/**
* This method simulates uploading a file to a server
* 1 - The file is uploaded to the server
* 2 - The merkle tree is built
* 3- The master hash is recorded
*/
IMerkleTreeuploadFile(Filefile, IServerserver) throwsException {
this.server = server;
this.server.uploadFile(file);
IMerkleTreemerkleTree = newMerkleTree();
this.masterHash = merkleTree.build(file);
this.numberOfNodes = merkleTree.getNumberOfNodes();
returnmerkleTree;
}
/**
* This method takes the number of times verification is to be run as input
* A randomly picked node is verified that many times
*/
intverifyFile(intverifyCount) throwsException {
intresult = 0;
for (inti = 0; i < verifyCount; i++) {
inttestNode = ThreadLocalRandom.current().nextInt(2, numberOfNodes);
List<IMerkleTree.Node> trace = this.server.generateResponse(testNode);
booleanmatched = verifyResponse(trace);
result += matched ? 1 : 0;
Configuration.println("Verification result for node " + testNode + " = " + matched);
}
returnresult;
}
/**
* Given the path siblings this function has to verify if
* the masterHash generated by concatenating and hashing
* level by level is the same as <i>this.masterHash</i>
* You can use <i>Configuration.hashFunction</i>
*/
protectedabstractbooleanverifyResponse(List<IMerkleTree.Node> pathSiblings) throwsException;
}