Ready for benchmark.
This commit is contained in:
parent
9c0fdb0cff
commit
3aeaaafdb4
|
@ -79,38 +79,38 @@ public class Driver {
|
|||
try {
|
||||
profiler.reset();
|
||||
testSendAllScheme(settings, database, profiler);
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "SendAllScheme");
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "Send_All");
|
||||
} catch (OutOfMemoryError error) {
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "SendAllScheme");
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "Send_All");
|
||||
}
|
||||
|
||||
if (numServers == 2) {
|
||||
try {
|
||||
profiler.reset();
|
||||
testXORScheme(settings, database, profiler);
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "XORScheme");
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "XOR");
|
||||
} catch (OutOfMemoryError error) {
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "XORScheme");
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "XOR");
|
||||
}
|
||||
|
||||
try {
|
||||
profiler.reset();
|
||||
testSqrtXORScheme(settings, database, profiler);
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "SqrtXORScheme");
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "Balanced_XOR");
|
||||
} catch (OutOfMemoryError error) {
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "SqrtXORScheme");
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "Balanced_XOR");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
boolean interPolySchemeShouldFuckOff = true;
|
||||
boolean interPolySchemeShouldFuckOff = false;
|
||||
if (numServers != 1 && !interPolySchemeShouldFuckOff) {
|
||||
try {
|
||||
profiler.reset();
|
||||
testInterPolyScheme(settings, database, profiler);
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "InterPolyScheme");
|
||||
reportResult(numServers, databaseSize, blockSize, profiler, "Interpolation");
|
||||
} catch (OutOfMemoryError error) {
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "InterPolyScheme");
|
||||
reportFailure(numServers, databaseSize, blockSize, "oom", "Interpolation");
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
|
|
|
@ -95,11 +95,23 @@ public class Profiler {
|
|||
return numbers;
|
||||
}
|
||||
|
||||
public int[][] clientReceive(int[][] numbers) {
|
||||
for (int[] n: numbers) {
|
||||
this.clientReceive(n);
|
||||
public boolean clientReceive(boolean bool) {
|
||||
this.received += 1;
|
||||
return bool;
|
||||
}
|
||||
|
||||
public boolean[] clientReceive(boolean[] booleans) {
|
||||
for (boolean b: booleans) {
|
||||
this.received += booleans.length;
|
||||
}
|
||||
return numbers;
|
||||
return booleans;
|
||||
}
|
||||
|
||||
public boolean[][] clientReceive(boolean[][] booleansArray) {
|
||||
for (boolean[] array: booleansArray) {
|
||||
this.clientReceive(array);
|
||||
}
|
||||
return booleansArray;
|
||||
}
|
||||
|
||||
public FieldElement clientReceive(FieldElement element) {
|
||||
|
|
|
@ -50,15 +50,6 @@ public class SqrtXORClient {
|
|||
}
|
||||
|
||||
public int[] receive(int record) {
|
||||
// TODO: This is bad - should merge with above receiveBit-method to send entire array of bits at once (like the simple XORScheme)
|
||||
int[] result = new int[settings.getBlocksize()];
|
||||
for (int i = 0; i < settings.getBlocksize(); i++) {
|
||||
result[i] = this.receiveBit(record * this.settings.getBlocksize() + i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int[] receiveBlock(int index) {
|
||||
/**
|
||||
* PLAN:
|
||||
* Divide n into sqrt(n)
|
||||
|
@ -68,33 +59,16 @@ public class SqrtXORClient {
|
|||
boolean[] S1 = selectIndexes(this.sqrtSize);
|
||||
boolean[] S2 = S1.clone();
|
||||
|
||||
int impBlock = (int) Math.floor(index/this.sqrtSize);
|
||||
S2[index % this.sqrtSize] = !S1[index % this.sqrtSize]; // Remove the index, if it's contained in S.
|
||||
int impBlock = (int) Math.floor(record/this.sqrtSize);
|
||||
S2[record % this.sqrtSize] = !S1[record % this.sqrtSize]; // Remove the index, if it's contained in S.
|
||||
|
||||
int[][] resBit1 = this.profiler.clientReceive(this.servers[0].computeBlock(this.profiler.clientSend(S1)));
|
||||
int[][] resBit2 = this.profiler.clientReceive(this.servers[1].computeBlock(this.profiler.clientSend(S2)));
|
||||
boolean[][] resBit1 = this.profiler.clientReceive(this.servers[0].computeBlock(this.profiler.clientSend(S1)));
|
||||
boolean[][] resBit2 = this.profiler.clientReceive(this.servers[1].computeBlock(this.profiler.clientSend(S2)));
|
||||
|
||||
int[] res = new int[this.settings.getBlocksize()];
|
||||
|
||||
for (int i = 0; i < this.settings.getBlocksize(); i++) {
|
||||
res[i] = ((resBit1[impBlock][i] + resBit2[impBlock][i]) % 2);
|
||||
res[i] = (resBit1[impBlock][i] ^ resBit2[impBlock][i]) ? 1 : 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PIRSettings settings = new PIRSettings(9, 2, 3);
|
||||
SqrtXORServer[] servers = new SqrtXORServer[settings.getNumServers()];
|
||||
|
||||
Database database = new ListDatabase(settings, new int[] {1,0,1,0,1,0,0,0,1,1,0,1,0,1,0,0,0,1,1,0,1,0,1,0,0,0,1});
|
||||
|
||||
for (int i = 0; i < settings.getNumServers(); i++) {
|
||||
servers[i] = new SqrtXORServer(database, settings);
|
||||
}
|
||||
SqrtXORClient client = new SqrtXORClient(settings, servers, null);
|
||||
System.out.println(Arrays.toString(client.receiveBlock(1)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ public class SqrtXORServer {
|
|||
return resList;
|
||||
}
|
||||
|
||||
public int[][] computeBlock(boolean[] indexes) {
|
||||
int[][] resList = new int[this.sqrtSize][this.settings.getBlocksize()];
|
||||
public boolean[][] computeBlock(boolean[] indexes) {
|
||||
boolean[][] resList = new boolean[this.sqrtSize][this.settings.getBlocksize()];
|
||||
for (int i = 0; i < this.sqrtSize; i++) {
|
||||
int[] tmpRes = new int[this.settings.getBlocksize()];
|
||||
boolean[] tmpRes = new boolean[this.settings.getBlocksize()];
|
||||
for (int j = 0; j < this.sqrtSize; j++) {
|
||||
try {
|
||||
if (indexes[j]) {
|
||||
|
@ -43,9 +43,7 @@ public class SqrtXORServer {
|
|||
// We then wish to loop over j*blockSize + indi
|
||||
// for j = 0; we want 0,1,2
|
||||
// for j = 1; we want 3,4,5 and so on..
|
||||
|
||||
tmpRes[indi] = (tmpRes[indi] + this.database.get(((j*this.settings.getBlocksize()) + indi)
|
||||
+ (this.sqrtSize * i))) % 2;
|
||||
tmpRes[indi] = ((tmpRes[indi] ? 1 : 0) + this.database.get(((j * this.settings.getBlocksize()) + indi) + (this.sqrtSize * i))) % 2 == 1;
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user