From 91080096ceb06bca08054db1a6838a93222f3ff5 Mon Sep 17 00:00:00 2001 From: yanghuanyu <991390114@qq.com> Date: Wed, 17 Nov 2021 12:58:38 +0800 Subject: [PATCH] feat: add distributeYPK --- .../bdware/server/nodecenter/UnitActions.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/org/bdware/server/nodecenter/UnitActions.java b/src/main/java/org/bdware/server/nodecenter/UnitActions.java index 5982360..79ff229 100644 --- a/src/main/java/org/bdware/server/nodecenter/UnitActions.java +++ b/src/main/java/org/bdware/server/nodecenter/UnitActions.java @@ -9,7 +9,9 @@ import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.db.KeyValueDBUtil; import org.bdware.sc.util.JsonUtil; import org.bdware.server.action.Action; +import org.zz.gmhelper.SM2Util; +import java.io.File; import java.util.*; public class UnitActions { @@ -236,6 +238,52 @@ public class UnitActions { listMultiPointContractProcess(json, resultCallback); } + @Action(async = true) + public void distributeYPK(JsonObject args, final ResultCallback rc) { + LOGGER.debug("[UnitActions] distributeYPK : -----------position1"); + + String pubKey = args.get("pubKey").getAsString(); + String signature = args.get("signature").getAsString(); + String projectName = args.get("projectName").getAsString(); + String[] strs = args.get("nodeIDs").getAsString().split(","); + Set nodePubKeys = new HashSet<>(); // nodes' pubkey + for (String str : strs) { + if (str != null && str.length() > 0) nodePubKeys.add(str); + } + Map nodes = new HashMap<>(); // node's pubKey-node'a name + for (CMNode node : NodeCenterActions.nodeInfos.values()) { + if (nodePubKeys.contains(node.pubKey)) { + nodes.put(node.pubKey, node.nodeName); + LOGGER.debug("nodes add " + node.pubKey + " " + node.nodeName); + } + } + + boolean result = + SM2Util.plainStrVerify( + pubKey, "DistributeYPK|" + projectName + "|" + pubKey, signature); + + LOGGER.debug("[UnitAcitons] 验签:" + result + " -> projectName:" + projectName); + + String ypkPath = "./NodeCenterDB/NC_YPKs/"; + File dir = new File(ypkPath); + if (!dir.exists()) { + dir.mkdirs(); + } + + String filePath = new File(dir, projectName).getAbsolutePath(); + File f = new File(filePath); + String fileName = null; + fileName = f.getName(); + LOGGER.debug("[UnitActions] distributeYPK : fileName=" + fileName); + LOGGER.debug("[UnitActions] nodeNames: " + JsonUtil.toJson(nodes)); + + String isPrivate = "true"; + for (String ID : nodes.keySet()) { + CMNode node = NodeCenterActions.nodeInfos.get(ID); + node.connection.sendProject(filePath, isPrivate, pubKey, rc); + } + } + // @Action(async = true, userPermission = 1L << 6) // public void startContractMultiPoint(JsonObject args, final ResultCallback rc) { // Map request = new HashMap();