Ready for benchmark.
This commit is contained in:
parent
9c0fdb0cff
commit
3aeaaafdb4
|
@ -79,38 +79,38 @@ public class Driver {
|
||||||
try {
|
try {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testSendAllScheme(settings, database, profiler);
|
testSendAllScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, profiler, "SendAllScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "Send_All");
|
||||||
} catch (OutOfMemoryError error) {
|
} catch (OutOfMemoryError error) {
|
||||||
reportFailure(numServers, databaseSize, blockSize, "oom", "SendAllScheme");
|
reportFailure(numServers, databaseSize, blockSize, "oom", "Send_All");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numServers == 2) {
|
if (numServers == 2) {
|
||||||
try {
|
try {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testXORScheme(settings, database, profiler);
|
testXORScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, profiler, "XORScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "XOR");
|
||||||
} catch (OutOfMemoryError error) {
|
} catch (OutOfMemoryError error) {
|
||||||
reportFailure(numServers, databaseSize, blockSize, "oom", "XORScheme");
|
reportFailure(numServers, databaseSize, blockSize, "oom", "XOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testSqrtXORScheme(settings, database, profiler);
|
testSqrtXORScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, profiler, "SqrtXORScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "Balanced_XOR");
|
||||||
} catch (OutOfMemoryError error) {
|
} catch (OutOfMemoryError error) {
|
||||||
reportFailure(numServers, databaseSize, blockSize, "oom", "SqrtXORScheme");
|
reportFailure(numServers, databaseSize, blockSize, "oom", "Balanced_XOR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean interPolySchemeShouldFuckOff = true;
|
boolean interPolySchemeShouldFuckOff = false;
|
||||||
if (numServers != 1 && !interPolySchemeShouldFuckOff) {
|
if (numServers != 1 && !interPolySchemeShouldFuckOff) {
|
||||||
try {
|
try {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testInterPolyScheme(settings, database, profiler);
|
testInterPolyScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, profiler, "InterPolyScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "Interpolation");
|
||||||
} catch (OutOfMemoryError error) {
|
} catch (OutOfMemoryError error) {
|
||||||
reportFailure(numServers, databaseSize, blockSize, "oom", "InterPolyScheme");
|
reportFailure(numServers, databaseSize, blockSize, "oom", "Interpolation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
|
@ -95,11 +95,23 @@ public class Profiler {
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] clientReceive(int[][] numbers) {
|
public boolean clientReceive(boolean bool) {
|
||||||
for (int[] n: numbers) {
|
this.received += 1;
|
||||||
this.clientReceive(n);
|
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) {
|
public FieldElement clientReceive(FieldElement element) {
|
||||||
|
|
|
@ -50,15 +50,6 @@ public class SqrtXORClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] receive(int record) {
|
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:
|
* PLAN:
|
||||||
* Divide n into sqrt(n)
|
* Divide n into sqrt(n)
|
||||||
|
@ -68,33 +59,16 @@ public class SqrtXORClient {
|
||||||
boolean[] S1 = selectIndexes(this.sqrtSize);
|
boolean[] S1 = selectIndexes(this.sqrtSize);
|
||||||
boolean[] S2 = S1.clone();
|
boolean[] S2 = S1.clone();
|
||||||
|
|
||||||
int impBlock = (int) Math.floor(index/this.sqrtSize);
|
int impBlock = (int) Math.floor(record/this.sqrtSize);
|
||||||
S2[index % this.sqrtSize] = !S1[index % this.sqrtSize]; // Remove the index, if it's contained in S.
|
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)));
|
boolean[][] 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[][] resBit2 = this.profiler.clientReceive(this.servers[1].computeBlock(this.profiler.clientSend(S2)));
|
||||||
|
|
||||||
int[] res = new int[this.settings.getBlocksize()];
|
int[] res = new int[this.settings.getBlocksize()];
|
||||||
|
|
||||||
for (int i = 0; i < this.settings.getBlocksize(); i++) {
|
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;
|
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;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] computeBlock(boolean[] indexes) {
|
public boolean[][] computeBlock(boolean[] indexes) {
|
||||||
int[][] resList = new int[this.sqrtSize][this.settings.getBlocksize()];
|
boolean[][] resList = new boolean[this.sqrtSize][this.settings.getBlocksize()];
|
||||||
for (int i = 0; i < this.sqrtSize; i++) {
|
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++) {
|
for (int j = 0; j < this.sqrtSize; j++) {
|
||||||
try {
|
try {
|
||||||
if (indexes[j]) {
|
if (indexes[j]) {
|
||||||
|
@ -43,9 +43,7 @@ public class SqrtXORServer {
|
||||||
// We then wish to loop over j*blockSize + indi
|
// We then wish to loop over j*blockSize + indi
|
||||||
// for j = 0; we want 0,1,2
|
// for j = 0; we want 0,1,2
|
||||||
// for j = 1; we want 3,4,5 and so on..
|
// for j = 1; we want 3,4,5 and so on..
|
||||||
|
tmpRes[indi] = ((tmpRes[indi] ? 1 : 0) + this.database.get(((j * this.settings.getBlocksize()) + indi) + (this.sqrtSize * i))) % 2 == 1;
|
||||||
tmpRes[indi] = (tmpRes[indi] + this.database.get(((j*this.settings.getBlocksize()) + indi)
|
|
||||||
+ (this.sqrtSize * i))) % 2;
|
|
||||||
}
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user