diff --git a/README.md b/README.md index 8a08dc5..c6a3193 100644 --- a/README.md +++ b/README.md @@ -151,12 +151,9 @@ To get the results, access the logs as described in the previous steps for both #### Re-running with different experiments - *Case 1: Re-run with different testing set* -First, you need to edit the `client_testing_job.yaml` file to point to both the new VALUES file. -Also, you should set the environment variable `TEST_AGAIN` to `1`. +As the job created the pod, you would connect to the pod and run the modified gradle command with the other VALUES file. ```bash -# Delete job and re-run evaluation -kubectl delete -f k8/client -kubectl apply -f k8/client +kubectl exec -- bash -c "gradle run -PchooseRole=weka.finito.client --args " ``` - *Case 2: Train level-sites with new DT and new testing set* First, you need to edit the `client_testing_job.yaml` file to point to a new VALUES file. diff --git a/k8/client/client_testing_job.yaml b/k8/client/client_testing_job.yaml index fe12a1e..48e61f0 100644 --- a/k8/client/client_testing_job.yaml +++ b/k8/client/client_testing_job.yaml @@ -32,9 +32,6 @@ spec: - name: SERVER value: "ppdt-server-site-service" - - name: TEST_AGAIN - value: "0" - - name: GRADLE_USER_HOME value: "gradle_user_home" diff --git a/src/main/java/weka/finito/client.java b/src/main/java/weka/finito/client.java index ef68440..a979bdd 100644 --- a/src/main/java/weka/finito/client.java +++ b/src/main/java/weka/finito/client.java @@ -49,7 +49,7 @@ public final class client implements Runnable { private DGKPrivateKey dgk_private_key; private PaillierPrivateKey paillier_private_key; private final HashMap hashed_classification = new HashMap<>(); - private final boolean talk_to_server_site; + private boolean talk_to_server_site; private final String server_ip; private final int server_port; @@ -59,7 +59,6 @@ public static void main(String[] args) { int key_size = -1; int precision = -1; int port = -1; - int test_again = -1; String level_site_string; String server_ip; @@ -98,29 +97,21 @@ public static void main(String[] args) { System.exit(1); } - try { - test_again = Integer.parseInt(System.getenv("TEST_AGAIN")); - } catch (NumberFormatException e) { - System.out.println("No integer value for repeat provided."); - System.exit(1); - } - client test = null; if (args.length == 1) { - test = new client(key_size, args[0], level_domains, port, precision,server_ip, port, test_again == 1); + test = new client(key_size, args[0], level_domains, port, precision,server_ip, port); } else { System.out.println("Missing Testing Data set as an argument parameter"); System.exit(1); } - test.read_keys(); test.run(); System.exit(0); } - // For local host testing + // For local host testing with GitHub Actions public client(int key_size, String features_file, String [] level_site_ips, int [] level_site_ports, - int precision, String server_ip, int server_port, boolean talk_to_server_site) { + int precision, String server_ip, int server_port) { this.key_size = key_size; this.features_file = features_file; this.level_site_ips = level_site_ips; @@ -129,11 +120,11 @@ public client(int key_size, String features_file, String [] level_site_ips, int this.port = -1; this.server_ip = server_ip; this.server_port = server_port; - this.talk_to_server_site = talk_to_server_site; } + // Testing using Kubernetes public client(int key_size, String features_file, String [] level_site_ips, int port, - int precision, String server_ip, int server_port, boolean talk_to_server_site) { + int precision, String server_ip, int server_port) { this.key_size = key_size; this.features_file = features_file; this.level_site_ips = level_site_ips; @@ -142,7 +133,6 @@ public client(int key_size, String features_file, String [] level_site_ips, int this.port = port; this.server_ip = server_ip; this.server_port = server_port; - this.talk_to_server_site = talk_to_server_site; } public void generate_keys() { @@ -159,11 +149,6 @@ public void generate_keys() { paillier_public_key = (PaillierPublicKey) paillier.getPublic(); dgk_private_key = (DGKPrivateKey) dgk.getPrivate(); paillier_private_key = (PaillierPrivateKey) paillier.getPrivate(); - - //dgk_public_key.writeKey("dgk.pub"); - //paillier_public_key.writeKey("paillier.pub"); - //dgk_private_key.writeKey("dgk"); - //paillier_private_key.writeKey("paillier"); } public static String hash(String text) throws NoSuchAlgorithmException { @@ -172,11 +157,17 @@ public static String hash(String text) throws NoSuchAlgorithmException { return Base64.getEncoder().encodeToString(hash); } - private void read_keys() { - dgk_public_key = DGKPublicKey.readKey("dgk.pub"); - paillier_public_key = PaillierPublicKey.readKey("paillier.pub"); - dgk_private_key = DGKPrivateKey.readKey("dgk"); - paillier_private_key = PaillierPrivateKey.readKey("paillier"); + private boolean need_keys() { + try { + dgk_public_key = DGKPublicKey.readKey("dgk.pub"); + paillier_public_key = PaillierPublicKey.readKey("paillier.pub"); + dgk_private_key = DGKPrivateKey.readKey("dgk"); + paillier_private_key = PaillierPrivateKey.readKey("paillier"); + return false; + } + catch (RuntimeException e) { + return true; + } } // Used for set-up @@ -319,12 +310,17 @@ else if (comparison_type == 1) { // Function used to Evaluate public void run() { + this.talk_to_server_site = this.need_keys(); try { // Don't regenerate keys if you are just using a different VALUES file if (talk_to_server_site) { + System.out.println("Need to generate keys..."); generate_keys(); } + else { + System.out.println("I already read the keys from a file made from a previous run..."); + } feature = read_features(features_file, paillier_public_key, dgk_public_key, precision); @@ -379,5 +375,11 @@ public void run() { catch (Exception e) { throw new RuntimeException(e); } + + // At the end, write your keys... + dgk_public_key.writeKey("dgk.pub"); + paillier_public_key.writeKey("paillier.pub"); + dgk_private_key.writeKey("dgk"); + paillier_private_key.writeKey("paillier"); } } diff --git a/src/test/java/PrivacyTest.java b/src/test/java/PrivacyTest.java index 6c7c7d6..eb1fc69 100644 --- a/src/test/java/PrivacyTest.java +++ b/src/test/java/PrivacyTest.java @@ -26,7 +26,7 @@ public final class PrivacyTest { private String data_directory; private int server_port; private String server_ip; - + private final static String [] delete_files = {"dgk", "dgk.pub", "paillier", "paillier.pub"}; @Before public void read_properties() throws IOException { // Arguments: @@ -96,7 +96,7 @@ public static String test_case(String training_data, String features_file, int l // Create client client evaluate = new client(key_size, features_file, level_site_ips, level_site_ports, precision, - server_ip, server_port, true); + server_ip, server_port); Thread client = new Thread(evaluate); client.start(); @@ -108,7 +108,21 @@ public static String test_case(String training_data, String features_file, int l for (level_site_server levelSite : level_sites) { levelSite.stop(); } + // Be sure to delete any keys you made... + for (String file: delete_files) { + delete_file(file); + } + return evaluate.getClassification(); } + + public static void delete_file(String file_name){ + File myObj = new File(file_name); + if (myObj.delete()) { + System.out.println("Deleted the file: " + myObj.getName()); + } else { + System.out.println("Failed to delete the file."); + } + } }