Skip to content

Commit

Permalink
This cleans up my crappy static coding from a text editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed Jan 14, 2024
1 parent befb3fb commit 291b269
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
20 changes: 8 additions & 12 deletions src/main/java/weka/finito/level_site_evaluation_thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
public class level_site_evaluation_thread implements Runnable {

private final Socket client_socket;
private ObjectInputStream fromClient;
private ObjectOutputStream toClient;

private level_order_site level_site_data = null;
private final level_order_site level_site_data;
private final Hashtable<String, BigIntegers> encrypted_features = new Hashtable<>();

// This thread is ONLY to handle evaluations
Expand All @@ -42,22 +39,21 @@ public level_site_evaluation_thread(Socket client_socket, level_order_site level
public final void run() {
long start_time = System.nanoTime();
alice_joye niu = new alice_joye();
ObjectInputStream ois = new ObjectInputStream(client_socket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(client_socket.getOutputStream());

try {


ObjectInputStream ois = null;
ObjectOutputStream oos = null;
try {
ois = new ObjectInputStream(client_socket.getInputStream());
oos = new ObjectOutputStream(client_socket.getOutputStream());
niu.set_socket(client_socket);
if (this.level_site_data == null) {
toClient.writeInt(-2);
oos.writeInt(-2);
closeConnection(oos, ois, client_socket);
return;
}

niu.setDGKPublicKey(this.level_site_data.dgk_public_key);
niu.setPaillierPublicKey(this.level_site_data.paillier_public_key);
level_site_data.set_current_index(fromClient.readInt());
level_site_data.set_current_index(ois.readInt());

// Null, keep going down the tree,
// Not null, you got the correct leaf node of your DT!
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/weka/finito/level_site_server.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,31 @@ public void run() {
}

// Collect the object, and see what to do depending on the object.
oos = new ObjectOutputStream(client_socket.getOutputStream());
ois = new ObjectInputStream(client_socket.getInputStream());
o = ois.readObject();

if (o instanceof level_order_site) {
// Traffic from Server, collect the level-site data
this.level_site_parameters = (level_order_site) o;
// System.out.println("Level-Site received training data on Port: " + client_socket.getLocalPort());
oos.writeBoolean(true);
closeConnection(oos, ois, client_socket);
}
else if (o instanceof Hashtable) {
// Start evaluating with the client
Hashtable x = (Hashtable) o;
level_site_evaluation_thread current_level_site_class = new level_site_evaluation_thread(client_socket,
this.level_site_parameters, x);
new Thread(current_level_site_class).start();
try {
oos = new ObjectOutputStream(client_socket.getOutputStream());
ois = new ObjectInputStream(client_socket.getInputStream());
o = ois.readObject();
if (o instanceof level_order_site) {
// Traffic from Server, collect the level-site data
this.level_site_parameters = (level_order_site) o;
// System.out.println("Level-Site received training data on Port: " + client_socket.getLocalPort());
oos.writeBoolean(true);
closeConnection(oos, ois, client_socket);
}
else if (o instanceof Hashtable) {
// Start evaluating with the client
Hashtable x = (Hashtable) o;
level_site_evaluation_thread current_level_site_class = new level_site_evaluation_thread(client_socket,
this.level_site_parameters, x);
new Thread(current_level_site_class).start();
}
else {
System.out.println("The level site received the wrong object: " + o.getClass().getName());
closeConnection(oos, ois, client_socket);
}
}
else {
System.out.println("The level site received the wrong object: " + o.getClass().getName());
closeConnection(oos, ois, client_socket);
catch (ClassNotFoundException | IOException e) {
System.out.println("Yikes! A bad connection from " + client_socket.getInetAddress());
}
}
System.out.println("Server Stopped on port: " + this.serverPort) ;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/weka/finito/utils/shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ else if ((comparisonType == 3) || (comparisonType == 5)) {

public static void closeConnection(ObjectOutputStream oos,
ObjectInputStream ois, Socket client_socket) throws IOException {
oos.close();
ois.close();
if (oos != null) {
oos.close();
}
if (ois != null) {
ois.close();
}
if (client_socket != null && client_socket.isConnected()) {
client_socket.close();
}
Expand Down

0 comments on commit 291b269

Please sign in to comment.