Skip to content

Commit

Permalink
OK, so got a new struct to make it easier to pass down level-sites. I…
Browse files Browse the repository at this point in the history
… have no bleeping idea why client code requires level_site input stream, but at this rate, I do not care, ill worry about pass down now
  • Loading branch information
AndrewQuijano committed Jan 15, 2024
1 parent dcebb00 commit ed916fa
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/main/java/weka/finito/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ private void communicate_with_level_site(Socket level_site)
bob_joye client;

// Create I/O stream and send features
// this.feature.set_next_index(next_index);
ObjectOutputStream to_level_site = new ObjectOutputStream(level_site.getOutputStream());
ObjectInputStream from_level_site = get_ois(level_site);
to_level_site.writeObject(this.feature);
to_level_site.flush();

Expand All @@ -317,7 +319,7 @@ private void communicate_with_level_site(Socket level_site)
// I am not sure why I need this loop, but you will only need 1 comparison.
int comparison_type;
while (true) {
comparison_type = client.readInt();
comparison_type = from_level_site.readInt();
if (comparison_type == -1) {
this.classification_complete = true;
break;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/weka/finito/level_site_evaluation_thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import weka.finito.structs.level_order_site;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import static weka.finito.utils.shared.*;
Expand All @@ -19,22 +17,29 @@ public class level_site_evaluation_thread implements Runnable {
private final Socket client_socket;
private final level_order_site level_site_data;
private final features encrypted_features;
private final Socket next_level_site;

// This thread is ONLY to handle evaluations
public level_site_evaluation_thread(Socket client_socket, level_order_site level_site_data,
features encrypted_features) {
// Have encrypted copy of thresholds if not done already for all nodes in level-site
this(client_socket, level_site_data, encrypted_features, null);
}

// This thread is ONLY to handle evaluations
public level_site_evaluation_thread(Socket client_socket, level_order_site level_site_data,
features encrypted_features, Socket next_level_site) {
// Have encrypted copy of thresholds if not done already for all nodes in level-site
this.level_site_data = level_site_data;
this.client_socket = client_socket;
this.encrypted_features = encrypted_features;
this.next_level_site = next_level_site;
}

// This will run the communication with client and next level site
public final void run() {
long start_time = System.nanoTime();
alice_joye niu = new alice_joye();
ObjectInputStream ois = null;
ObjectOutputStream oos = null;
try {
niu.set_socket(client_socket);
niu.setDGKPublicKey(this.level_site_data.dgk_public_key);
Expand Down Expand Up @@ -66,7 +71,7 @@ public final void run() {
}
finally {
try {
closeConnection(oos, ois, client_socket);
closeConnection(client_socket);
} catch (IOException e) {
System.out.println("IO Exception in closing Level-Site Connection in Evaluation");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/weka/finito/level_site_server.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void run() {
this.level_site_parameters = (level_order_site) o;
// System.out.println("Level-Site received training data on Port: " + client_socket.getLocalPort());
oos.writeBoolean(true);
// Create a persistent connection to next level-site and oos to send the next stuff down
closeConnection(oos, ois, client_socket);
}
else if (o instanceof features) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/weka/finito/server.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ else if (threshold_string.equals("f") || threshold_string.equals("no")) {
}

assert node_info != null;
if (!node_info.is_leaf){
if (!node_info.is_leaf) {
NodeInfo additionalNode = null;
if (node_info.comparisonType == 1) {
additionalNode = new NodeInfo(false, node_info.getVariableName(), 6);
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/weka/finito/structs/features.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
import java.math.BigInteger;
import java.util.HashMap;

public class features implements Serializable {
public final class features implements Serializable {
private static final long serialVersionUID = 6000706455545108960L;
private String client_ip;
private int current_index;
private int next_index;

private final HashMap<String, BigIntegers> thresholds;

public features(String path, int precision, PaillierPublicKey paillier_public_key, DGKPublicKey dgk_public_key)
throws HomomorphicException, IOException {
this.client_ip = "";
this.current_index = 0;
this.next_index = 0;
this.thresholds = read_values(path, precision, paillier_public_key, dgk_public_key);
}
Expand All @@ -37,14 +35,6 @@ public void set_client_ip(String client_ip) {
this.client_ip = client_ip;
}

public int get_current_index() {
return this.current_index;
}

public void set_current_index(int current_index) {
this.current_index = current_index;
}

public int get_next_index() {
return this.next_index;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/weka/finito/structs/level_order_site.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

public final class level_order_site implements Serializable {

private static final long serialVersionUID = 575566807906351024L;
private int index = 0;
private int next_index;
Expand All @@ -24,7 +23,7 @@ public final class level_order_site implements Serializable {

private final List<NodeInfo> node_level_data = new ArrayList<>();

// Set to value to client, to let level-site d-1 know to talk to client next with answer
// Set to value to a client, to let level-site d-1 know to talk to a client next with answer
private String next_level_site = "client";

private int next_level_site_port = -1;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/weka/finito/utils/shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public static void closeConnection(ObjectOutputStream oos,
}
}

public static void closeConnection(Socket client_socket) throws IOException {
closeConnection(null, null, client_socket);
}

public static ValidatingObjectInputStream get_ois(Socket socket) throws IOException {
ValidatingObjectInputStream ois = new ValidatingObjectInputStream(socket.getInputStream());
ois.accept(
Expand Down

0 comments on commit ed916fa

Please sign in to comment.