move router logic from router.json to create params, from YJSCompile to ContractProcess

This commit is contained in:
haoeliu@foxmail.com 2023-03-12 20:54:17 +08:00
parent 18b01e3ab0
commit 1a8cb9c2a7
2 changed files with 30 additions and 21 deletions

View File

@ -16,6 +16,7 @@ import org.bdware.analysis.gas.PPCount;
import org.bdware.analysis.taint.TaintBB; import org.bdware.analysis.taint.TaintBB;
import org.bdware.analysis.taint.TaintCFG; import org.bdware.analysis.taint.TaintCFG;
import org.bdware.analysis.taint.TaintResult; import org.bdware.analysis.taint.TaintResult;
import org.bdware.doip.audit.EndpointConfig;
import org.bdware.sc.ContractResult.Status; import org.bdware.sc.ContractResult.Status;
import org.bdware.sc.bean.*; import org.bdware.sc.bean.*;
import org.bdware.sc.boundry.JavaScriptEntry; import org.bdware.sc.boundry.JavaScriptEntry;
@ -49,6 +50,7 @@ import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
public class ContractProcess { public class ContractProcess {
@ -522,10 +524,7 @@ public class ContractProcess {
// doipModule的话拉起DoipServer服务端口 // doipModule的话拉起DoipServer服务端口
if(cn.getYjsType() == YjsType.DoipModule) { if(cn.getYjsType() == YjsType.DoipModule) {
// 只有一台机器去更新Router中的repoInfo就可以了 // 只有一台机器去更新Router中的repoInfo就可以了
if(JavaScriptEntry.shardingID == 0) { updateRepoInfo(contract.getCreateParam());
DoipClusterServer server = DoipClusterServer.getDOOPServerInstance();
server.updateRepoInfo(contract, cn);
}
invokeOnStartingDoipServer(cn, contract.getCreateParam()); invokeOnStartingDoipServer(cn, contract.getCreateParam());
} }
@ -665,11 +664,7 @@ public class ContractProcess {
// doipModule的话拉起DoipServer服务端口 // doipModule的话拉起DoipServer服务端口
if(cn.getYjsType() == YjsType.DoipModule) { if(cn.getYjsType() == YjsType.DoipModule) {
// 只有一台机器去更新Router中的repoInfo就可以了 updateRepoInfo(contract.getCreateParam());
if(JavaScriptEntry.shardingID == 0) {
DoipClusterServer server = DoipClusterServer.getDOOPServerInstance();
server.updateRepoInfo(contract, cn);
}
invokeOnStartingDoipServer(cn, 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) { public void invokeOnStartingDoipServer(ContractNode cn, JsonElement arg) {
ContractRequest onStartingDoipServer = new ContractRequest(); ContractRequest onStartingDoipServer = new ContractRequest();
onStartingDoipServer.setAction("onServerStart"); onStartingDoipServer.setAction("onServerStart");

View File

@ -119,18 +119,6 @@ public class YJSCompiler {
ContractManifest cm = ContractManifest cm =
JsonUtil.GSON.fromJson( JsonUtil.GSON.fromJson(
new InputStreamReader(manifestInput), ContractManifest.class); 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进行插装 // 如果没有就不限制根据gas进行插装
if (0L != cm.getInsnLimit()) { if (0L != cm.getInsnLimit()) {
LOGGER.info("++++++++++++++++++++++true"); LOGGER.info("++++++++++++++++++++++true");