Parcourir la source

add Reshare simulation in Eviction; still need to change XOT to 2 round version

Boyang Wei il y a 6 ans
Parent
commit
0e88944882
4 fichiers modifiés avec 140 ajouts et 51 suppressions
  1. 120 38
      src/pir/PIRRetrieve.java
  2. 4 4
      src/protocols/Eviction.java
  3. 14 8
      src/protocols/SSXOT.java
  4. 2 1
      src/util/P.java

+ 120 - 38
src/pir/PIRRetrieve.java

@@ -1,5 +1,6 @@
 package pir;
 
+import java.math.BigInteger;
 import java.util.Arrays;
 
 import communication.Communication;
@@ -20,12 +21,17 @@ import protocols.struct.Party;
 import protocols.struct.PreData;
 import protocols.struct.TwoThreeXorByte;
 import protocols.struct.TwoThreeXorInt;
+import util.M;
+import util.P;
 import util.Timer;
+import util.Util;
 
 // TODO: really FlipFlag on path, and update path in Eviction
 
 public class PIRRetrieve extends Protocol {
 
+	private int pid = P.PIRRtv;
+
 	Communication[] cons1;
 	Communication[] cons2;
 
@@ -38,8 +44,10 @@ public class PIRRetrieve extends Protocol {
 		cons2 = b;
 	}
 
-	public void runE(Metadata md, PreData predata, Tree tree_DE, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
+	public OutPIRAccess runE(Metadata md, PreData predata, Tree tree_DE, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
 			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
+		timer.start(pid, M.online_comp);
+
 		int treeIndex = tree_DE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
@@ -93,10 +101,47 @@ public class PIRRetrieve extends Protocol {
 
 		Eviction eviction = new Eviction(con1, con2);
 		eviction.runE(predata, isFirstTree, Li, path, tree_DE, timer);
+
+		// simulation of Reshare
+		timer.start(pid, M.online_write);
+		con2.write(pid, path);
+		timer.stop(pid, M.online_write);
+
+		timer.start(pid, M.online_read);
+		con2.readTupleArray(pid);
+		timer.stop(pid, M.online_read);
+
+		// second eviction sim
+		preupdateroot.runE(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), timer);
+
+		for (int i = 0; i < pathTuples; i++) {
+			path[i] = outpiracc.pathTuples_DE[i].xor(outpiracc.pathTuples_CE[i]);
+		}
+		R = Arrays.copyOfRange(path, 0, stashSize);
+		R = updateroot.runE(predata, isFirstTree, Li, R, T.DE.xor(T.CE), timer);
+		System.arraycopy(R, 0, path, 0, R.length);
+
+		preeviction.runE(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), timer);
+
+		eviction.runE(predata, isFirstTree, Li, path, tree_DE, timer);
+
+		// simulation of Reshare
+		timer.start(pid, M.online_write);
+		con2.write(pid, path);
+		timer.stop(pid, M.online_write);
+
+		timer.start(pid, M.online_read);
+		con2.readTupleArray(pid);
+		timer.stop(pid, M.online_read);
+
+		timer.stop(pid, M.online_comp);
+		return outpiracc;
 	}
 
-	public void runD(Metadata md, PreData predata, Tree tree_DE, Tree tree_CD, byte[] Li, TwoThreeXorByte L,
+	public OutPIRAccess runD(Metadata md, PreData predata, Tree tree_DE, Tree tree_CD, byte[] Li, TwoThreeXorByte L,
 			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
+		timer.start(pid, M.online_comp);
+
 		int treeIndex = tree_DE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
@@ -146,10 +191,24 @@ public class PIRRetrieve extends Protocol {
 
 		Eviction eviction = new Eviction(con1, con2);
 		eviction.runD(predata, isFirstTree, Li, tree_DE, timer);
+
+		// second eviction sim
+		preupdateroot.runD(predata, isFirstTree, stashSize, md.getLBitsOfTree(treeIndex), tupleParam, timer);
+
+		updateroot.runD(predata, isFirstTree, Li, tree_DE.getW(), timer);
+
+		preeviction.runD(predata, isFirstTree, tree_DE.getD(), tree_DE.getW(), tupleParam, timer);
+
+		eviction.runD(predata, isFirstTree, Li, tree_DE, timer);
+
+		timer.stop(pid, M.online_comp);
+		return outpiracc;
 	}
 
-	public void runC(Metadata md, PreData predata, Tree tree_CD, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
+	public OutPIRAccess runC(Metadata md, PreData predata, Tree tree_CD, Tree tree_CE, byte[] Li, TwoThreeXorByte L,
 			TwoThreeXorByte N, TwoThreeXorInt dN, Timer timer) {
+		timer.start(pid, M.online_comp);
+
 		int treeIndex = tree_CE.getTreeIndex();
 		boolean isLastTree = treeIndex == md.getNumTrees() - 1;
 		boolean isFirstTree = treeIndex == 0;
@@ -201,6 +260,39 @@ public class PIRRetrieve extends Protocol {
 
 		Eviction eviction = new Eviction(con1, con2);
 		eviction.runC(predata, isFirstTree, path, tree_CD.getD(), stashSize, tree_CD.getW(), timer);
+
+		// simulation of Reshare
+		timer.start(pid, M.online_write);
+		con1.write(pid, path);
+		timer.stop(pid, M.online_write);
+
+		timer.start(pid, M.online_read);
+		con1.readTupleArray(pid);
+		timer.stop(pid, M.online_read);
+
+		// second eviction sim
+		preupdateroot.runC(predata, isFirstTree, timer);
+
+		R = Arrays.copyOfRange(path, 0, stashSize);
+
+		R = updateroot.runC(predata, isFirstTree, R, T.CD, timer);
+		System.arraycopy(R, 0, path, 0, R.length);
+
+		preeviction.runC(predata, isFirstTree, timer);
+
+		eviction.runC(predata, isFirstTree, path, tree_CD.getD(), stashSize, tree_CD.getW(), timer);
+
+		// simulation of Reshare
+		timer.start(pid, M.online_write);
+		con1.write(pid, path);
+		timer.stop(pid, M.online_write);
+
+		timer.start(pid, M.online_read);
+		con1.readTupleArray(pid);
+		timer.stop(pid, M.online_read);
+
+		timer.stop(pid, M.online_comp);
+		return outpiracc;
 	}
 
 	@Override
@@ -245,48 +337,38 @@ public class PIRRetrieve extends Protocol {
 				byte[] Li = new byte[Llen];
 
 				if (party == Party.Eddie) {
-					this.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN, timer);
-					// OutPIRAccess out = this.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN,
-					// timer);
-					// out.j.t_D = con1.readInt();
-					// out.j.t_C = con2.readInt();
-					// out.X.CD = con1.read();
-					// int pathTuples = out.pathTuples_CE.length;
-					// int index = (out.j.t_D + out.j.s_CE) % pathTuples;
-					// byte[] X = Util.xor(Util.xor(out.X.DE, out.X.CE), out.X.CD);
-					//
+					OutPIRAccess out = this.runE(md, predata, tree_DE, tree_CE, Li, L, N, dN, timer);
+					out.j.t_D = con1.readInt();
+					out.j.t_C = con2.readInt();
+					out.X.CD = con1.read();
+					int pathTuples = out.pathTuples_CE.length;
+					int index = (out.j.t_D + out.j.s_CE) % pathTuples;
+					byte[] X = Util.xor(Util.xor(out.X.DE, out.X.CE), out.X.CD);
+
 					boolean fail = false;
-					// if (index != 0) {
-					// System.err.println(test + " " + treeIndex + ": PIRAcc test failed on KSearch
-					// index");
-					// fail = true;
-					// }
-					// if (new BigInteger(1, X).intValue() != 0) {
-					// System.err.println(test + " " + treeIndex + ": PIRAcc test failed on
-					// 3ShiftPIR X");
-					// fail = true;
-					// }
-					// if (treeIndex < md.getNumTrees() - 1 && new BigInteger(1,
-					// out.Lip1).intValue() != 0) {
-					// System.err.println(test + " " + treeIndex + ": PIRAcc test failed on
-					// 3ShiftXorPIR Lip1");
-					// fail = true;
-					// }
+					if (index != 0) {
+						System.err.println(test + " " + treeIndex + ": PIRAcc test failed on KSearch index");
+						fail = true;
+					}
+					if (new BigInteger(1, X).intValue() != 0) {
+						System.err.println(test + " " + treeIndex + ": PIRAcc test failed on 3ShiftPIR X");
+						fail = true;
+					}
+					if (treeIndex < md.getNumTrees() - 1 && new BigInteger(1, out.Lip1).intValue() != 0) {
+						System.err.println(test + " " + treeIndex + ": PIRAcc test failed on 3ShiftXorPIR Lip1");
+						fail = true;
+					}
 					if (!fail)
 						System.out.println(test + " " + treeIndex + ": PIRAcc test passed");
 
 				} else if (party == Party.Debbie) {
-					this.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN, timer);
-					// OutPIRAccess out = this.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN,
-					// timer);
-					// con1.write(out.j.t_D);
-					// con1.write(out.X.CD);
+					OutPIRAccess out = this.runD(md, predata, tree_DE, tree_CD, Li, L, N, dN, timer);
+					con1.write(out.j.t_D);
+					con1.write(out.X.CD);
 
 				} else if (party == Party.Charlie) {
-					this.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN, timer);
-					// OutPIRAccess out = this.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN,
-					// timer);
-					// con1.write(out.j.t_C);
+					OutPIRAccess out = this.runC(md, predata, tree_CD, tree_CE, Li, L, N, dN, timer);
+					con1.write(out.j.t_C);
 
 				} else {
 					throw new NoSuchPartyException(party + "");

+ 4 - 4
src/protocols/Eviction.java

@@ -127,7 +127,7 @@ public class Eviction extends Protocol {
 
 		if (firstTree) {
 			timer.start(pid, M.online_read);
-			Tuple[] originalPath = con2.readTupleArray(pid);
+			// Tuple[] originalPath = con2.readTupleArray(pid);
 			timer.stop(pid, M.online_read);
 
 			// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), new Bucket[] { new
@@ -172,7 +172,7 @@ public class Eviction extends Protocol {
 		ssxot.runD(predata, evict, timer);
 
 		timer.start(pid, M.online_read);
-		Bucket[] pathBuckets = con2.readBucketArray(pid);
+		// Bucket[] pathBuckets = con2.readBucketArray(pid);
 		timer.stop(pid, M.online_read);
 
 		// OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
@@ -183,7 +183,7 @@ public class Eviction extends Protocol {
 	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
 		if (firstTree) {
 			timer.start(pid, M.online_write);
-			con2.write(pid, originalPath);
+			// con2.write(pid, originalPath);
 			timer.stop(pid, M.online_write);
 			return;
 		}
@@ -245,7 +245,7 @@ public class Eviction extends Protocol {
 		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
 
 		timer.start(pid, M.online_write);
-		con2.write(pid, pathBuckets);
+		// con2.write(pid, pathBuckets);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 14 - 8
src/protocols/SSXOT.java

@@ -16,6 +16,8 @@ import util.P;
 import util.Timer;
 import util.Util;
 
+// TODO: change XOT to do 2 rounds and 2|path| bndw
+
 public class SSXOT extends Protocol {
 
 	private int id;
@@ -41,12 +43,14 @@ public class SSXOT extends Protocol {
 		for (int i = 0; i < m.length; i++)
 			a[i] = m[predata.ssxot_E_pi[id][i]].xor(predata.ssxot_E_r[id][i]);
 
-		timer.start(pid, M.online_write);
-		con2.write(pid, a);
-		timer.stop(pid, M.online_write);
+		// timer.start(pid, M.online_write);
+		// con2.write(pid, a);
+		// timer.stop(pid, M.online_write);
+		con2.write(a);
 
+		a = con2.readTupleArray();
 		timer.start(pid, M.online_read);
-		a = con2.readTupleArray(pid);
+		// a = con2.readTupleArray(pid);
 
 		// step 2
 		int[] j = con1.readIntArray(pid);
@@ -96,12 +100,14 @@ public class SSXOT extends Protocol {
 		for (int i = 0; i < m.length; i++)
 			a[i] = m[predata.ssxot_C_pi[id][i]].xor(predata.ssxot_C_r[id][i]);
 
-		timer.start(pid, M.online_write);
-		con1.write(pid, a);
-		timer.stop(pid, M.online_write);
+		// timer.start(pid, M.online_write);
+		// con1.write(pid, a);
+		// timer.stop(pid, M.online_write);
+		con1.write(a);
 
+		a = con1.readTupleArray();
 		timer.start(pid, M.online_read);
-		a = con1.readTupleArray(pid);
+		// a = con1.readTupleArray(pid);
 
 		// step 2
 		int[] j = con2.readIntArray(pid);

+ 2 - 1
src/util/P.java

@@ -22,8 +22,9 @@ public class P {
 	public static final int FF = 17;
 	public static final int InsLbl = 18;
 	public static final int ULiT = 19;
+	public static final int PIRRtv = 20;
 
 	public static final String[] names = { "ACC", "COT", "IOT", "PPT", "RSF", "UR", "URXOT", "EVI", "PT", "PI", "XOT",
-			"SSPIR", "SftPIR", "TSPIR", "SftXorPIR", "TSXPIR", "Shift", "FF", "InsLbl", "ULiT" };
+			"SSPIR", "SftPIR", "TSPIR", "SftXorPIR", "TSXPIR", "Shift", "FF", "InsLbl", "ULiT", "PIRRtv" };
 	public static final int size = names.length;
 }