Skip to content

Commit

Permalink
Modify SocketProducer to generate key rather than accept one.
Browse files Browse the repository at this point in the history
  • Loading branch information
conmf committed Sep 16, 2022
1 parent b857ae4 commit c6c4af8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SocketDestination(String key, DataOutputStream out) {

public final synchronized boolean send(Packet packet) {
try {
out.writeUTF(packet.getData());
out.write(packet.getData().getBytes());
} catch (JSONException | IOException e) {
e.printStackTrace();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,12 @@ public Response processSTRT(Packet packet) {
}

public Response processEDAT(Packet packet) {
<<<<<<< HEAD

//manager.send();
return ResponseFactory.response0();
=======
if(!manager.containsDestination(packet.getSubData()))
return ResponseFactory.response471(packet.getSubData());

if(!manager.send(packet.getSubData(), packet))
return ResponseFactory.response472(packet.getSubData());

return ResponseFactory.response200("");
>>>>>>> branch 'main' of https://github.rpi.edu/DataINCITE/IDEA-DeFi-CRAFT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected final Response send(String tag, String sub_tag, String data, String su

public final synchronized void add(OutputDestination destination) {
destinations.put(destination.getKey(), destination);
destination.send(Packet.packet(handler, "", "", "Connected: " + destination.getKey()));
//destination.send(Packet.packet(handler, "", "", "Connected: " + destination.getKey()));
}

public final synchronized void remove(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;

public class SocketManager {

Expand Down Expand Up @@ -47,7 +49,9 @@ public synchronized static String accept(int port) {

// validate new connection:
DataInputStream in = new DataInputStream(connection.getInputStream());
String key = in.readUTF();
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
String key = UUID.randomUUID().toString();
out.write(key.getBytes());

if(connections.containsKey(key))
connections.get(key).close();
Expand Down Expand Up @@ -78,6 +82,7 @@ public synchronized static boolean accept(int port, String required_key) {
Socket connection = servers.get(port).accept();
// validate new connection:
DataInputStream in = new DataInputStream(connection.getInputStream());

String key = in.readUTF();

if(!required_key.equals(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@ public class Endpoint {
System.exit(1);
}
}

<<<<<<< HEAD
// sample testing url: http://localhost:8080/defi/v1/rest/json?key=test&protocol=source_exists&data=amber_data
@GetMapping(path="/defi/v1/rest/json")
public String getRest(@RequestParam String key, @RequestParam String protocol, @RequestParam String data) throws InterruptedException {
=======
// sample testing url: http://localhost:8080/defi/v1/rest/live?key=TEST-KEY&protocol=request&data=key,external
@GetMapping(path="/defi/v1/rest/live")
public String getRestLive(@RequestParam String key, @RequestParam String protocol, @RequestParam String data) throws InterruptedException {
>>>>>>> branch 'main' of https://github.rpi.edu/DataINCITE/IDEA-DeFi-CRAFT
String response = request(key, protocol, data);
if(response == null)
return new JSONObject()
Expand Down

0 comments on commit c6c4af8

Please sign in to comment.