Browse Source

added code for second eviction of each retrieval

Boyoung- 9 years ago
parent
commit
7ba95d44c1
3 changed files with 166 additions and 36 deletions
  1. 84 0
      src/protocols/Access.java
  2. 50 19
      src/protocols/Retrieve.java
  3. 32 17
      src/protocols/precomputation/PreRetrieve.java

+ 84 - 0
src/protocols/Access.java

@@ -207,6 +207,90 @@ public class Access extends Protocol {
 		return outaccess;
 	}
 
+	public OutAccess runE2(Tree OTi, Timer timer) {
+		timer.start(pid, M.online_comp);
+
+		// step 0: get Li from C
+		byte[] Li = new byte[0];
+		timer.start(pid, M.online_read);
+		if (OTi.getTreeIndex() > 0)
+			Li = con2.read();
+		timer.stop(pid, M.online_read);
+
+		// step 1
+		Bucket[] pathBuckets = OTi.getBucketsOnPath(Li);
+		Tuple[] pathTuples = Bucket.bucketsToTuples(pathBuckets);
+
+		// step 5
+		Tuple Ti = null;
+		if (OTi.getTreeIndex() == 0)
+			Ti = pathTuples[0];
+		else {
+			Ti = new Tuple(1, OTi.getNBytes(), OTi.getLBytes(), OTi.getABytes(), Crypto.sr);
+			Ti.setF(new byte[1]);
+		}
+
+		OutAccess outaccess = new OutAccess(Li, null, null, null, null, Ti, pathTuples);
+
+		timer.stop(pid, M.online_comp);
+		return outaccess;
+	}
+
+	public byte[] runD2(Tree OTi, Timer timer) {
+		timer.start(pid, M.online_comp);
+
+		// step 0: get Li from C
+		byte[] Li = new byte[0];
+		timer.start(pid, M.online_read);
+		if (OTi.getTreeIndex() > 0)
+			Li = con2.read();
+		timer.stop(pid, M.online_read);
+
+		// step 1
+		Bucket[] pathBuckets = OTi.getBucketsOnPath(Li);
+		Tuple[] pathTuples = Bucket.bucketsToTuples(pathBuckets);
+
+		// step 2
+		timer.start(pid, M.online_write);
+		con2.write(pid, pathTuples);
+		timer.stop(pid, M.online_write);
+
+		timer.stop(pid, M.online_comp);
+		return Li;
+	}
+
+	public OutAccess runC2(Metadata md, int treeIndex, byte[] Li, Timer timer) {
+		timer.start(pid, M.online_comp);
+
+		// step 0: send Li to E and D
+		timer.start(pid, M.online_write);
+		if (treeIndex > 0) {
+			con1.write(Li);
+			con2.write(Li);
+		}
+		timer.stop(pid, M.online_write);
+
+		// step 2
+		timer.start(pid, M.online_read);
+		Tuple[] pathTuples = con2.readObject();
+		timer.stop(pid, M.online_read);
+
+		// step 5
+		Tuple Ti = null;
+		if (treeIndex == 0) {
+			Ti = pathTuples[0];
+		} else {
+			Ti = new Tuple(1, md.getNBytesOfTree(treeIndex), md.getLBytesOfTree(treeIndex),
+					md.getABytesOfTree(treeIndex), Crypto.sr);
+			Ti.setF(new byte[1]);
+		}
+
+		OutAccess outaccess = new OutAccess(Li, null, Ti, pathTuples, null, null, null);
+
+		timer.stop(pid, M.online_comp);
+		return outaccess;
+	}
+
 	// for testing correctness
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {

+ 50 - 19
src/protocols/Retrieve.java

@@ -27,40 +27,58 @@ public class Retrieve extends Protocol {
 		super(con1, con2);
 	}
 
-	public OutAccess runE(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, int h, Timer timer) {
+	public OutAccess runE(PreData[] predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, int h, Timer timer) {
+		// 1st eviction
 		Access access = new Access(con1, con2);
 		Reshuffle reshuffle = new Reshuffle(con1, con2);
 		PostProcessT postprocesst = new PostProcessT(con1, con2);
 		UpdateRoot updateroot = new UpdateRoot(con1, con2);
 		Eviction eviction = new Eviction(con1, con2);
 
-		OutAccess outaccess = access.runE(predata, OTi, Ni, Nip1_pr, timer);
-		Tuple[] path = reshuffle.runE(predata, outaccess.E_P, OTi.getTreeIndex() == 0, timer);
-		Tuple Ti = postprocesst.runE(predata, outaccess.E_Ti, OTi.getTreeIndex() == h - 1, timer);
+		OutAccess outaccess = access.runE(predata[0], OTi, Ni, Nip1_pr, timer);
+		Tuple[] path = reshuffle.runE(predata[0], outaccess.E_P, OTi.getTreeIndex() == 0, timer);
+		Tuple Ti = postprocesst.runE(predata[0], outaccess.E_Ti, OTi.getTreeIndex() == h - 1, timer);
 		Tuple[] root = Arrays.copyOfRange(path, 0, OTi.getStashSize());
-		root = updateroot.runE(predata, OTi.getTreeIndex() == 0, outaccess.Li, root, Ti, timer);
+		root = updateroot.runE(predata[0], OTi.getTreeIndex() == 0, outaccess.Li, root, Ti, timer);
 		System.arraycopy(root, 0, path, 0, root.length);
-		eviction.runE(predata, OTi.getTreeIndex() == 0, outaccess.Li,
+		eviction.runE(predata[0], OTi.getTreeIndex() == 0, outaccess.Li,
 				OTi.getTreeIndex() == 0 ? new Tuple[] { Ti } : path, OTi, timer);
 
+		// 2nd eviction
+		OutAccess outaccess2 = access.runE2(OTi, timer);
+		Tuple[] path2 = outaccess2.E_P;
+		Tuple Ti2 = outaccess2.E_Ti;
+		Tuple[] root2 = Arrays.copyOfRange(path2, 0, OTi.getStashSize());
+		root2 = updateroot.runE(predata[1], OTi.getTreeIndex() == 0, outaccess2.Li, root2, Ti2, timer);
+		System.arraycopy(root2, 0, path2, 0, root2.length);
+		eviction.runE(predata[1], OTi.getTreeIndex() == 0, outaccess2.Li,
+				OTi.getTreeIndex() == 0 ? new Tuple[] { Ti2 } : path2, OTi, timer);
+
 		return outaccess;
 	}
 
-	public void runD(PreData predata, Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer timer) {
+	public void runD(PreData predata[], Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer timer) {
+		// 1st eviction
 		Access access = new Access(con1, con2);
 		Reshuffle reshuffle = new Reshuffle(con1, con2);
 		PostProcessT postprocesst = new PostProcessT(con1, con2);
 		UpdateRoot updateroot = new UpdateRoot(con1, con2);
 		Eviction eviction = new Eviction(con1, con2);
 
-		byte[] Li = access.runD(predata, OTi, Ni, Nip1_pr, timer);
+		byte[] Li = access.runD(predata[0], OTi, Ni, Nip1_pr, timer);
 		reshuffle.runD();
 		postprocesst.runD();
-		updateroot.runD(predata, OTi.getTreeIndex() == 0, Li, OTi.getW(), timer);
-		eviction.runD(predata, OTi.getTreeIndex() == 0, Li, OTi, timer);
+		updateroot.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi.getW(), timer);
+		eviction.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi, timer);
+
+		// 2nd eviction
+		byte[] Li2 = access.runD2(OTi, timer);
+		updateroot.runD(predata[1], OTi.getTreeIndex() == 0, Li2, OTi.getW(), timer);
+		eviction.runD(predata[1], OTi.getTreeIndex() == 0, Li2, OTi, timer);
 	}
 
-	public OutAccess runC(PreData predata, Metadata md, int ti, byte[] Li, int h, Timer timer) {
+	public OutAccess runC(PreData[] predata, Metadata md, int ti, byte[] Li, int h, Timer timer) {
+		// 1st eviction
 		Access access = new Access(con1, con2);
 		Reshuffle reshuffle = new Reshuffle(con1, con2);
 		PostProcessT postprocesst = new PostProcessT(con1, con2);
@@ -68,12 +86,24 @@ public class Retrieve extends Protocol {
 		Eviction eviction = new Eviction(con1, con2);
 
 		OutAccess outaccess = access.runC(md, ti, Li, timer);
-		Tuple[] path = reshuffle.runC(predata, outaccess.C_P, ti == 0, timer);
-		Tuple Ti = postprocesst.runC(predata, outaccess.C_Ti, Li, outaccess.C_Lip1, outaccess.C_j2, ti == h - 1, timer);
+		Tuple[] path = reshuffle.runC(predata[0], outaccess.C_P, ti == 0, timer);
+		Tuple Ti = postprocesst.runC(predata[0], outaccess.C_Ti, Li, outaccess.C_Lip1, outaccess.C_j2, ti == h - 1,
+				timer);
 		Tuple[] root = Arrays.copyOfRange(path, 0, md.getStashSizeOfTree(ti));
-		root = updateroot.runC(predata, ti == 0, root, Ti, timer);
+		root = updateroot.runC(predata[0], ti == 0, root, Ti, timer);
 		System.arraycopy(root, 0, path, 0, root.length);
-		eviction.runC(predata, ti == 0, ti == 0 ? new Tuple[] { Ti } : path, md.getLBitsOfTree(ti) + 1,
+		eviction.runC(predata[0], ti == 0, ti == 0 ? new Tuple[] { Ti } : path, md.getLBitsOfTree(ti) + 1,
+				md.getStashSizeOfTree(ti), md.getW(), timer);
+
+		// 2nd eviction
+		byte[] Li2 = Util.nextBytes(md.getLBytesOfTree(ti), Crypto.sr);
+		OutAccess outaccess2 = access.runC2(md, ti, Li2, timer);
+		Tuple[] path2 = outaccess2.C_P;
+		Tuple Ti2 = outaccess2.C_Ti;
+		Tuple[] root2 = Arrays.copyOfRange(path2, 0, md.getStashSizeOfTree(ti));
+		root2 = updateroot.runC(predata[1], ti == 0, root2, Ti2, timer);
+		System.arraycopy(root2, 0, path2, 0, root2.length);
+		eviction.runC(predata[1], ti == 0, ti == 0 ? new Tuple[] { Ti2 } : path2, md.getLBitsOfTree(ti) + 1,
 				md.getStashSizeOfTree(ti), md.getW(), timer);
 
 		return outaccess;
@@ -115,10 +145,11 @@ public class Retrieve extends Protocol {
 				System.out.println("N=" + BigInteger.valueOf(N).toString(2));
 
 				System.out.print("Precomputation... ");
-				PreData[] predata = new PreData[numTrees];
+				PreData[][] predata = new PreData[numTrees][2];
 				PreRetrieve preretrieve = new PreRetrieve(con1, con2);
 				for (int ti = 0; ti < numTrees; ti++) {
-					predata[ti] = new PreData();
+					predata[ti][0] = new PreData();
+					predata[ti][1] = new PreData();
 
 					if (party == Party.Eddie) {
 						ete_off.start();
@@ -127,12 +158,12 @@ public class Retrieve extends Protocol {
 
 					} else if (party == Party.Debbie) {
 						ete_off.start();
-						preretrieve.runD(predata[ti], md, ti, ti == 0 ? null : predata[ti - 1], timer);
+						preretrieve.runD(predata[ti], md, ti, ti == 0 ? null : predata[ti - 1][0], timer);
 						ete_off.stop();
 
 					} else if (party == Party.Charlie) {
 						ete_off.start();
-						preretrieve.runC(predata[ti], md, ti, ti == 0 ? null : predata[ti - 1], timer);
+						preretrieve.runC(predata[ti], md, ti, ti == 0 ? null : predata[ti - 1][0], timer);
 						ete_off.stop();
 
 					} else {

+ 32 - 17
src/protocols/precomputation/PreRetrieve.java

@@ -15,7 +15,8 @@ public class PreRetrieve extends Protocol {
 
 	// TODO: not all protocols run on all trees (remove unnecessary precomp)
 
-	public void runE(PreData predata, Metadata md, int ti, Timer timer) {
+	public void runE(PreData[] predata, Metadata md, int ti, Timer timer) {
+		// 1st eviction
 		PreAccess preaccess = new PreAccess(con1, con2);
 		PreReshuffle prereshuffle = new PreReshuffle(con1, con2);
 		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
@@ -26,14 +27,19 @@ public class PreRetrieve extends Protocol {
 		int[] tupleParam = new int[] { ti == 0 ? 0 : 1, md.getNBytesOfTree(ti), md.getLBytesOfTree(ti),
 				md.getABytesOfTree(ti) };
 
-		preaccess.runE(predata, md.getTwoTauPow(), numTuples, tupleParam, timer);
-		prereshuffle.runE(predata, timer);
-		prepostprocesst.runE(predata, timer);
-		preupdateroot.runE(predata, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), timer);
-		preeviction.runE(predata, ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), timer);
+		preaccess.runE(predata[0], md.getTwoTauPow(), numTuples, tupleParam, timer);
+		prereshuffle.runE(predata[0], timer);
+		prepostprocesst.runE(predata[0], timer);
+		preupdateroot.runE(predata[0], md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), timer);
+		preeviction.runE(predata[0], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), timer);
+
+		// 2nd eviction
+		preupdateroot.runE(predata[1], md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), timer);
+		preeviction.runE(predata[1], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), timer);
 	}
 
-	public void runD(PreData predata, Metadata md, int ti, PreData prev, Timer timer) {
+	public void runD(PreData[] predata, Metadata md, int ti, PreData prev, Timer timer) {
+		// 1st eviction
 		PreAccess preaccess = new PreAccess(con1, con2);
 		PreReshuffle prereshuffle = new PreReshuffle(con1, con2);
 		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
@@ -43,14 +49,19 @@ public class PreRetrieve extends Protocol {
 		int[] tupleParam = new int[] { ti == 0 ? 0 : 1, md.getNBytesOfTree(ti), md.getLBytesOfTree(ti),
 				md.getABytesOfTree(ti) };
 
-		preaccess.runD(predata, timer);
-		prereshuffle.runD(predata, tupleParam, timer);
-		prepostprocesst.runD(predata, prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), md.getTau(), timer);
-		preupdateroot.runD(predata, md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), tupleParam, timer);
-		preeviction.runD(predata, ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), tupleParam, timer);
+		preaccess.runD(predata[0], timer);
+		prereshuffle.runD(predata[0], tupleParam, timer);
+		prepostprocesst.runD(predata[0], prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), md.getTau(), timer);
+		preupdateroot.runD(predata[0], md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), tupleParam, timer);
+		preeviction.runD(predata[0], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), tupleParam, timer);
+
+		// 2nd eviction
+		preupdateroot.runD(predata[1], md.getStashSizeOfTree(ti), md.getLBitsOfTree(ti), tupleParam, timer);
+		preeviction.runD(predata[1], ti == 0, md.getLBitsOfTree(ti) + 1, md.getW(), tupleParam, timer);
 	}
 
-	public void runC(PreData predata, Metadata md, int ti, PreData prev, Timer timer) {
+	public void runC(PreData[] predata, Metadata md, int ti, PreData prev, Timer timer) {
+		// 1st eviction
 		PreAccess preaccess = new PreAccess(con1, con2);
 		PreReshuffle prereshuffle = new PreReshuffle(con1, con2);
 		PrePostProcessT prepostprocesst = new PrePostProcessT(con1, con2);
@@ -58,10 +69,14 @@ public class PreRetrieve extends Protocol {
 		PreEviction preeviction = new PreEviction(con1, con2);
 
 		preaccess.runC(timer);
-		prereshuffle.runC(predata, timer);
-		prepostprocesst.runC(predata, prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), timer);
-		preupdateroot.runC(predata, timer);
-		preeviction.runC(predata, ti == 0, timer);
+		prereshuffle.runC(predata[0], timer);
+		prepostprocesst.runC(predata[0], prev, md.getLBytesOfTree(ti), md.getAlBytesOfTree(ti), timer);
+		preupdateroot.runC(predata[0], timer);
+		preeviction.runC(predata[0], ti == 0, timer);
+
+		// 2nd eviction
+		preupdateroot.runC(predata[1], timer);
+		preeviction.runC(predata[1], ti == 0, timer);
 	}
 
 	@Override