mirror of
				https://gitee.com/BDWare/router-backend
				synced 2025-11-04 06:22:15 +00:00 
			
		
		
		
	feat: add sendProject progress
This commit is contained in:
		
							parent
							
								
									537ecbfc6c
								
							
						
					
					
						commit
						e94dfe3998
					
				@ -48,7 +48,7 @@ public class DistributeCallback extends ResultCallback {
 | 
			
		||||
            if (ID.equals(sponsorPubkey))
 | 
			
		||||
                continue;
 | 
			
		||||
            CMNode node = NodeCenterActions.nodeInfos.get(ID);
 | 
			
		||||
            node.connection.sendProject(filePath, isPrivate, pubKey, this);
 | 
			
		||||
            node.connection.sendProject(filePath, isPrivate, pubKey, node.ipPort, this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -64,7 +64,7 @@ public class DistributeCallback extends ResultCallback {
 | 
			
		||||
        res.onResult(JsonUtil.toJson(map));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onDistribute(String progress) {
 | 
			
		||||
    public void onDistribute(String progress, String nodeIP) {
 | 
			
		||||
        Map<String, String> ret2 = new HashMap<>();
 | 
			
		||||
        ret2.put("action", "onDistributeContract");
 | 
			
		||||
        ret2.put(
 | 
			
		||||
@ -77,27 +77,25 @@ public class DistributeCallback extends ResultCallback {
 | 
			
		||||
        if (progress.equals("100.00")) index++;
 | 
			
		||||
 | 
			
		||||
        Map<String, String> map = new HashMap<>();
 | 
			
		||||
        map.put("action", "onDistribute");
 | 
			
		||||
        map.put("distributeID", distributeID);
 | 
			
		||||
        map.put("action", "onDistributeYPK");
 | 
			
		||||
        map.put("responseID", distributeID);
 | 
			
		||||
        map.put("content", JsonUtil.toJson(ret2));
 | 
			
		||||
        map.put("nodeIP", nodeIP);
 | 
			
		||||
        map.put("progress", progress);
 | 
			
		||||
        res.onResult(JsonUtil.toJson(map));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onReceive(Map<String, String> map) {
 | 
			
		||||
        LOGGER.debug("[DistributeCallback] onReceive :  position----9");
 | 
			
		||||
        String progress = map.get("progress");
 | 
			
		||||
 | 
			
		||||
        String nodeIP = map.get("ipPort");
 | 
			
		||||
        if (progress.equals("100")) {
 | 
			
		||||
            Map<String, String> args = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
            args.put("fileName", fileName);
 | 
			
		||||
            args.put("pubKey", pubKey);
 | 
			
		||||
            args.put("signature", signature);
 | 
			
		||||
 | 
			
		||||
            count++;
 | 
			
		||||
 | 
			
		||||
            LOGGER.debug(count + "个节点已收完成" + "   总共有" + nodes.size() + "  个节点");
 | 
			
		||||
 | 
			
		||||
            if (count == nodes.size()) {
 | 
			
		||||
                // res返回给前端,合约分发完成
 | 
			
		||||
                Map<String, String> ret2 = new HashMap<>();
 | 
			
		||||
@ -105,8 +103,9 @@ public class DistributeCallback extends ResultCallback {
 | 
			
		||||
                ret2.put("progress", "100%");
 | 
			
		||||
                Map<String, String> map_send = new HashMap<>();
 | 
			
		||||
                map_send.put("action", "onDistribute");
 | 
			
		||||
                map_send.put("responseID", distributeID);
 | 
			
		||||
                map_send.put("over", "true");
 | 
			
		||||
                map_send.put("distributeID", distributeID);
 | 
			
		||||
                map_send.put("nodeIP", nodeIP);
 | 
			
		||||
                map_send.put("content", JsonUtil.toJson(ret2));
 | 
			
		||||
                res.onResult(JsonUtil.toJson(map_send));
 | 
			
		||||
                //NC delete file
 | 
			
		||||
@ -136,7 +135,7 @@ public class DistributeCallback extends ResultCallback {
 | 
			
		||||
                distributeContractProject(map.get("receiveFileName"), map.get("isPrivate"));
 | 
			
		||||
                break;
 | 
			
		||||
            case "onDistribute":
 | 
			
		||||
                onDistribute(map.get("progress"));
 | 
			
		||||
                onDistribute(map.get("progress"), map.get("nodeIP"));
 | 
			
		||||
                break;
 | 
			
		||||
            case "onReceive":
 | 
			
		||||
                onReceive(map);
 | 
			
		||||
 | 
			
		||||
@ -176,6 +176,11 @@ public class NodeCenterActions {
 | 
			
		||||
        return node.peerID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getIpPortByNodeId(String id) {
 | 
			
		||||
        CMNode node = nodeInfos.get(id);
 | 
			
		||||
        return node.ipPort;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Action(httpAccess = true)
 | 
			
		||||
    public void downloadUUID(JsonObject args, ResultCallback resultCallback) {
 | 
			
		||||
        String pubKey = args.get("pubKey").getAsString();
 | 
			
		||||
@ -973,7 +978,7 @@ public class NodeCenterActions {
 | 
			
		||||
        }
 | 
			
		||||
        if (args.has("operation")) {
 | 
			
		||||
            cr.setAction(args.get("operation").getAsString());
 | 
			
		||||
            cr.setArg(args.get("arg"));
 | 
			
		||||
            cr.setArg(args.get("arg").getAsString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final JsonObject ret = new JsonObject();
 | 
			
		||||
@ -1109,7 +1114,7 @@ public class NodeCenterActions {
 | 
			
		||||
    // in its
 | 
			
		||||
    // onResult
 | 
			
		||||
    public void sendProject(
 | 
			
		||||
            String filePath, String isPrivate, String pubKey, ResultCallback result) {
 | 
			
		||||
            String filePath, String isPrivate, String pubKey, String nodeIP, ResultCallback result) {
 | 
			
		||||
        LOGGER.debug("sendProject : position----6" + filePath);
 | 
			
		||||
 | 
			
		||||
        File project = new File(filePath);
 | 
			
		||||
@ -1135,7 +1140,9 @@ public class NodeCenterActions {
 | 
			
		||||
                FileInputStream fin = new FileInputStream(project);
 | 
			
		||||
                byte[] buff = new byte[30 * 1024];
 | 
			
		||||
                long count = 0;
 | 
			
		||||
                long preCount = 0;
 | 
			
		||||
                long total = project.length();
 | 
			
		||||
                long step = total / 10;
 | 
			
		||||
                LOGGER.debug("ypk = " + total);
 | 
			
		||||
 | 
			
		||||
                for (int len = 0; (len = (fin.read(buff))) > 0; ) {
 | 
			
		||||
@ -1145,14 +1152,15 @@ public class NodeCenterActions {
 | 
			
		||||
                    count += len;
 | 
			
		||||
                    controller.sendMsg(JsonUtil.toJson(req));
 | 
			
		||||
                    req.put("isAppend", "true");
 | 
			
		||||
 | 
			
		||||
                    Map<String, String> req2 = new HashMap<>();
 | 
			
		||||
                    req2.put("operation", "onDistribute");
 | 
			
		||||
                    req2.put("requestID", requestID);
 | 
			
		||||
                    req2.put("progress", String.format("%.2f", count * 100F / total));
 | 
			
		||||
                    sync.wakeUp(requestID, JsonUtil.toJson(req2));
 | 
			
		||||
 | 
			
		||||
                    Thread.sleep(300);
 | 
			
		||||
                    if (count - preCount > step || count == total) {
 | 
			
		||||
                        preCount = count;
 | 
			
		||||
                        Map<String, String> req2 = new HashMap<>();
 | 
			
		||||
                        req2.put("operation", "onDistribute");
 | 
			
		||||
                        req2.put("requestID", requestID);
 | 
			
		||||
                        req2.put("progress", String.format("%.2f", count * 100F / total));
 | 
			
		||||
                        req2.put("nodeIP", nodeIP);
 | 
			
		||||
                        sync.wakeUp(requestID, JsonUtil.toJson(req2));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                fin.close();
 | 
			
		||||
 | 
			
		||||
@ -1162,7 +1170,7 @@ public class NodeCenterActions {
 | 
			
		||||
 | 
			
		||||
                // delete ypk_NC
 | 
			
		||||
                LOGGER.debug("[NodeCenterActions] send project finish.");
 | 
			
		||||
            } catch (IOException | InterruptedException e) {
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -1176,6 +1184,7 @@ public class NodeCenterActions {
 | 
			
		||||
        Map<String, String> req = new HashMap<>();
 | 
			
		||||
        req.put("operation", "onReceive");
 | 
			
		||||
        req.put("peerID", NodeCenterActions.getPeerIdByNodeId(args.get("nodeID").getAsString()));
 | 
			
		||||
        req.put("ipPort", NodeCenterActions.getIpPortByNodeId(args.get("nodeID").getAsString()));
 | 
			
		||||
        req.put("progress", args.get("progress").getAsString());
 | 
			
		||||
        req.put("requestID", args.get("requestID").getAsString());
 | 
			
		||||
        String requestID = args.get("requestID").getAsString();
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ 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.bdware.server.action.DistributeCallback;
 | 
			
		||||
import org.zz.gmhelper.SM2Util;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
@ -242,11 +243,11 @@ public class UnitActions {
 | 
			
		||||
 | 
			
		||||
    @Action(async = true)
 | 
			
		||||
    public void distributeYPK(JsonObject args, final ResultCallback rc) {
 | 
			
		||||
        LOGGER.debug("[UnitActions] distributeYPK :  -----------position1");
 | 
			
		||||
 | 
			
		||||
        LOGGER.info("[UnitActions] distributeYPK :  -----------position1");
 | 
			
		||||
        String pubKey = args.get("pubKey").getAsString();
 | 
			
		||||
        String signature = args.get("signature").getAsString();
 | 
			
		||||
        String projectName = args.get("projectName").getAsString();
 | 
			
		||||
        String requestID = args.get("requestID").getAsString();
 | 
			
		||||
        String[] strs = args.get("nodeIDs").getAsString().split(",");
 | 
			
		||||
        Set<String> nodePubKeys = new HashSet<>(); // nodes' pubkey
 | 
			
		||||
        for (String str : strs) {
 | 
			
		||||
@ -256,33 +257,38 @@ public class UnitActions {
 | 
			
		||||
        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);
 | 
			
		||||
                LOGGER.info("nodes add " + node.pubKey + "   " + node.nodeName);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (nodes.isEmpty()) {
 | 
			
		||||
            simpleReply(rc, "onDistributeYPK", "empty nodes");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean result =
 | 
			
		||||
                SM2Util.plainStrVerify(
 | 
			
		||||
                        pubKey, "DistributeYPK|" + projectName + "|" + pubKey, signature);
 | 
			
		||||
        LOGGER.info("[UnitAcitons] 验签:" + result + " -> projectName:" + projectName);
 | 
			
		||||
 | 
			
		||||
        LOGGER.debug("[UnitAcitons] 验签:" + result + " -> projectName:" + projectName);
 | 
			
		||||
 | 
			
		||||
        String ypkPath = "./NodeCenterDB/NC_YPKs/";
 | 
			
		||||
        String ypkType = projectName.split("_")[0];
 | 
			
		||||
        String ypkPath = "./NodeCenterDB/NC_YPKs/" + ypkType;
 | 
			
		||||
        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));
 | 
			
		||||
        LOGGER.info("[UnitActions] distributeYPK : fileName=" + fileName);
 | 
			
		||||
        LOGGER.info("[UnitActions] nodeNames: " + JsonUtil.toJson(nodes));
 | 
			
		||||
 | 
			
		||||
        String isPrivate = "true";
 | 
			
		||||
        DistributeCallback dcb = new DistributeCallback(requestID, "", nodes, rc, signature, "s");
 | 
			
		||||
        NodeCenterActions.sync.sleepWithTimeout(requestID, dcb, 60);
 | 
			
		||||
 | 
			
		||||
        for (String ID : nodes.keySet()) {
 | 
			
		||||
            CMNode node = NodeCenterActions.nodeInfos.get(ID);
 | 
			
		||||
            node.connection.sendProject(filePath, isPrivate, pubKey, rc);
 | 
			
		||||
            node.connection.sendProject(filePath, isPrivate, pubKey, node.ipPort, dcb);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,8 +7,12 @@ import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
public class WordSegmentationTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    public void go() throws IOException {
 | 
			
		||||
    public void go() {
 | 
			
		||||
        MetaIndexAction i = new MetaIndexAction();
 | 
			
		||||
        i.segmentWord(null, null);
 | 
			
		||||
        try {
 | 
			
		||||
            i.segmentWord(null, null);
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user