From 1a8cb9c2a74003fa4a20cfa8f2d704dae8e7cb46 Mon Sep 17 00:00:00 2001 From: "haoeliu@foxmail.com" Date: Sun, 12 Mar 2023 20:54:17 +0800 Subject: [PATCH] move router logic from router.json to create params, from YJSCompile to ContractProcess --- .../java/org/bdware/sc/ContractProcess.java | 39 ++++++++++++++----- .../org/bdware/sc/compiler/YJSCompiler.java | 12 ------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractProcess.java b/src/main/java/org/bdware/sc/ContractProcess.java index 4edbac6..323b3d3 100644 --- a/src/main/java/org/bdware/sc/ContractProcess.java +++ b/src/main/java/org/bdware/sc/ContractProcess.java @@ -16,6 +16,7 @@ import org.bdware.analysis.gas.PPCount; import org.bdware.analysis.taint.TaintBB; import org.bdware.analysis.taint.TaintCFG; import org.bdware.analysis.taint.TaintResult; +import org.bdware.doip.audit.EndpointConfig; import org.bdware.sc.ContractResult.Status; import org.bdware.sc.bean.*; import org.bdware.sc.boundry.JavaScriptEntry; @@ -49,6 +50,7 @@ import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; +import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ContractProcess { @@ -522,10 +524,7 @@ public class ContractProcess { // doipModule的话,拉起DoipServer服务端口 if(cn.getYjsType() == YjsType.DoipModule) { // 只有一台机器去更新Router中的repoInfo就可以了 - if(JavaScriptEntry.shardingID == 0) { - DoipClusterServer server = DoipClusterServer.getDOOPServerInstance(); - server.updateRepoInfo(contract, cn); - } + updateRepoInfo(contract.getCreateParam()); invokeOnStartingDoipServer(cn, contract.getCreateParam()); } @@ -665,11 +664,7 @@ public class ContractProcess { // doipModule的话,拉起DoipServer服务端口 if(cn.getYjsType() == YjsType.DoipModule) { - // 只有一台机器去更新Router中的repoInfo就可以了 - if(JavaScriptEntry.shardingID == 0) { - DoipClusterServer server = DoipClusterServer.getDOOPServerInstance(); - server.updateRepoInfo(contract, cn); - } + updateRepoInfo(contract.getCreateParam()); invokeOnStartingDoipServer(cn, contract.getCreateParam()); } @@ -682,6 +677,32 @@ public class ContractProcess { } } + public void updateRepoInfo(JsonElement arg) throws Exception { + // 只有0号节点需要初始化IRP连接去updateRepoInfo + if(JavaScriptEntry.shardingID == 0) { + // DOOP relevant logic + DoipClusterServer server = DoipClusterServer.getDOOPServerInstance(); + if(server == null) { + JsonObject createParams = arg.getAsJsonObject(); + if(createParams.has("router")) { + JsonElement routerInfo = createParams.get("router"); + if(!routerInfo.isJsonObject()) throw new Exception("Provide wrong router info in create params to DoipModule"); + else { + EndpointConfig endpointConfig = JsonUtil.GSON.fromJson(routerInfo.getAsJsonObject(), EndpointConfig.class); + DoipClusterServer.createDOOPServerInstance(endpointConfig); + } + } else { + throw new Exception("DoipModule should provide router info in create params"); + } + + server = DoipClusterServer.getDOOPServerInstance(); + } + + // 只有一台机器去更新Router中的repoInfo就可以了 + server.updateRepoInfo(contract, cn); + } + } + public void invokeOnStartingDoipServer(ContractNode cn, JsonElement arg) { ContractRequest onStartingDoipServer = new ContractRequest(); onStartingDoipServer.setAction("onServerStart"); diff --git a/src/main/java/org/bdware/sc/compiler/YJSCompiler.java b/src/main/java/org/bdware/sc/compiler/YJSCompiler.java index beb2517..e597263 100644 --- a/src/main/java/org/bdware/sc/compiler/YJSCompiler.java +++ b/src/main/java/org/bdware/sc/compiler/YJSCompiler.java @@ -119,18 +119,6 @@ public class YJSCompiler { ContractManifest cm = JsonUtil.GSON.fromJson( new InputStreamReader(manifestInput), ContractManifest.class); - - // DOOP relevant logic - ZipEntry routerConfig = zf.getEntry("/router.json"); - if (null == routerConfig) { - routerConfig = zf.getEntry("router.json"); - } - if(null != routerConfig) { - InputStream routerInput = zf.getInputStream(routerConfig); - EndpointConfig endpointConfig = JsonUtil.GSON.fromJson(new InputStreamReader(routerInput), EndpointConfig.class); - DoipClusterServer.createDOOPServerInstance(endpointConfig); - } - // 如果没有就不限制,根据gas进行插装 if (0L != cm.getInsnLimit()) { LOGGER.info("++++++++++++++++++++++true");