From 9dba1ff749f90e9ea5fbc8910946abcd81132cbd Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Tue, 2 Nov 2021 15:03:25 +0800 Subject: [PATCH] feat: support debug cp --- .../server/action/TemporyTestAction.java | 34 +++++++++++++++++++ .../action/p2p/MasterClientTCPAction.java | 2 +- .../action/p2p/MasterServerTCPAction.java | 5 +-- .../java/org/bdware/units/NetworkManager.java | 6 ---- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bdware/server/action/TemporyTestAction.java b/src/main/java/org/bdware/server/action/TemporyTestAction.java index f4a41c9..181faf5 100644 --- a/src/main/java/org/bdware/server/action/TemporyTestAction.java +++ b/src/main/java/org/bdware/server/action/TemporyTestAction.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bdware.sc.ContractClient; +import org.bdware.sc.ContractManager; import org.bdware.sc.ContractMeta; import org.bdware.sc.ContractStatusEnum; import org.bdware.sc.bean.Contract; @@ -154,4 +155,37 @@ public class TemporyTestAction { jo.put("recoverStatus", MasterServerRecoverMechAction.recoverStatus); resultCallback.onResult(JsonUtil.toPrettyJson(jo)); } + + @Action(async = true) + public void getAgentConfig(JsonObject args, ResultCallback resultCallback) { + JsonObject jo = new JsonObject(); + jo.addProperty("action", "onGetAgentConfig"); + jo.addProperty("cmi", ContractClient.cmi); + jo.addProperty("dbPath", ContractManager.dbPath); + jo.addProperty("cPort", ContractManager.cPort.getCMPort()); + jo.addProperty("port", ContractManager.cPort.getPortAndInc()); + resultCallback.onResult(jo.toString()); + } + + @Action(async = true) + public void allocateKeyPair(JsonObject args, ResultCallback resultCallback) { + Contract c = new Contract(); + c.setScript(args.get("script").getAsString()); + c.setOwner(args.get("owner").getAsString()); + ContractManager.instance.allocateKeyIfNotExists(c); + JsonObject jo = JsonUtil.parseObject(c); + jo.addProperty("action", "onAllocateKeyPair"); + resultCallback.onResult(jo.toString()); + } + + @Action(async = true) + public void reconnectAll(JsonObject args, ResultCallback resultCallback) { + ContractManager.instance.reconnectContractProcess(); + String data = ContractManager.instance.listContractsWithOwner( + args.get("owner").getAsString(), null, 0); + JsonObject ret = new JsonObject(); + ret.addProperty("data", data); + ret.addProperty("action", "onReconnectAll"); + resultCallback.onResult(ret); + } } diff --git a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java index 63d241c..9775fab 100644 --- a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java +++ b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java @@ -220,7 +220,7 @@ public class MasterClientTCPAction { run1(); } catch (Throwable t) { t.printStackTrace(); - this.cancel(); + HeartBeatUtil.getInstance().cancel(this); } } diff --git a/src/main/java/org/bdware/server/action/p2p/MasterServerTCPAction.java b/src/main/java/org/bdware/server/action/p2p/MasterServerTCPAction.java index d30cd97..972c2fe 100644 --- a/src/main/java/org/bdware/server/action/p2p/MasterServerTCPAction.java +++ b/src/main/java/org/bdware/server/action/p2p/MasterServerTCPAction.java @@ -83,6 +83,7 @@ public class MasterServerTCPAction { checkAliveTask, MasterClientTCPAction.sendDelay, MasterClientTCPAction.checkDelay); + } private static void notifyNodeOffline(String contractID, String nodeID) { @@ -413,8 +414,8 @@ public class MasterServerTCPAction { Set contracts = new HashSet<>(); String nodeID = handler.pubKey; if (nodeID == null) { - LOGGER.info("nodeID == null"); - this.cancel(); + LOGGER.info("nodeID == null " + this); + HeartBeatUtil.getInstance().cancel(this); return; } diff --git a/src/main/java/org/bdware/units/NetworkManager.java b/src/main/java/org/bdware/units/NetworkManager.java index f6535ed..ef8503a 100644 --- a/src/main/java/org/bdware/units/NetworkManager.java +++ b/src/main/java/org/bdware/units/NetworkManager.java @@ -139,13 +139,7 @@ public class NetworkManager { @Override protected void initChannel(SocketChannel arg0) { arg0.pipeline() - // - // .addLast(new IdleStateHandler(5, 0, 0, - // TimeUnit.SECONDS)) .addLast(new DelimiterCodec()) - // .addLast(new IdleStateHandler(10, 0, 0)) - // - // .addLast(new HeartBeatDecode()) .addLast(new TCPServerFrameHandler()); } });