feat: add distributeYPK

This commit is contained in:
yanghuanyu 2021-11-17 12:58:38 +08:00
parent f84177c850
commit 91080096ce

View File

@ -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<String> nodePubKeys = new HashSet<>(); // nodes' pubkey
for (String str : strs) {
if (str != null && str.length() > 0) nodePubKeys.add(str);
}
Map<String, String> 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<String, String> request = new HashMap<String, String>();