Skip to content

Commit

Permalink
Adding gradle speed boosts, and added a place where to time how long …
Browse files Browse the repository at this point in the history
…it takes to run comparison
  • Loading branch information
AndrewQuijano committed May 7, 2024
1 parent 77ffe56 commit 0e70354
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 20 deletions.
33 changes: 29 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ java {
}

dependencies {
implementation 'junit:junit:4.13.1'
implementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0-M1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'

Expand Down Expand Up @@ -49,14 +49,39 @@ gradle.projectsEvaluated {
}
}


jacocoTestReport {
reports {
xml.required=true
html.required=true
if (project.hasProperty("createReports")) {
xml.required = true
html.required = true
}
else {
html.required = false
xml.required = false
}
}
}

tasks.withType(JavaCompile).configureEach {
options.fork = true
options.incremental = true
}

tasks.withType(Test).configureEach {
if (project.hasProperty("createReports")) {
reports.html.required = true
reports.junitXml.required = true
}
else {
reports.html.required = false
reports.junitXml.required = false
}
}

clean {
delete 'logs/*.log'
}

check.dependsOn jacocoTestReport

application {
Expand Down
31 changes: 31 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Project-wide Gradle settings.
# View this guide for faster builds
# https://docs.gradle.org/current/userguide/performance.html

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

org.gradle.caching=true
org.gradle.configuration-cache=true
13 changes: 8 additions & 5 deletions src/main/java/CleartextPathsComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class CleartextPathsComparison {
public static BigInteger maxBigInt(BigInteger a, BigInteger b) {
if (a.compareTo(b) < 0) {
return b;
} else {
}
else {
return a;
}

Expand All @@ -28,15 +29,15 @@ public static BigInteger maxBigInt(BigInteger a, BigInteger b) {
public static BigInteger minBigInt(BigInteger a, BigInteger b) {
if (a.compareTo(b) < 0) {
return a;
} else {
}
else {
return b;
}
}

//Returns true if a is greater than or equal to b
public static boolean geBigInt(BigInteger a, BigInteger b) {
return a.compareTo(b) >= 0;

}

//Returns true if a is lesser than or equal to b
Expand Down Expand Up @@ -64,9 +65,11 @@ static int orientation(BigIntPoint p, BigIntPoint q, BigIntPoint r) {

if (ans == 0) {
return 0;
} else if (ans > 0) {
}
else if (ans > 0) {
return 1;
} else {
}
else {
return 2;
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/EncryptedPathsComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class EncryptedPathsComparison {

private static final Logger logger = LogManager.getLogger(EncryptedPathsComparison.class);

public EncryptedPathsComparison(alice_joye myself) {
this.myself = myself;
}
Expand All @@ -35,7 +38,7 @@ public BigInteger encryptedMaxBigInt(BigInteger a, BigInteger b) {
}

//This method runs Protocol2 to find Min value. I could've just used Max, but it reads easier this way later on.
public BigInteger encryptedMinBigInt(BigInteger a, BigInteger b){
public BigInteger encryptedMinBigInt(BigInteger a, BigInteger b) {
boolean z = false;
try {
myself.writeInt(2);
Expand Down Expand Up @@ -105,10 +108,10 @@ public boolean encryptedOnSegment (BigIntPoint p, BigIntPoint q, BigIntPoint r)

try {
// I had to pull these out of comparison statement to work with BobThread
BigInteger u = encryptedMaxBigInt(p.x,r.x);
BigInteger v = encryptedMinBigInt(p.x,r.x);
BigInteger w = encryptedMaxBigInt(p.y,r.y);
BigInteger x = encryptedMinBigInt(p.y,r.y);
BigInteger u = encryptedMaxBigInt(p.x, r.x);
BigInteger v = encryptedMinBigInt(p.x, r.x);
BigInteger w = encryptedMaxBigInt(p.y, r.y);
BigInteger x = encryptedMinBigInt(p.y, r.y);

/*I have to run these at a time to work with BobThread. Maybe passing 4 and calling
Protocol2 4 times in BobThread would speed things up.
Expand Down Expand Up @@ -179,6 +182,7 @@ public List<Integer> encryptedWhereIntersection(List<BigIntPoint> mine, List<Big
PaillierPublicKey public_key, BigInteger encrypted_zero)
{
List<Integer> index = new ArrayList<>();
long start_wait = System.nanoTime();

// This is where I was picturing the threading going, so that the calls from these for loops can be run separately,
// My concern is that Bob might need to be able to multi-thread his part of the protocols to see proper speed gains
Expand All @@ -196,8 +200,12 @@ public List<Integer> encryptedWhereIntersection(List<BigIntPoint> mine, List<Big
myself.writeInt(0);
}
catch(IOException e) {
e.printStackTrace();
logger.fatal(e.getStackTrace());
}
long end_wait = System.nanoTime();
double wait_time = (double) (end_wait - start_wait);
wait_time = wait_time/1000000;
logger.info(String.format("[Alice] completed intersection checking %f ms", wait_time));
return index;
}
}
6 changes: 3 additions & 3 deletions src/main/java/PathsAlice.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public static void main(String[] args) {
BigInteger encrypted_zero = PaillierCipher.encrypt(0, alice.getPaillierPublicKey());

for (BigIntPoint bigIntPoint : alice_route) {
BigInteger alicex = PaillierCipher.encrypt(bigIntPoint.x.longValue(), alice.getPaillierPublicKey());
BigInteger alicey = PaillierCipher.encrypt(bigIntPoint.y.longValue(), alice.getPaillierPublicKey());
BigInteger alice_x = PaillierCipher.encrypt(bigIntPoint.x.longValue(), alice.getPaillierPublicKey());
BigInteger alice_y = PaillierCipher.encrypt(bigIntPoint.y.longValue(), alice.getPaillierPublicKey());

BigIntPoint point = new BigIntPoint(alicex, alicey);
BigIntPoint point = new BigIntPoint(alice_x, alice_y);
alices_encrypted_route.add(point);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/PathsBob.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class PathsBob {

private static int port;
private int port;
private static ServerSocket bob_socket = null;
private static Socket bob_client = null;
private KeyPair paillier;
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="File" fileName="logs/paths.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit 0e70354

Please sign in to comment.