Skip to content

Commit

Permalink
checking if global messaging works
Browse files Browse the repository at this point in the history
  • Loading branch information
codybum committed May 30, 2024
1 parent fdd2c89 commit 4995e12
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/main/java/io/cresco/stunnel/SocketSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import io.cresco.library.utilities.CLogger;

import javax.jms.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.Socket;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -101,7 +99,11 @@ public boolean closeClient(String clientId) {
isClosed = true;

} catch (Exception ex) {
ex.printStackTrace();
logger.error("closeClient clientId: " + clientId + " error!");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
logger.error(sw.toString());
}

return isClosed;
Expand Down Expand Up @@ -295,23 +297,30 @@ public void close () {
}

private void connectionBroken() {

mParent.close();
//close remote
Map<String,String> tunnelConfig = socketController.getTunnelConfig(sTunnelId);
MsgEvent request = plugin.getGlobalPluginMsgEvent(MsgEvent.Type.CONFIG, tunnelConfig.get("dst_region"), tunnelConfig.get("dst_agent"), tunnelConfig.get("dst_plugin"));
request.setParam("action", "closesrcclient");
request.setParam("action_client_id", clientId);
MsgEvent response = plugin.sendRPC(request);
if(response.getParam("status") != null) {
int status = Integer.parseInt(response.getParam("status"));
if(status == 10) {
logger.info("(15) [dst] Src port confirmed closed.");
try {
mParent.close();
//close remote
Map<String, String> tunnelConfig = socketController.getTunnelConfig(sTunnelId);
MsgEvent request = plugin.getGlobalPluginMsgEvent(MsgEvent.Type.CONFIG, tunnelConfig.get("dst_region"), tunnelConfig.get("dst_agent"), tunnelConfig.get("dst_plugin"));
request.setParam("action", "closesrcclient");
request.setParam("action_client_id", clientId);
MsgEvent response = plugin.sendRPC(request);
if (response.getParam("status") != null) {
int status = Integer.parseInt(response.getParam("status"));
if (status == 10) {
logger.info("(15) [dst] Src port confirmed closed.");
} else {
logger.error("Error in closing src port: " + response.getParams());
}
} else {
logger.error("Error in closing src port: " + response.getParams());
logger.error("Missing status from response: " + response.getParams());
}
} else {
logger.error("Missing status from response: " + response.getParams());
} catch (Exception ex) {
logger.error("connectionBroken: error!");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
logger.error(sw.toString());
}

}
Expand Down Expand Up @@ -356,7 +365,11 @@ public void run() {
logger.error("IOException error: " + e.getMessage());
connectionBroken();
} catch (Exception ex) {
logger.error("SOME EXCEPTION: " + ex.getMessage());
logger.error("run: " + ex.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
logger.error(sw.toString());
connectionBroken();
}

Expand Down

0 comments on commit 4995e12

Please sign in to comment.