add support for remote debug

This commit is contained in:
CaiHQ 2022-09-02 21:27:32 +08:00
parent b5a9b2d085
commit 926078e081
19 changed files with 445 additions and 513 deletions

View File

@ -1,3 +1,5 @@
#/bin/bash #/bin/bash
scp -P 222 ./build/bdserver.zip dev@47.95.110.68:/data/public/releases/bdcontract/$1/ scp -P 222 ./build/bdserver.zip dev@47.95.110.68:/data/public/releases/bdcontract/$1/
#In_235813

View File

@ -38,12 +38,13 @@ public class HeartBeatUtil {
public synchronized void schedule(TimerTask checkAliveTask, int delay, int period) { public synchronized void schedule(TimerTask checkAliveTask, int delay, int period) {
try { try {
if (!recordedFuture.containsKey(checkAliveTask)) { if (recordedFuture.containsKey(checkAliveTask)) {
ScheduledFuture<?> future = cancel(checkAliveTask);
ContractManager.scheduledThreadPool.scheduleWithFixedDelay(
checkAliveTask, delay, period, TimeUnit.MILLISECONDS);
recordedFuture.put(checkAliveTask, future);
} }
ScheduledFuture<?> future =
ContractManager.scheduledThreadPool.scheduleWithFixedDelay(
checkAliveTask, delay, period, TimeUnit.MILLISECONDS);
recordedFuture.put(checkAliveTask, future);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -674,7 +674,7 @@ public class CMActions implements OnHashCallback {
c.setScript(script); c.setScript(script);
c.setOwner(GlobalConf.instance.keyPair.getPublicKeyStr()); c.setOwner(GlobalConf.instance.keyPair.getPublicKeyStr());
c.doSignature(GlobalConf.instance.keyPair); c.doSignature(GlobalConf.instance.keyPair);
ret.put(fileName, manager.startContractAndRedirect(c, System.out)); ret.put(fileName, manager.startContract(c));
if (args.has("dumpPeriod")) { if (args.has("dumpPeriod")) {
LOGGER.debug("启动后设置dump周期" + args.get("dumpPeriod").getAsString()); LOGGER.debug("启动后设置dump周期" + args.get("dumpPeriod").getAsString());
@ -734,16 +734,16 @@ public class CMActions implements OnHashCallback {
if (args.has("createParam")) { if (args.has("createParam")) {
c.setCreateParam(args.get("createParam")); c.setCreateParam(args.get("createParam"));
} }
// if (!c.verifySignature()) { if (args.has("remoteDebugPort")) {
// ret.put("data", "verify failed"); c.setRemoteDebugPort(args.get("remoteDebugPort").getAsInt());
// resultCallback.onResult(gson.toJson(ret)); }
// return; if (args.has("isDebug")) {
// } c.setDebug(true);
}
if (path != null && path.startsWith("/")) { if (path != null && path.startsWith("/")) {
String parPath; String parPath;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateCompiledDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateCompiledDir + "/" + getLoginPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicCompiledDir; parPath = GlobalConf.instance.publicCompiledDir;
} }
@ -751,33 +751,11 @@ public class CMActions implements OnHashCallback {
// TODO script should encoded!! // TODO script should encoded!!
File temp = new File(parPath + path); File temp = new File(parPath + path);
if (temp.isFile() && temp.exists()) c.setScript(temp.getAbsolutePath()); if (temp.isFile() && temp.exists()) c.setScript(temp.getAbsolutePath());
// TODO
// if (DoConfig.openContractDORegister) {
// File file = new File(dir.getAbsolutePath() +
// "/manifest.json");
// if (file.isFile() && file.exists()) {
// try {
// InputStream manifestInput = new FileInputStream(file);
// ContractManifest cm =
// JsonUtil
// .fromJson(new
// InputStreamReader(manifestInput), ContractManifest.class);
// c.setDoipFlag(cm.doipFlag);
// if (cm.doi != null && !cm.doi.equals(""))
// c.setDOI(cm.doi);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// } else {
// c.setDoipFlag(false);
// }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS() ret.put("data", manager.startContract(c)); //
ret.put("cid", c.getID()); ret.put("cid", c.getID());
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
resultCallback.onResult(ret); resultCallback.onResult(ret);
@ -834,15 +812,12 @@ public class CMActions implements OnHashCallback {
if (args.has("createParam")) { if (args.has("createParam")) {
c.setCreateParam(args.get("createParam")); c.setCreateParam(args.get("createParam"));
} }
// 上面那些有空再整理一下 if (args.has("remoteDebugPort")) {
c.setDebug(false); c.setRemoteDebugPort(args.get("remoteDebugPort").getAsInt());
}
if (args.has("isDebug") && args.get("isDebug").getAsBoolean())
c.setDebug(true);
c.setOwner(args.get("verifiedPubKey").getAsString()); c.setOwner(args.get("verifiedPubKey").getAsString());
// if (!c.verifySignature()) {
// ret.put("data", "verify failed");
// resultCallback.onResult(gson.toJson(ret));
// return;
// }
if (path != null && path.startsWith("/")) { if (path != null && path.startsWith("/")) {
String parPath; String parPath;
@ -858,7 +833,7 @@ public class CMActions implements OnHashCallback {
String ypkPath; String ypkPath;
File dir; File dir;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getLoginPubkey(args);
dir = new File(parPath, parentPath.toString()); dir = new File(parPath, parentPath.toString());
ypkPath = FileActions.autoCompile(parPath, dir.getName()); ypkPath = FileActions.autoCompile(parPath, dir.getName());
@ -872,37 +847,12 @@ public class CMActions implements OnHashCallback {
// TODO script should encoded!! // TODO script should encoded!!
c.setScript(ypkPath); c.setScript(ypkPath);
/*
if (DoConfig.openContractDORegister) {
File file = new File(dir.getAbsolutePath() + "/manifest.json");
if (file.isFile() && file.exists()) {
try {
InputStream manifestInput = new FileInputStream(file);
ContractManifest cm =
JsonUtil
.fromJson(
new InputStreamReader(manifestInput),
ContractManifest.class);
c.setDoipFlag(cm.doipFlag);
if (cm.doi != null && !cm.doi.equals("")) c.setDOI(cm.doi);
if (cm.authInfoPersistDOI != null
&& !cm.authInfoPersistDOI.equals(""))
c.setAuthInfoPersistDOI(cm.authInfoPersistDOI);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
c.setDoipFlag(false);
}
*/
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
ret.put("data", manager.startContractAndRedirect(c, System.out)); ret.put("data", manager.startContract(c));
ret.put("status", true); ret.put("status", true);
ret.put("cid", c.getID()); ret.put("cid", c.getID());
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
@ -929,6 +879,16 @@ public class CMActions implements OnHashCallback {
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} }
private String getLoginPubkey(JsonObject args) {
try {
if (handler != null) return handler.getPubKey();
return args.get("pubKey").getAsString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Action(userPermission = 1 << 14, async = true) @Action(userPermission = 1 << 14, async = true)
public void startContractAsDebug(JsonObject args, ResultCallback resultCallback) { public void startContractAsDebug(JsonObject args, ResultCallback resultCallback) {
if (args.has("verifiedPubKey")) { if (args.has("verifiedPubKey")) {
@ -963,6 +923,9 @@ public class CMActions implements OnHashCallback {
if (args.has("createParam")) { if (args.has("createParam")) {
c.setCreateParam(args.get("createParam")); c.setCreateParam(args.get("createParam"));
} }
if (args.has("remoteDebugPort")) {
c.setRemoteDebugPort(args.get("remoteDebugPort").getAsInt());
}
// 上面那些有空再整理一下 // 上面那些有空再整理一下
c.setOwner(args.get("verifiedPubKey").getAsString()); c.setOwner(args.get("verifiedPubKey").getAsString());
@ -986,7 +949,7 @@ public class CMActions implements OnHashCallback {
String ypkPath; String ypkPath;
File dir; File dir;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getLoginPubkey(args);
dir = new File(parPath, parentPath.toString()); dir = new File(parPath, parentPath.toString());
ypkPath = FileActions.autoCompile(parPath, dir.getName()); ypkPath = FileActions.autoCompile(parPath, dir.getName());
@ -1028,8 +991,7 @@ public class CMActions implements OnHashCallback {
e.printStackTrace(); e.printStackTrace();
} }
} }
ret.put("data", manager.startContract(c)); // createPS()
ret.put("data", manager.startContractAndRedirectWithDebug(c)); // createPS()
ret.put("cid", c.getID()); ret.put("cid", c.getID());
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
if (args.has("requestID")) { if (args.has("requestID")) {
@ -1178,7 +1140,6 @@ public class CMActions implements OnHashCallback {
r.put("data", "success"); r.put("data", "success");
r.put("action", "transferHandler"); r.put("action", "transferHandler");
// 从这继续写 // 从这继续写
LOGGER.debug("forContract :"); LOGGER.debug("forContract :");
// strs2.append("[CMActions] forContract :\n"); // strs2.append("[CMActions] forContract :\n");
resultCallback.onResult(r); resultCallback.onResult(r);
@ -1289,7 +1250,7 @@ public class CMActions implements OnHashCallback {
ContractMeta meta = manager.statusRecorder.getContractMeta(rc.getContractID()); ContractMeta meta = manager.statusRecorder.getContractMeta(rc.getContractID());
Contract contract = meta.contract; Contract contract = meta.contract;
killContractProcess(args, resultCallback); killContractProcess(args, resultCallback);
manager.startContractAndRedirect(contract, System.out); manager.startContract(contract);
String data = manager.listContractsWithOwner( String data = manager.listContractsWithOwner(
args.get("verifiedPubKey").getAsString(), args.get("verifiedPubKey").getAsString(),
null, null,
@ -1366,7 +1327,7 @@ public class CMActions implements OnHashCallback {
} }
String parPath = GlobalConf.instance.publicDir; String parPath = GlobalConf.instance.publicDir;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getLoginPubkey(args);
} }
byte[] bb = byte[] bb =
YJSPacker.pack(new File(parPath, parentPath.toString()).getAbsolutePath()); YJSPacker.pack(new File(parPath, parentPath.toString()).getAbsolutePath());
@ -1417,7 +1378,7 @@ public class CMActions implements OnHashCallback {
resultCallback.onResult(r); resultCallback.onResult(r);
} }
@Action(userPermission = 1L << 26, async = true, httpAccess = false) @Action(userPermission = 1L << 26, async = true)
public void killAllContract(JsonObject args, ResultCallback resultCallback) { public void killAllContract(JsonObject args, ResultCallback resultCallback) {
if (args.has("verifiedPubKey")) { if (args.has("verifiedPubKey")) {
if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) { if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) {
@ -1443,7 +1404,6 @@ public class CMActions implements OnHashCallback {
if (sc2.hasNextInt()) pid = sc2.nextInt() + ""; if (sc2.hasNextInt()) pid = sc2.nextInt() + "";
} }
sc2.close(); sc2.close();
if (pid != null) { if (pid != null) {
ProcessBuilder subProcess = ProcessBuilder subProcess =
new ProcessBuilder("kill", "-9", pid); new ProcessBuilder("kill", "-9", pid);
@ -1598,9 +1558,12 @@ public class CMActions implements OnHashCallback {
unitPeers = JsonUtil.parseString(jsonObject.get("value").getAsString()).getAsJsonArray(); unitPeers = JsonUtil.parseString(jsonObject.get("value").getAsString()).getAsJsonArray();
for (JsonElement jsonElemenPeer : unitPeers) { for (JsonElement jsonElemenPeer : unitPeers) {
jsonPeer = jsonElemenPeer.getAsJsonObject(); jsonPeer = jsonElemenPeer.getAsJsonObject();
nodeName = jsonPeer.get("nodeName").getAsString(); if (jsonPeer.has("nodeName"))
peerID = jsonPeer.get("peerID").getAsString(); nodeName = jsonPeer.get("nodeName").getAsString();
ipPort = jsonPeer.get("ipPort").getAsString(); if (jsonPeer.has("peerID"))
peerID = jsonPeer.get("peerID").getAsString();
if (jsonPeer.has("ipPort"))
ipPort = jsonPeer.get("ipPort").getAsString();
// NetworkManager.instance.peerID2TCPAddress.put(peer, ipPort); // NetworkManager.instance.peerID2TCPAddress.put(peer, ipPort);
// try { // try {
// NetworkManager.instance.createTCPClient(peerID, ipPort); // NetworkManager.instance.createTCPClient(peerID, ipPort);

View File

@ -55,6 +55,7 @@ public class FileActions {
static Map<String, FileOutputStream> fileMap = new HashMap<>(); static Map<String, FileOutputStream> fileMap = new HashMap<>();
static Map<String, Long> updateTime = new HashMap<>(); static Map<String, Long> updateTime = new HashMap<>();
static io.netty.util.TimerTask clearUploadFailed; static io.netty.util.TimerTask clearUploadFailed;
ContractManagerFrameHandler handler;
static { static {
clearUploadFailed = clearUploadFailed =
@ -69,11 +70,6 @@ public class FileActions {
SyncResult.timer.newTimeout(clearUploadFailed, 5, TimeUnit.MINUTES); SyncResult.timer.newTimeout(clearUploadFailed, 5, TimeUnit.MINUTES);
} }
ContractManagerFrameHandler handler;
// public FileActions() {
// handler = null;
// }
public FileActions(ContractManagerFrameHandler webSocketFrameHandler) { public FileActions(ContractManagerFrameHandler webSocketFrameHandler) {
handler = webSocketFrameHandler; handler = webSocketFrameHandler;
@ -420,7 +416,7 @@ public class FileActions {
c.setScript(ypkPath); c.setScript(ypkPath);
c.setOwner(owner); c.setOwner(owner);
c.setDebug(isDebug); c.setDebug(isDebug);
CMActions.manager.startContractAndRedirect(c, System.out); // createPS() CMActions.manager.startContractAndRedirect(c, System.out, null); // createPS()
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -658,7 +654,7 @@ public class FileActions {
boolean isPrivate = false; boolean isPrivate = false;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
isPrivate = true; isPrivate = true;
} }
changeSet.add(new File(parPath, toProjectName(projectName)).getAbsolutePath()); changeSet.add(new File(parPath, toProjectName(projectName)).getAbsolutePath());
@ -685,7 +681,7 @@ public class FileActions {
boolean isPrivate = false; boolean isPrivate = false;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
isPrivate = true; isPrivate = true;
} }
File dir = new File(parPath, toProjectName(projectName)); File dir = new File(parPath, toProjectName(projectName));
@ -775,41 +771,41 @@ public class FileActions {
} }
@Action(userPermission = 1L << 17) @Action(userPermission = 1L << 17)
public void listCompiledFiles(JsonObject json, ResultCallback resultCallback) { public void listCompiledFiles(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onListCompiledFiles"; response.action = "onListCompiledFiles";
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
File f; File f;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
f = new File(GlobalConf.instance.privateCompiledDir + "/" + handler.getPubKey()); f = new File(GlobalConf.instance.privateCompiledDir + "/" + getPubkey(args));
} else { } else {
f = new File(GlobalConf.instance.publicCompiledDir); f = new File(GlobalConf.instance.publicCompiledDir);
} }
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
returnFileListResponse(resultCallback, response, dirs, f); returnFileListResponse(resultCallback, response, dirs, f);
} }
// 合约提供者 // 合约提供者
@Action(userPermission = 1L << 15) @Action(userPermission = 1L << 15)
public void listProjects(JsonObject json, ResultCallback resultCallback) { public void listProjects(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onListProjects"; response.action = "onListProjects";
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
File f; File f;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
f = new File(GlobalConf.instance.privateDir + "/" + handler.getPubKey()); f = new File(GlobalConf.instance.privateDir + "/" + getPubkey(args));
} else { } else {
f = new File(GlobalConf.instance.publicDir); f = new File(GlobalConf.instance.publicDir);
} }
@ -833,20 +829,20 @@ public class FileActions {
} }
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void getProject(JsonObject json, ResultCallback resultCallback) { public void getProject(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onGetProject"; response.action = "onGetProject";
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
String project = json.get("project").getAsString(); String project = args.get("project").getAsString();
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicDir; parPath = GlobalConf.instance.publicDir;
} }
@ -867,21 +863,21 @@ public class FileActions {
} }
@Action(userPermission = 1L << 15) @Action(userPermission = 1L << 15)
public void listProject(JsonObject json, ResultCallback resultCallback) { public void listProject(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onListProject"; response.action = "onListProject";
String project = json.get("project").getAsString(); String project = args.get("project").getAsString();
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
ListProjectResp resp = new ListProjectResp(); ListProjectResp resp = new ListProjectResp();
// List<String> dirs = new ArrayList<>(); // List<String> dirs = new ArrayList<>();
File f; File f;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
String str = "/" + handler.getPubKey(); String str = "/" + getPubkey(args);
f = new File(GlobalConf.instance.privateDir + str, project); f = new File(GlobalConf.instance.privateDir + str, project);
response.isPrivate = true; response.isPrivate = true;
} else { } else {
@ -908,26 +904,26 @@ public class FileActions {
} }
@Action(userPermission = 1L << 15) @Action(userPermission = 1L << 15)
public void listFile(JsonObject json, ResultCallback resultCallback) { public void listFile(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onListFile"; response.action = "onListFile";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
ListProjectResp resp = new ListProjectResp(); ListProjectResp resp = new ListProjectResp();
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicDir; parPath = GlobalConf.instance.publicDir;
} }
if (GlobalConf.instance.projectDir != null) { if (GlobalConf.instance.projectDir != null) {
resp.isDir = false; resp.isDir = false;
resp.path = json.get("path").getAsString(); resp.path = args.get("path").getAsString();
File f = new File(parPath + resp.path); File f = new File(parPath + resp.path);
if (!resp.path.contains("..") && f.exists()) { if (!resp.path.contains("..") && f.exists()) {
if (isTextFile(f.getName())) { if (isTextFile(f.getName())) {
@ -944,20 +940,20 @@ public class FileActions {
} }
@Action(async = true, userPermission = 1 << 14) @Action(async = true, userPermission = 1 << 14)
public void downloadContractFromOtherHost(JsonObject json, ResultCallback resultCallback) { public void downloadContractFromOtherHost(JsonObject args, ResultCallback resultCallback) {
String fileName = json.get("fileName").getAsString(); String fileName = args.get("fileName").getAsString();
String mainHost = json.get("mainHost").getAsString(); String mainHost = args.get("mainHost").getAsString();
String projectName = json.get("projectName").getAsString(); String projectName = args.get("projectName").getAsString();
String url; String url;
Response response = new Response(); Response response = new Response();
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
String projectDir; String projectDir;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
String strr = "/" + handler.getPubKey(); String strr = "/" + getPubkey(args);
projectDir = GlobalConf.instance.privateDir + strr; projectDir = GlobalConf.instance.privateDir + strr;
// url = // url =
// "http://" // "http://"
@ -1061,25 +1057,25 @@ public class FileActions {
} }
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void renameFile(JsonObject json, ResultCallback resultCallback) { public void renameFile(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onRenameFile"; response.action = "onRenameFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicDir; parPath = GlobalConf.instance.publicDir;
} }
if (GlobalConf.instance.projectDir != null) { if (GlobalConf.instance.projectDir != null) {
try { try {
String oldFile = json.get("oldFile").getAsString(); String oldFile = args.get("oldFile").getAsString();
String newFile = json.get("newFile").getAsString(); String newFile = args.get("newFile").getAsString();
File f = new File(parPath + "/" + oldFile); File f = new File(parPath + "/" + oldFile);
if (!oldFile.contains("..") && !newFile.contains("..") && f.exists()) { if (!oldFile.contains("..") && !newFile.contains("..") && f.exists()) {
File newF = new File(parPath + "/" + newFile); File newF = new File(parPath + "/" + newFile);
@ -1099,19 +1095,19 @@ public class FileActions {
} }
@Action(userPermission = 1L << 14) @Action(userPermission = 1L << 14)
public void createFile(JsonObject json, ResultCallback resultCallback) { public void createFile(JsonObject args, ResultCallback resultCallback) {
String dir = json.get("dir").getAsString(); String dir = args.get("dir").getAsString();
String fileName = json.get("name").getAsString(); String fileName = args.get("name").getAsString();
boolean isFolder = json.get("isFolder").getAsBoolean(); boolean isFolder = args.get("isFolder").getAsBoolean();
if (fileName.contains("..") || dir.contains("..")) { if (fileName.contains("..") || dir.contains("..")) {
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onCreateFile\",\"status\":\"failed\",\"data\":\"incorrect fileName or dir\"}"); "{\"action\":\"onCreateFile\",\"status\":\"failed\",\"data\":\"incorrect fileName or dir\"}");
return; return;
} }
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
if (isLocked(handler.getPubKey())) { if (isLocked(getPubkey(args))) {
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onCreateFile\",\"status\":\"failed\",\"data\":\"locked status\"}"); "{\"action\":\"onCreateFile\",\"status\":\"failed\",\"data\":\"locked status\"}");
@ -1137,8 +1133,8 @@ public class FileActions {
File mainyjs = new File(newFile, fileName + ".yjs"); File mainyjs = new File(newFile, fileName + ".yjs");
FileOutputStream mainyjsFout = new FileOutputStream(mainyjs, false); FileOutputStream mainyjsFout = new FileOutputStream(mainyjs, false);
if (json.has("projectTemplate")) { if (args.has("projectTemplate")) {
switch (json.get("projectTemplate").getAsString()) { switch (args.get("projectTemplate").getAsString()) {
case "数据共享项目": case "数据共享项目":
case "Data Sharing Project": case "Data Sharing Project":
// 注册一个用于授权状态持久化的DO并设置到manifest // 注册一个用于授权状态持久化的DO并设置到manifest
@ -1178,14 +1174,14 @@ public class FileActions {
// return; // return;
// } // }
if (json.has("projectDOI")) if (args.has("projectDOI"))
manifestFout.write( manifestFout.write(
("{\n \"main\":\"" ("{\n \"main\":\""
+ fileName + fileName
+ ".yjs\",\n" + ".yjs\",\n"
+ " \"doipFlag\":true,\n" + " \"doipFlag\":true,\n"
+ " \"doi\":\"" + " \"doi\":\""
+ json.get("projectDOI").getAsString() + args.get("projectDOI").getAsString()
+ "\",\n" + "\",\n"
+ " \"authInfoPersistDOI\":\"" + " \"authInfoPersistDOI\":\""
+ authInfoPersistDOI + authInfoPersistDOI
@ -1214,12 +1210,12 @@ public class FileActions {
.getBytes()); .getBytes());
break; break;
default: default:
if (json.has("projectDOI")) if (args.has("projectDOI"))
manifestFout.write( manifestFout.write(
("{\n \"main\":\"" ("{\n \"main\":\""
+ fileName + fileName
+ ".yjs\",\n \"doipFlag\":true,\n \"doi\":\"" + ".yjs\",\n \"doipFlag\":true,\n \"doi\":\""
+ json.get("projectDOI").getAsString() + args.get("projectDOI").getAsString()
+ "\"\n}") + "\"\n}")
.getBytes()); .getBytes());
else else
@ -1242,20 +1238,20 @@ public class FileActions {
e.printStackTrace(); e.printStackTrace();
} }
} }
listProjects(json, resultCallback); listProjects(args, resultCallback);
} }
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void deleteFile(JsonObject json, ResultCallback resultCallback) { public void deleteFile(JsonObject args, ResultCallback resultCallback) {
Response response = new Response(); Response response = new Response();
response.action = "onDeleteFile"; response.action = "onDeleteFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
boolean compiled = false, isPrivate = false; boolean compiled = false, isPrivate = false;
if (json.has("isCompiled") && json.get("isCompiled").getAsBoolean()) { if (args.has("isCompiled") && args.get("isCompiled").getAsBoolean()) {
compiled = true; compiled = true;
} }
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
isPrivate = true; isPrivate = true;
} }
@ -1264,14 +1260,14 @@ public class FileActions {
if (compiled) { if (compiled) {
if (isPrivate) { if (isPrivate) {
parPath = GlobalConf.instance.privateCompiledDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateCompiledDir + "/" + getPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicCompiledDir; parPath = GlobalConf.instance.publicCompiledDir;
} }
} else { } else {
if (isPrivate) { if (isPrivate) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
if (isLocked(handler.getPubKey())) { if (isLocked(getPubkey(args))) {
response.data = "failed, in locked status"; response.data = "failed, in locked status";
resultCallback.onResult(JsonUtil.toJson(response)); resultCallback.onResult(JsonUtil.toJson(response));
return; return;
@ -1283,7 +1279,7 @@ public class FileActions {
if (GlobalConf.instance.projectDir != null) { if (GlobalConf.instance.projectDir != null) {
try { try {
String oldFile = json.get("file").getAsString(); String oldFile = args.get("file").getAsString();
File f = new File(parPath + "/" + oldFile); File f = new File(parPath + "/" + oldFile);
if (!oldFile.contains("..") && f.exists()) { if (!oldFile.contains("..") && f.exists()) {
@ -1303,7 +1299,7 @@ public class FileActions {
e.printStackTrace(); e.printStackTrace();
} }
} }
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
resultCallback.onResult(JsonUtil.toJson(response)); resultCallback.onResult(JsonUtil.toJson(response));
} }
@ -1361,18 +1357,18 @@ public class FileActions {
// 将私有路径下合约传至共有路径 // 将私有路径下合约传至共有路径
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void changePublic(JsonObject json, ResultCallback resultCallback) throws Exception { public void changePublic(JsonObject args, ResultCallback resultCallback) throws Exception {
String pubkey = handler.getPubKey();
String fileName = json.get("fileName").getAsString(); // 文件夹名 String fileName = args.get("fileName").getAsString(); // 文件夹名
Response response = new Response(); Response response = new Response();
response.action = "onChangePublic"; response.action = "onChangePublic";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
File file = new File(GlobalConf.instance.privateDir + "/" + handler.getPubKey(), fileName); File file = new File(GlobalConf.instance.privateDir + "/" + getPubkey(args), fileName);
LOGGER.debug("[FileActions] from " + file.getAbsolutePath()); LOGGER.debug("[FileActions] from " + file.getAbsolutePath());
File copyFile = new File(GlobalConf.instance.publicDir + "/" + fileName); File copyFile = new File(GlobalConf.instance.publicDir + "/" + fileName);
@ -1393,30 +1389,30 @@ public class FileActions {
// 参数isAppend // 参数isAppend
// 参数content // 参数content
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void uploadFile(JsonObject json, ResultCallback resultCallback) throws Exception { public void uploadFile(JsonObject args, ResultCallback resultCallback) throws Exception {
Response response = new Response(); Response response = new Response();
response.action = "onUploadFile"; response.action = "onUploadFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json); ReplyUtil.injectRequestID(response, args);
String fileName = json.get("fileName").getAsString(); String fileName = args.get("fileName").getAsString();
if (!checkFileType(fileName)) { if (!checkFileType(fileName)) {
response.data = "Illegal file"; response.data = "Illegal file";
resultCallback.onResult(JsonUtil.toJson(response)); resultCallback.onResult(JsonUtil.toJson(response));
return; return;
} }
try { try {
boolean isAppend = json.get("isAppend").getAsBoolean(); boolean isAppend = args.get("isAppend").getAsBoolean();
String path = json.get("path").getAsString(); String path = args.get("path").getAsString();
String content = json.get("content").getAsString(); String content = args.get("content").getAsString();
File target; File target;
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
} else { } else {
parPath = GlobalConf.instance.publicDir; parPath = GlobalConf.instance.publicDir;
} }
@ -1467,6 +1463,16 @@ public class FileActions {
// 参数增加一个type支持text类型和byte[](base64编码后上传) // 参数增加一个type支持text类型和byte[](base64编码后上传)
// 参数增加一个,path? /public/ziptest/xxxxx; /567896789056789/zip // 参数增加一个,path? /public/ziptest/xxxxx; /567896789056789/zip
private String getPubkey(JsonObject args) {
try {
if (handler != null) return handler.getPubKey();
return args.get("pubKey").getAsString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Action(userPermission = 1 << 14) @Action(userPermission = 1 << 14)
public void saveFile(JsonObject json, ResultCallback resultCallback) throws Exception { public void saveFile(JsonObject json, ResultCallback resultCallback) throws Exception {
Response response = new Response(); Response response = new Response();
@ -1483,8 +1489,8 @@ public class FileActions {
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) {
response.isPrivate = true; response.isPrivate = true;
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(json);
if (isLocked(handler.getPubKey())) { if (isLocked(getPubkey(json))) {
response.data = "failed, in locked status"; response.data = "failed, in locked status";
resultCallback.onResult(JsonUtil.toJson(response)); resultCallback.onResult(JsonUtil.toJson(response));
return; return;
@ -1495,13 +1501,14 @@ public class FileActions {
LOGGER.debug("[FileAction] saveFile:" + content); LOGGER.debug("[FileAction] saveFile:" + content);
File target = new File(parPath + "/" + path); File target = new File(parPath + "/" + path);
if (!path.contains("..") && target.exists() && isTextFile(path)) { if (!target.exists()) {
response.data = "failed, file not exists! create file first.";
} else if (!path.contains("..") && isTextFile(path)) {
FileOutputStream fout = new FileOutputStream(target, isAppend); FileOutputStream fout = new FileOutputStream(target, isAppend);
fout.write(content.getBytes()); fout.write(content.getBytes());
fout.close(); fout.close();
changeSet.add(new File(parPath, toProjectName(path)).getAbsolutePath()); changeSet.add(new File(parPath, toProjectName(path)).getAbsolutePath());
response.data = "successs"; response.data = "success";
} else { } else {
response.data = "failed, not text type!"; response.data = "failed, not text type!";
} }
@ -1538,7 +1545,7 @@ public class FileActions {
// ContractManager.toObject(contractDO.elements.get(0).getData()); // ContractManager.toObject(contractDO.elements.get(0).getData());
// String projectName = contractDOI.replace('/', '_'); // String projectName = contractDOI.replace('/', '_');
// String projectDirStr = // String projectDirStr =
// GlobalConf.instance.privateDir + "/" + handler.getPubKey() + "/" + // GlobalConf.instance.privateDir + "/" + getPubkey(args) + "/" +
// projectName; // projectName;
// File projectDir = new File(projectDirStr); // File projectDir = new File(projectDirStr);
// if (projectDir.isDirectory()) { // if (projectDir.isDirectory()) {
@ -1593,7 +1600,7 @@ public class FileActions {
String projectName = args.get("path").getAsString(); String projectName = args.get("path").getAsString();
String parPath = GlobalConf.instance.publicDir; String parPath = GlobalConf.instance.publicDir;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = GlobalConf.instance.privateDir + "/" + handler.getPubKey(); parPath = GlobalConf.instance.privateDir + "/" + getPubkey(args);
} }
String ypkPath = autoCompile(parPath, toProjectName(projectName)); String ypkPath = autoCompile(parPath, toProjectName(projectName));
Map<String, Object> ret = new HashMap<>(); Map<String, Object> ret = new HashMap<>();
@ -1619,9 +1626,14 @@ public class FileActions {
@Action(async = true, userPermission = 1L << 14) @Action(async = true, userPermission = 1L << 14)
public void distributeContract(JsonObject json, ResultCallback resultCallback) { public void distributeContract(JsonObject json, ResultCallback resultCallback) {
if (getPubkey(json).startsWith("04303")) {
resultCallback.onResult("ERROR");
return;
}
SM2KeyPair keyPair = GlobalConf.instance.keyPair; SM2KeyPair keyPair = GlobalConf.instance.keyPair;
json.addProperty("sponsorPubkey", keyPair.getPublicKeyStr()); // 节点 json.addProperty("sponsorPubkey", keyPair.getPublicKeyStr()); // 节点
json.addProperty("pubkey", handler.getPubKey()); // 用户 json.addProperty("pubkey", getPubkey(json)); // 用户
String reqID = String reqID =
System.currentTimeMillis() + "_" + (int) (Math.random() * 10000) + "_distribute"; System.currentTimeMillis() + "_" + (int) (Math.random() * 10000) + "_distribute";
json.addProperty("distributeID", reqID); json.addProperty("distributeID", reqID);

View File

@ -42,11 +42,7 @@ public class ManagerActions {
public void getEncodedUUID(JsonObject args, ResultCallback resultCallback) { public void getEncodedUUID(JsonObject args, ResultCallback resultCallback) {
String data = null; String data = null;
try { try {
data = data = ByteUtils.toHexString(SM2Util.encrypt(GlobalConf.instance.keyPair.getPublicKey(), HardwareInfo.getCPUID().getBytes()));
ByteUtils.toHexString(
SM2Util.encrypt(
GlobalConf.instance.keyPair.getPublicKey(),
HardwareInfo.getCPUID().getBytes()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -55,8 +51,7 @@ public class ManagerActions {
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void downloadUUID(JsonObject args, ResultCallback resultCallback) { public void downloadUUID(JsonObject args, ResultCallback resultCallback) {
String uuid = String uuid = ByteUtil.encodeBASE64(HardwareInfo.getCPUID().getBytes()).replaceAll("\n", "");
ByteUtil.encodeBASE64(HardwareInfo.getCPUID().getBytes()).replaceAll("\n", "");
resultCallback.onResult(uuid); resultCallback.onResult(uuid);
} }
@ -65,8 +60,7 @@ public class ManagerActions {
try { try {
String key = args.get("key").getAsString(); String key = args.get("key").getAsString();
String val = args.get("val").getAsString(); String val = args.get("val").getAsString();
boolean boolean status = true;
status = true;
Object data; Object data;
switch (key) { switch (key) {
case "licence": case "licence":
@ -87,6 +81,9 @@ public class ManagerActions {
case "nodeCenter": case "nodeCenter":
data = status = GlobalConf.resetNodeCenter(val); data = status = GlobalConf.resetNodeCenter(val);
break; break;
case "nodeCenterWS":
data = status = GlobalConf.resetNodeCenterWS(val);
break;
case "nodeName": case "nodeName":
data = status = GlobalConf.resetNodeName(val); data = status = GlobalConf.resetNodeName(val);
break; break;
@ -101,8 +98,9 @@ public class ManagerActions {
return; return;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
ReplyUtil.replyWithStatus(resultCallback, "onUpdateConfig", false, "exception:" + e.getMessage());
} }
resultCallback.onResult("Exception");
} }
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
@ -111,8 +109,7 @@ public class ManagerActions {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("projectDir", GlobalConf.instance.projectDir); data.put("projectDir", GlobalConf.instance.projectDir);
data.put("yjsPath", GlobalConf.instance.yjsPath); data.put("yjsPath", GlobalConf.instance.yjsPath);
if (GlobalConf.instance.datachainConf != null) if (GlobalConf.instance.datachainConf != null) data.put("datachainConf", GlobalConf.instance.datachainConf);
data.put("datachainConf", GlobalConf.instance.datachainConf);
data.put("nodeCenter", GlobalConf.getNodeCenterUrl()); data.put("nodeCenter", GlobalConf.getNodeCenterUrl());
data.put("licence", GlobalConf.instance.licence); data.put("licence", GlobalConf.instance.licence);
data.put("expireTime", new Date(GlobalConf.instance.expireTime) + ""); data.put("expireTime", new Date(GlobalConf.instance.expireTime) + "");
@ -123,13 +120,12 @@ public class ManagerActions {
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
public void listNodeInfos(JsonObject args, ResultCallback resultCallback) { public void listNodeInfos(JsonObject args, ResultCallback resultCallback) {
ControllerManager.getNodeCenterController().getNodeInfos( ControllerManager.getNodeCenterController().getNodeInfos(new ResultCallback() {
new ResultCallback() { @Override
@Override public void onResult(String str) {
public void onResult(String str) { ReplyUtil.replyWithStatus(resultCallback, "onListNodeInfos", true, str);
ReplyUtil.replyWithStatus(resultCallback, "onListNodeInfos", true, str); }
} });
});
} }
@Action(userPermission = 1L << 26) @Action(userPermission = 1L << 26)
@ -154,7 +150,7 @@ public class ManagerActions {
data.put("clusterConnected", String.valueOf(NetworkManager.instance.isConnectedToNodeCenter())); data.put("clusterConnected", String.valueOf(NetworkManager.instance.isConnectedToNodeCenter()));
data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr()); data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr());
data.put("masterAddress", GlobalConf.instance.masterAddress); data.put("masterAddress", GlobalConf.instance.masterAddress);
data.put("nodeCenterWS",GlobalConf.getNodeCenterWSUrl()); data.put("nodeCenterWS", GlobalConf.getNodeCenterWSUrl());
ReplyUtil.replyWithStatus(resultCallback, "onLoadNodeConfig", true, data); ReplyUtil.replyWithStatus(resultCallback, "onLoadNodeConfig", true, data);
} }
@ -164,6 +160,7 @@ public class ManagerActions {
LOGGER.debug(JsonUtil.toJson(args)); LOGGER.debug(JsonUtil.toJson(args));
ReplyUtil.replyWithStatus(resultCallback, "onChangeNodeCenter", true, GlobalConf.resetNodeCenter(val)); ReplyUtil.replyWithStatus(resultCallback, "onChangeNodeCenter", true, GlobalConf.resetNodeCenter(val));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeNodeCenterWS(JsonObject args, ResultCallback resultCallback) { public void changeNodeCenterWS(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
@ -221,8 +218,7 @@ public class ManagerActions {
String pubKey = null; String pubKey = null;
if (json.has("verifiedPubKey")) pubKey = json.get("verifiedPubKey").getAsString(); if (json.has("verifiedPubKey")) pubKey = json.get("verifiedPubKey").getAsString();
if (pubKey == null) { if (pubKey == null) {
resultCallback.onResult( resultCallback.onResult("{\"action\":\"onApplyNodeRole\",\"data\":\"Failed: Illegal user\"}");
"{\"action\":\"onApplyNodeRole\",\"data\":\"Failed: Illegal user\"}");
return; return;
} }
String ro = json.get("role").getAsString(); String ro = json.get("role").getAsString();
@ -230,28 +226,21 @@ public class ManagerActions {
LOGGER.debug("[role]" + ro); LOGGER.debug("[role]" + ro);
Role role = Role.parse(json.get("role").getAsString()); Role role = Role.parse(json.get("role").getAsString());
if (role != Role.Anonymous) { if (role != Role.Anonymous) {
String str = String str = KeyValueDBUtil.instance.getValue(CMTables.ApplyRole.toString(), pubKey);
KeyValueDBUtil.instance.getValue(CMTables.ApplyRole.toString(), pubKey); String already = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey);
String already =
KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey);
if (already != null && already.contains(role.toString())) { if (already != null && already.contains(role.toString())) {
ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "already has!"); ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "already has!");
return; return;
} }
if (str == null || str.length() == 0) { if (str == null || str.length() == 0) {
KeyValueDBUtil.instance.setValue( KeyValueDBUtil.instance.setValue(CMTables.ApplyRole.toString(), pubKey, role.name());
CMTables.ApplyRole.toString(), pubKey, role.name());
} else { } else {
if (!str.contains(role.name())) if (!str.contains(role.name()))
KeyValueDBUtil.instance.setValue( KeyValueDBUtil.instance.setValue(CMTables.ApplyRole.toString(), pubKey, str + "," + role.name());
CMTables.ApplyRole.toString(), pubKey, str + "," + role.name());
} }
KeyValueDBUtil.instance.setValue( KeyValueDBUtil.instance.setValue(CMTables.ApplyTime.toString(), pubKey, Long.toString(new Date().getTime()));
CMTables.ApplyTime.toString(),
pubKey,
Long.toString(new Date().getTime()));
ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "success"); ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "success");
return; return;
@ -261,13 +250,11 @@ public class ManagerActions {
ret.addProperty("action", "onApplyNodeRole"); ret.addProperty("action", "onApplyNodeRole");
ret.addProperty("data", "success"); ret.addProperty("data", "success");
ret.addProperty("role", ro); ret.addProperty("role", ro);
resultCallback.onResult( resultCallback.onResult(ret);
ret);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
resultCallback.onResult( resultCallback.onResult("{\"action\":\"onApplyNodeRole\",\"data\":\"Failed: Exception happened\"}");
"{\"action\":\"onApplyNodeRole\",\"data\":\"Failed: Exception happened\"}");
} }
} }
} }

View File

@ -1,5 +1,7 @@
package org.bdware.server.action; package org.bdware.server.action;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -18,33 +20,34 @@ import org.bdware.server.action.p2p.MasterServerTCPAction;
import org.bdware.server.trustedmodel.MultiPointContractInfo; import org.bdware.server.trustedmodel.MultiPointContractInfo;
import org.bdware.server.trustedmodel.MultiPointCooperateContractInfo; import org.bdware.server.trustedmodel.MultiPointCooperateContractInfo;
import org.bdware.server.trustedmodel.ResultCollector; import org.bdware.server.trustedmodel.ResultCollector;
import org.bdware.server.ws.ContractManagerFrameHandler;
import org.bdware.units.NetworkManager; import org.bdware.units.NetworkManager;
import org.zz.gmhelper.SM2KeyPair; import org.zz.gmhelper.SM2KeyPair;
import org.zz.gmhelper.SM2Util; import org.zz.gmhelper.SM2Util;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// WebSocket接口 // WebSocket接口
public class MasterWSAction { public class MasterWSAction {
private static final Logger LOGGER = LogManager.getLogger(MasterWSAction.class); private static final Logger LOGGER = LogManager.getLogger(MasterWSAction.class);
private final UserManagerAction managerAction; private final ContractManagerFrameHandler handler;
public MasterWSAction(UserManagerAction userManagerAction) { public MasterWSAction(ContractManagerFrameHandler handler) {
this.managerAction = userManagerAction; this.handler = handler;
} }
public static boolean hostMaster(String contractID) { public static boolean hostMaster(String contractID) {
return CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID).isMaster(); return CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID).isMaster();
} }
private boolean waitForConnection(Set<String> nodeNames) { private boolean waitForConnection(List<String> nodeNames) {
LOGGER.info("waitForAllNodes:" + JsonUtil.toJson(nodeNames)); LOGGER.info("waitForAllNodes:" + JsonUtil.toJson(nodeNames));
for (int i = 0; i < 5; i++) { for (int i = 0; i < 500; i++) {
boolean all = true; boolean all = true;
for (String str : nodeNames) { for (String str : nodeNames) {
if (!NetworkManager.instance.hasAgentConnection(str)) { if (!NetworkManager.instance.hasAgentConnection(str)) {
@ -68,6 +71,16 @@ public class MasterWSAction {
return false; return false;
} }
@Action(async = true)
public void warmConnection(JsonObject args, ResultCallback rc) {
long start = System.currentTimeMillis();
JsonArray pubkeys = args.get("pubKeys").getAsJsonArray();
for (JsonElement pri : pubkeys)
NetworkManager.instance.connectToAgent(pri.getAsString(), null);
long end = System.currentTimeMillis();
rc.onResult("{\"duration\":" + (end - start) + ", \"action\":\"onWarmConnection\"}");
}
@Action(async = true, userPermission = 1L << 26) @Action(async = true, userPermission = 1L << 26)
// zyx modified // zyx modified
public void startContractMultiPoint(JsonObject args, final ResultCallback rc) { public void startContractMultiPoint(JsonObject args, final ResultCallback rc) {
@ -92,8 +105,7 @@ public class MasterWSAction {
} else if (args.has("projectName")) { } else if (args.has("projectName")) {
contract.setScript("/" + args.get("projectName").getAsString()); contract.setScript("/" + args.get("projectName").getAsString());
} }
if (args.has("createParam")) if (args.has("createParam")) contract.setCreateParam(args.get("createParam"));
contract.setCreateParam(args.get("createParam"));
// contract.setScript("/" + args.get("projectName").getAsString() + "/manifest.json"); // contract.setScript("/" + args.get("projectName").getAsString() + "/manifest.json");
// String toVerify = // String toVerify =
@ -120,10 +132,7 @@ public class MasterWSAction {
SM2KeyPair sm2Key; SM2KeyPair sm2Key;
String parPath = GlobalConf.instance.publicCompiledDir; String parPath = GlobalConf.instance.publicCompiledDir;
if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) {
parPath = parPath = GlobalConf.instance.privateCompiledDir + "/" + args.get("verifiedPubKey").getAsString();
GlobalConf.instance.privateCompiledDir
+ "/"
+ args.get("verifiedPubKey").getAsString();
} }
String scriptOrPath = contract.getScriptStr(); String scriptOrPath = contract.getScriptStr();
@ -131,8 +140,7 @@ public class MasterWSAction {
scriptOrPath = parPath + contract.getScriptStr(); scriptOrPath = parPath + contract.getScriptStr();
} }
String key = ContractManager.getContractMd5(scriptOrPath, contract); String key = ContractManager.getContractMd5(scriptOrPath, contract);
String privateKeyStr = String privateKeyStr = KeyValueDBUtil.instance.getValue(CMTables.ContractInfo.toString(), key);
KeyValueDBUtil.instance.getValue(CMTables.ContractInfo.toString(), key);
if (privateKeyStr == null || privateKeyStr.length() == 0) { if (privateKeyStr == null || privateKeyStr.length() == 0) {
privateKeyStr = SM2Util.generateSM2KeyPair().toJson(); privateKeyStr = SM2Util.generateSM2KeyPair().toJson();
KeyValueDBUtil.instance.setValue(CMTables.ContractInfo.toString(), key, privateKeyStr); KeyValueDBUtil.instance.setValue(CMTables.ContractInfo.toString(), key, privateKeyStr);
@ -162,7 +170,7 @@ public class MasterWSAction {
} }
} }
*/ */
Set<String> nodeNames; // nodes' peerID List<String> nodeNames; // nodes' peerID
// if (contract.getType().equals(ContractExecType.SelfAdaptiveSharding)) { // if (contract.getType().equals(ContractExecType.SelfAdaptiveSharding)) {
// if (ContractManager.instance.nodeCenterConn.listNodes().length < 3) { // if (ContractManager.instance.nodeCenterConn.listNodes().length < 3) {
// rc.onResult( // rc.onResult(
@ -177,21 +185,17 @@ public class MasterWSAction {
// Math.max(unitSize, 3))); // Math.max(unitSize, 3)));
// } else { // } else {
// all nodes' peerID in the unit // all nodes' peerID in the unit
String[] nodeNamesStr = String[] nodeNamesStr = args.get("peersID").getAsString().split(",");
args.get("peersID").getAsString().split(",");
// record information of these nodes // record information of these nodes
nodeNames = nodeNames = Arrays.stream(nodeNamesStr).filter(x -> null != x && !x.isEmpty()).collect(Collectors.toList());
Arrays.stream(nodeNamesStr)
.filter(x -> null != x && !x.isEmpty())
.collect(Collectors.toSet());
// } // }
String masterNode = GlobalConf.instance.keyPair.getPublicKeyStr(); SM2KeyPair keyPair = GlobalConf.instance.keyPair;
nodeNames.add(masterNode); String masterNode = keyPair.getPublicKeyStr();
assert nodeNames.contains(masterNode);
//nodeNames.add(masterNode);
int nodeSize = nodeNames.size(); int nodeSize = nodeNames.size();
// 方式一向NodeCenter发要求Slave节点主动连接到Master节点. // 方式一向NodeCenter发要求Slave节点主动连接到Master节点.
Map<String, Object> requestConnect = new HashMap<>(); Map<String, Object> requestConnect = new HashMap<>();
requestConnect.put("action", "requestConnectToMaster"); requestConnect.put("action", "requestConnectToMaster");
LOGGER.debug(multiPointContractInfo.masterNode); LOGGER.debug(multiPointContractInfo.masterNode);
@ -200,50 +204,43 @@ public class MasterWSAction {
if (contract.getType() == ContractExecType.Sharding) { if (contract.getType() == ContractExecType.Sharding) {
requestConnect.put("connectAll", true); requestConnect.put("connectAll", true);
} }
NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发 // NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发
waitForConnection(nodeNames); //waitForConnection(nodeNames);
LOGGER.debug(JsonUtil.toPrettyJson(requestConnect)); LOGGER.debug(JsonUtil.toPrettyJson(requestConnect));
ContractManager.threadPool.execute( ContractManager.threadPool.execute(() -> {
() -> { // 多点合约更新repository信息
// 多点合约更新repository信息 if (contract.getDOI() != null && !contract.getDOI().equals("null")) {
if (contract.getDOI() != null && !contract.getDOI().equals("null")) { LOGGER.info("multipoint contract doi register");
LOGGER.info("multipoint contract doi register"); GRPCPool.instance.reRegister(contract.getDOI());
GRPCPool.instance.reRegister(contract.getDOI()); } else {
} else { LOGGER.info("multipoint contract don't update register " + (null == contract.getDOI() ? "null" : contract.getDOI()));
LOGGER.info( }
"multipoint contract don't update register " });
+ (null == contract.getDOI() ? "null" : contract.getDOI()));
}
});
final long curr = System.currentTimeMillis(); final long curr = System.currentTimeMillis();
String requestID = curr + "_" + (int) (Math.random() * 10000); String requestID = curr + "_" + (int) (Math.random() * 10000);
ResultCollector collector = ResultCollector collector = new ResultCollector(requestID, new ResultCallback() {
new ResultCollector( @Override
requestID, public void onResult(String str) {
new ResultCallback() { Map<String, String> ret = new HashMap<>();
@Override ret.put("action", "onStartContractTrustfullyResult");
public void onResult(String str) { if (args.has("requestID")) {
Map<String, String> ret = new HashMap<>(); ret.put("responseID", args.get("requestID").getAsString());
ret.put("action", "onStartContractTrustfullyResult"); }
if (args.has("requestID")) { ret.put("data", str);
ret.put("responseID", args.get("requestID").getAsString()); ret.put("executionTime", (System.currentTimeMillis() - curr) + "");
} rc.onResult(ret);
ret.put("data", str); }
ret.put("executionTime", (System.currentTimeMillis() - curr) + ""); }, nodeSize);
rc.onResult(ret);
}
},
nodeSize);
MasterServerTCPAction.sync.sleepWithTimeout(requestID, collector, 20); MasterServerTCPAction.sync.sleepWithTimeout(requestID, collector, 20);
Map<String, Object> request = new HashMap<>(); Map<String, Object> request = new HashMap<>();
request.put("master", masterNode); request.put("master", keyPair.getPublicKeyStr());
if (args.has("isPrivate")) { if (args.has("isPrivate")) {
request.put("isPrivate", args.get("isPrivate").getAsString()); request.put("isPrivate", args.get("isPrivate").getAsString());
} }
if (args.has("isDebug")) { if (args.has("isDebug")) {
contract.setDebug(args.get("isDebug").getAsBoolean()); contract.setDebug(args.get("isDebug").getAsBoolean());
} }
request.put("pubKey", managerAction.getPubKey()); request.put("pubKey", getPubKey(args));
request.put("action", "startContractTrustfully"); request.put("action", "startContractTrustfully");
request.put("requestID", requestID); request.put("requestID", requestID);
request.put("members", nodeNames); // 执行这个合约的所有节点的pubKey request.put("members", nodeNames); // 执行这个合约的所有节点的pubKey
@ -282,16 +279,14 @@ public class MasterWSAction {
if (!MasterServerRecoverMechAction.recoverStatus.containsKey(nodeID)) { if (!MasterServerRecoverMechAction.recoverStatus.containsKey(nodeID)) {
MasterServerRecoverMechAction.recoverStatus.put(nodeID, new ConcurrentHashMap<>()); MasterServerRecoverMechAction.recoverStatus.put(nodeID, new ConcurrentHashMap<>());
} }
MasterServerRecoverMechAction.recoverStatus MasterServerRecoverMechAction.recoverStatus.get(nodeID).put(contractID, RecoverFlag.Fine);
.get(nodeID)
.put(contractID, RecoverFlag.Fine);
} }
rc.onResult( rc.onResult("{\"status\":\"Success\",\"result\":\"" + contract.getID() + "\"," + "\"action\":\"onStartTrustfulContract\"}");
"{\"status\":\"Success\",\"result\":\""
+ contract.getID()
+ "\","
+ "\"action\":\"onStartTrustfulContract\"}");
LOGGER.info("startContractMultiPoint succeed!"); LOGGER.info("startContractMultiPoint succeed!");
} }
public String getPubKey(JsonObject jo) {
if (handler != null) return handler.getPubKey();
return jo.get("pubKey").getAsString();
}
} }

View File

@ -32,7 +32,7 @@ public class UserManagerAction {
private final Random random = new Random(); private final Random random = new Random();
ContractManagerFrameHandler handler; ContractManagerFrameHandler handler;
private String sessionID; private String sessionID;
private String pubKey; private String publicKey;
public static String getNodeManager() { public static String getNodeManager() {
return KeyValueDBUtil.instance.getValue(CMTables.ConfigDB.toString(), NodeManager); return KeyValueDBUtil.instance.getValue(CMTables.ConfigDB.toString(), NodeManager);
@ -42,6 +42,7 @@ public class UserManagerAction {
handler = contractManagerFrameHandler; handler = contractManagerFrameHandler;
} }
@Action(userPermission = 0) @Action(userPermission = 0)
public void getSessionID(JsonObject json, ResultCallback resultCallback) { public void getSessionID(JsonObject json, ResultCallback resultCallback) {
sessionID = random.nextLong() + "_session_node"; sessionID = random.nextLong() + "_session_node";
@ -57,7 +58,7 @@ public class UserManagerAction {
LOGGER.debug("[NodeManagerAction] session:" + (sessionID)); LOGGER.debug("[NodeManagerAction] session:" + (sessionID));
String pubKey = json.get("pubKey").getAsString(); String pubKey = json.get("pubKey").getAsString();
if (SM2Util.plainStrVerify(pubKey, sessionID, json.get("signature").getAsString())) { if (SM2Util.plainStrVerify(pubKey, sessionID, json.get("signature").getAsString())) {
this.pubKey = pubKey; this.publicKey = pubKey;
counter.inc(); counter.inc();
// 是否有该用户的私有目录,没有就创建 // 是否有该用户的私有目录,没有就创建
// BUG修复需要仅在验证通过后可创建 // BUG修复需要仅在验证通过后可创建
@ -67,7 +68,8 @@ public class UserManagerAction {
} }
getNodeRole(json, resultCallback); getNodeRole(json, resultCallback);
} else { } else {
handler.setPermission(0);
setHandlerPermission(0);
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onLogin\",\"status\":\"verify sign failed\"," + "{\"action\":\"onLogin\",\"status\":\"verify sign failed\"," +
"\"data\":\"" + Role.Anonymous.name() + "\"}"); "\"data\":\"" + Role.Anonymous.name() + "\"}");
@ -75,8 +77,13 @@ public class UserManagerAction {
} }
} }
private void setHandlerPermission(long i) {
if (handler != null) handler.setPermission(i);
}
public void getNodeRole(JsonObject json, ResultCallback resultCallback) { public void getNodeRole(JsonObject json, ResultCallback resultCallback) {
if (pubKey == null) { String pubKey = getPubKey(json);
if (getPubKey(json) == null) {
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onLogin\",\"data\":\"" + Role.Anonymous.name() + "\"}"); "{\"action\":\"onLogin\",\"data\":\"" + Role.Anonymous.name() + "\"}");
return; return;
@ -89,20 +96,20 @@ public class UserManagerAction {
ret = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey); ret = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey);
if (isNodeManager) { if (isNodeManager) {
if (ret != null && ret.length() > 0) { if (ret != null && ret.length() > 0) {
handler.setPermission(0x86000f41L | Role.compoundValue(ret.split(","))); setHandlerPermission(0x86000f41L | Role.compoundValue(ret.split(",")));
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onLogin\",\"data\":\"" + ret + "\"}"); "{\"action\":\"onLogin\",\"data\":\"" + ret + "\"}");
} else { } else {
handler.setPermission(0x86000f41L); setHandlerPermission(0x86000f41L);
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onLogin\",\"data\":\"NodeManager\"}"); "{\"action\":\"onLogin\",\"data\":\"NodeManager\"}");
} }
} else { } else {
if (ret == null || ret.equals("")) { if (ret == null || ret.equals("")) {
ret = Role.Anonymous.name(); ret = Role.Anonymous.name();
handler.setPermission(0); setHandlerPermission(0);
} else { } else {
handler.setPermission(Role.compoundValue(ret.split(","))); setHandlerPermission(Role.compoundValue(ret.split(",")));
} }
resultCallback.onResult("{\"action\":\"onLogin\",\"data\":\"" + ret + "\"}"); resultCallback.onResult("{\"action\":\"onLogin\",\"data\":\"" + ret + "\"}");
} }
@ -112,7 +119,7 @@ public class UserManagerAction {
CMTables.NodeRole.toString(), pubKey, "NodeManager"); CMTables.NodeRole.toString(), pubKey, "NodeManager");
KeyValueDBUtil.instance.setValue( KeyValueDBUtil.instance.setValue(
CMTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime())); CMTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime()));
handler.setPermission(0x86000d41L); setHandlerPermission(0x86000d41L);
resultCallback.onResult("{\"action\":\"onLogin\",\"data\":\"NodeManager\"}"); resultCallback.onResult("{\"action\":\"onLogin\",\"data\":\"NodeManager\"}");
} }
} catch (Exception e) { } catch (Exception e) {
@ -124,7 +131,7 @@ public class UserManagerAction {
@Action(userPermission = 0) @Action(userPermission = 0)
public void applyNodeRole(JsonObject json, ResultCallback resultCallback) { public void applyNodeRole(JsonObject json, ResultCallback resultCallback) {
if (pubKey == null) { if (getPubKey(json) == null) {
resultCallback.onResult("{\"action\":\"onApplyNodeRole\",\"data\":\"missing pubKey\"}"); resultCallback.onResult("{\"action\":\"onApplyNodeRole\",\"data\":\"missing pubKey\"}");
return; return;
} }
@ -133,7 +140,7 @@ public class UserManagerAction {
LOGGER.debug("[role]" + ro); LOGGER.debug("[role]" + ro);
Role role = Role.parse(json.get("role").getAsString()); Role role = Role.parse(json.get("role").getAsString());
if (role != Role.Anonymous) { if (role != Role.Anonymous) {
applyNodeRoleAtDB(role, resultCallback); applyNodeRoleAtDB(role, getPubKey(json), resultCallback);
return; return;
} }
} }
@ -141,7 +148,7 @@ public class UserManagerAction {
"{\"action\":\"onApplyNodeRole\",\"data\":\"success\",\"role\":\"" + ro + "\"}"); "{\"action\":\"onApplyNodeRole\",\"data\":\"success\",\"role\":\"" + ro + "\"}");
} }
private void applyNodeRoleAtDB(Role role, ResultCallback resultCallback) { private void applyNodeRoleAtDB(Role role, String pubKey, ResultCallback resultCallback) {
String str = KeyValueDBUtil.instance.getValue(CMTables.ApplyRole.toString(), pubKey); String str = KeyValueDBUtil.instance.getValue(CMTables.ApplyRole.toString(), pubKey);
String already = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey); String already = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey);
if (already != null && already.contains(role.toString())) { if (already != null && already.contains(role.toString())) {
@ -250,6 +257,9 @@ public class UserManagerAction {
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void authNodeRole(JsonObject json, ResultCallback resultCallback) { public void authNodeRole(JsonObject json, ResultCallback resultCallback) {
String pubKey = json.get("pubKey").getAsString(); String pubKey = json.get("pubKey").getAsString();
if (json.has("authorizedPubKey")) {
pubKey = json.get("authorizedPubKey").getAsString();
}
boolean isAccept = json.get("isAccept").getAsBoolean(); boolean isAccept = json.get("isAccept").getAsBoolean();
if (pubKey == null || pubKey.length() == 0) { if (pubKey == null || pubKey.length() == 0) {
resultCallback.onResult("{\"action\":\"onAuthNodeRole\",\"data\":\"missing pubKey\"}"); resultCallback.onResult("{\"action\":\"onAuthNodeRole\",\"data\":\"missing pubKey\"}");
@ -286,15 +296,25 @@ public class UserManagerAction {
@Action(userPermission = 0) @Action(userPermission = 0)
public void queryRole(JsonObject args, final ResultCallback resultCallback) { public void queryRole(JsonObject args, final ResultCallback resultCallback) {
if (pubKey == null) { String pubkey = getPubKey(args);
if (pubkey == null) {
resultCallback.onResult("{\"action\":\"onQueryRole\",\"data\":\"anonymous\"}"); resultCallback.onResult("{\"action\":\"onQueryRole\",\"data\":\"anonymous\"}");
return; return;
} }
args.addProperty("pubKey", pubKey); args.addProperty("pubKey", pubkey);
args.addProperty("requestID", random.nextLong() + "_ID"); args.addProperty("requestID", random.nextLong() + "_ID");
} }
public String getPubKey() { public String getPubKey() {
return pubKey; return getPubKey(null);
}
private String getPubKey(JsonObject json) {
try {
if (this.publicKey != null) return this.publicKey;
return json.get("pubKey").getAsString();
} catch (Exception e) {
return null;
}
} }
} }

View File

@ -20,8 +20,8 @@ import java.util.Map;
import java.util.TimerTask; import java.util.TimerTask;
public class AliveCheckClientAction { public class AliveCheckClientAction {
public static final int sendDelay = 2000; public static final int sendDelay = 20000;
public static final int checkDelay = 5000; public static final int checkDelay = 50000;
private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class); private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class);
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss"); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss");
private final String masterPubkey; private final String masterPubkey;

View File

@ -11,7 +11,6 @@ import org.bdware.server.action.Action;
import org.bdware.server.tcp.TCPServerFrameHandler; import org.bdware.server.tcp.TCPServerFrameHandler;
import org.bdware.units.NetworkManager; import org.bdware.units.NetworkManager;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
public class AliveCheckServerAction { public class AliveCheckServerAction {
@ -57,10 +56,10 @@ public class AliveCheckServerAction {
try { try {
long cur = System.currentTimeMillis(); long cur = System.currentTimeMillis();
if (cur - lastSlavePingTime >= (2L * delay)) { if (cur - lastSlavePingTime >= (2L * delay)) {
LOGGER.info( // LOGGER.info(
new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(lastSlavePingTime) // new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(lastSlavePingTime)
+ " " // + " "
+ delay); // + delay);
Set<String> contracts = new HashSet<>(); Set<String> contracts = new HashSet<>();
String nodeID = pubKey; String nodeID = pubKey;
if (nodeID == null) { if (nodeID == null) {

View File

@ -59,19 +59,12 @@ public class MasterClientTCPAction {
// } // }
request.put("contractID", contractID); request.put("contractID", contractID);
int lastSeq = int lastSeq = CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID).getLastExeSeq();
CMActions.manager
.multiContractRecorder
.getMultiContractMeta(contractID)
.getLastExeSeq();
request.put("lastExe", lastSeq + ""); request.put("lastExe", lastSeq + "");
request.put("master", "null"); // 不管之前master是哪个NC处是null所有节点重选 request.put("master", "null"); // 不管之前master是哪个NC处是null所有节点重选
if (null != uniNumber) request.put("uniNumber", uniNumber); if (null != uniNumber) request.put("uniNumber", uniNumber);
String members = CMActions.manager String members = CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID).joinMembers(",");
.multiContractRecorder
.getMultiContractMeta(contractID)
.joinMembers(",");
request.put("members", members); request.put("members", members);
NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(request)); NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(request));
@ -114,8 +107,7 @@ public class MasterClientTCPAction {
if (isMultiReq) { if (isMultiReq) {
// 开始执行多点合约请求需要将缓存的其他节点发来的同requestID的请求也触发调用 // 开始执行多点合约请求需要将缓存的其他节点发来的同requestID的请求也触发调用
LOGGER.info("开始执行多点合约请求需要将缓存的其他节点发来的同requestID的请求也触发调用"); LOGGER.info("开始执行多点合约请求需要将缓存的其他节点发来的同requestID的请求也触发调用");
MultiRequestInfo mri = MultiRequestInfo mri = MultiRequestInfo.reqInfos.get(request.getRequestID());
MultiRequestInfo.reqInfos.get(request.getRequestID());
for (String uniID : mri.callbackMap.keySet()) { for (String uniID : mri.callbackMap.keySet()) {
LOGGER.info("触发 uniID=" + uniID); LOGGER.info("触发 uniID=" + uniID);
MultiRequestInfo.exeMultiReq(request, uniID); MultiRequestInfo.exeMultiReq(request, uniID);
@ -142,10 +134,8 @@ public class MasterClientTCPAction {
LOGGER.info("返回 uniID=" + cei.uniReqIDMap.get(seq) + " 的结果"); LOGGER.info("返回 uniID=" + cei.uniReqIDMap.get(seq) + " 的结果");
cei.resultMap.get(seq).onResult(JsonUtil.toJson(ret)); cei.resultMap.get(seq).onResult(JsonUtil.toJson(ret));
cei.setLastExeSeq(seq); cei.setLastExeSeq(seq);
if (KeyValueDBUtil.instance.containsKey( if (KeyValueDBUtil.instance.containsKey(CMTables.LastExeSeq.toString(), contractID)) {
CMTables.LastExeSeq.toString(), contractID)) { KeyValueDBUtil.instance.setValue(CMTables.LastExeSeq.toString(), contractID, seq + "");
KeyValueDBUtil.instance.setValue(
CMTables.LastExeSeq.toString(), contractID, seq + "");
} }
// ledger检查点 public static final int LEDGER_PERIOD = 100; //账本检查点 // ledger检查点 public static final int LEDGER_PERIOD = 100; //账本检查点
@ -154,11 +144,8 @@ public class MasterClientTCPAction {
boolean isMaster = CMActions.manager.getContractIsMaster(contractID); boolean isMaster = CMActions.manager.getContractIsMaster(contractID);
if (isMaster) { if (isMaster) {
String lastHash; String lastHash;
if (KeyValueDBUtil.instance.containsKey( if (KeyValueDBUtil.instance.containsKey(CMTables.CheckPointLastHash.toString(), contractID)) {
CMTables.CheckPointLastHash.toString(), contractID)) { lastHash = KeyValueDBUtil.instance.getValue(CMTables.CheckPointLastHash.toString(), contractID);
lastHash =
KeyValueDBUtil.instance.getValue(
CMTables.CheckPointLastHash.toString(), contractID);
} else { } else {
lastHash = "firstCheckPoint"; lastHash = "firstCheckPoint";
} }
@ -167,8 +154,7 @@ public class MasterClientTCPAction {
map.put("state", state); map.put("state", state);
map.put("lastHash", lastHash); map.put("lastHash", lastHash);
String data = JsonUtil.toJson(map); String data = JsonUtil.toJson(map);
String requestID = String requestID = contractID + "_" + "checkPoint_" + new Random().nextInt();
contractID + "_" + "checkPoint_" + new Random().nextInt();
CheckPointCallback cb = new CheckPointCallback(); CheckPointCallback cb = new CheckPointCallback();
ContractManager.checkPointToLedger(cb, contractID, data, requestID); ContractManager.checkPointToLedger(cb, contractID, data, requestID);
} else { } else {
@ -194,10 +180,7 @@ public class MasterClientTCPAction {
SM2KeyPair keyPair = GlobalConf.instance.keyPair; SM2KeyPair keyPair = GlobalConf.instance.keyPair;
ret.put("nodeID", keyPair.getPublicKeyStr()); ret.put("nodeID", keyPair.getPublicKeyStr());
ret.put("responseID", responseID); ret.put("responseID", responseID);
ContractResult cr = ContractResult cr = new ContractResult(ContractResult.Status.Error, new JsonPrimitive(ComponedContractResult.EXPIRED_REQ));
new ContractResult(
ContractResult.Status.Error,
new JsonPrimitive(ComponedContractResult.EXPIRED_REQ));
ret.put("data", JsonUtil.toJson(cr)); ret.put("data", JsonUtil.toJson(cr));
cb.onResult(JsonUtil.toJson(ret)); cb.onResult(JsonUtil.toJson(ret));
} }
@ -228,8 +211,7 @@ public class MasterClientTCPAction {
public void onKillContractProcess(JsonObject jo, ResultCallback result) { public void onKillContractProcess(JsonObject jo, ResultCallback result) {
LOGGER.info("[MasterClientTCPAction] : onKillContractProcess"); LOGGER.info("[MasterClientTCPAction] : onKillContractProcess");
if (killUnitContractMap.containsKey(jo.get("requestID").getAsString())) { if (killUnitContractMap.containsKey(jo.get("requestID").getAsString())) {
KillUnitContractInfo info = KillUnitContractInfo info = killUnitContractMap.get(jo.get("requestID").getAsString());
killUnitContractMap.get(jo.get("requestID").getAsString());
Map<String, Object> r = new HashMap<>(); Map<String, Object> r = new HashMap<>();
r.put("action", "onKillContractProcess"); r.put("action", "onKillContractProcess");
r.put("data", jo.get("data")); r.put("data", jo.get("data"));
@ -251,12 +233,10 @@ public class MasterClientTCPAction {
ContractClient cc = CMActions.manager.getClient(id); ContractClient cc = CMActions.manager.getClient(id);
if (KeyValueDBUtil.instance.containsKey( if (KeyValueDBUtil.instance.containsKey(CMTables.LastExeSeq.toString(), cc.getContractID())) {
CMTables.LastExeSeq.toString(), cc.getContractID())) {
KeyValueDBUtil.instance.delete(CMTables.LastExeSeq.toString(), cc.getContractID()); KeyValueDBUtil.instance.delete(CMTables.LastExeSeq.toString(), cc.getContractID());
} }
if (KeyValueDBUtil.instance.containsKey( if (KeyValueDBUtil.instance.containsKey(CMTables.UnitContracts.toString(), cc.getContractID())) {
CMTables.UnitContracts.toString(), cc.getContractID())) {
KeyValueDBUtil.instance.delete(CMTables.UnitContracts.toString(), cc.getContractID()); KeyValueDBUtil.instance.delete(CMTables.UnitContracts.toString(), cc.getContractID());
} }
File file = new File(GlobalConf.instance.ADSPDir + "/" + cc.getContractID()); File file = new File(GlobalConf.instance.ADSPDir + "/" + cc.getContractID());
@ -298,8 +278,7 @@ public class MasterClientTCPAction {
} }
//TODO master连接 //TODO master连接
// contractID2MasterInfo.put(contractID, this); // 记录contractID master之间的对应关系 // contractID2MasterInfo.put(contractID, this); // 记录contractID master之间的对应关系
MultiContractMeta multiContractMeta = MultiContractMeta multiContractMeta = CMActions.manager.multiContractRecorder.createIfNotExist(contractID);
CMActions.manager.multiContractRecorder.createIfNotExist(contractID);
multiContractMeta.setLastExeSeq(-1); multiContractMeta.setLastExeSeq(-1);
if (!contract.getScriptStr().startsWith("/")) { if (!contract.getScriptStr().startsWith("/")) {
contract.setScript(dumpToDisk(contract, jo)); contract.setScript(dumpToDisk(contract, jo));
@ -308,6 +287,7 @@ public class MasterClientTCPAction {
String[] pp = contract.getScriptStr().split("/"); String[] pp = contract.getScriptStr().split("/");
String parPath = GlobalConf.instance.publicCompiledDir; String parPath = GlobalConf.instance.publicCompiledDir;
//TODO 第一次来的meta没有cid!!!
synchronized (multiContractMeta) { // 合约执行信息 synchronized (multiContractMeta) { // 合约执行信息
multiContractMeta.setYpkName(pp[pp.length - 1]); multiContractMeta.setYpkName(pp[pp.length - 1]);
multiContractMeta.setMembers(jo.get("members").getAsJsonArray()); multiContractMeta.setMembers(jo.get("members").getAsJsonArray());
@ -315,10 +295,7 @@ public class MasterClientTCPAction {
multiContractMeta.key = contract.getKey(); multiContractMeta.key = contract.getKey();
multiContractMeta.publicKey = contract.getPublicKey(); multiContractMeta.publicKey = contract.getPublicKey();
if (jo.has("isPrivate") && jo.get("isPrivate").getAsBoolean()) { if (jo.has("isPrivate") && jo.get("isPrivate").getAsBoolean()) {
parPath = parPath = GlobalConf.instance.privateCompiledDir + "/" + jo.get("pubKey").getAsString();
GlobalConf.instance.privateCompiledDir
+ "/"
+ jo.get("pubKey").getAsString();
multiContractMeta.setIsPrivate(true); multiContractMeta.setIsPrivate(true);
multiContractMeta.setPubKeyPath(jo.get("pubKey").getAsString()); multiContractMeta.setPubKeyPath(jo.get("pubKey").getAsString());
@ -329,12 +306,7 @@ public class MasterClientTCPAction {
try { try {
File temp = new File(parPath, pp[pp.length - 1]); File temp = new File(parPath, pp[pp.length - 1]);
if (!temp.exists()) { if (!temp.exists()) {
result.onResult( result.onResult(String.format("{\"action\":\"onStartContractTrustfully\",\"result\":\"missing contract files\"," + "\"requestID\":\"%s\",\"pubKey\":\"%s\"}", jo.get("requestID").getAsString(), GlobalConf.instance.keyPair.getPublicKeyStr()));
String.format(
"{\"action\":\"onStartContractTrustfully\",\"result\":\"missing contract files\"," +
"\"requestID\":\"%s\",\"pubKey\":\"%s\"}",
jo.get("requestID").getAsString(),
GlobalConf.instance.keyPair.getPublicKeyStr()));
return; return;
} }
contract.setScript(temp.getAbsolutePath()); contract.setScript(temp.getAbsolutePath());
@ -348,25 +320,19 @@ public class MasterClientTCPAction {
else { else {
multiContractMeta.setIsMaster(true); multiContractMeta.setIsMaster(true);
} }
LOGGER.debug("startup arguments: " + JsonUtil.toJson(contract));
String ret = CMActions.manager.startContract(contract); // 调用CMActions 里的启动合约的方法,启动结果
LOGGER.debug("startup result: " + ret);
CMActions.manager.multiContractRecorder.updateValue(multiContractMeta); CMActions.manager.multiContractRecorder.updateValue(multiContractMeta);
ContractMeta meta = CMActions.manager.statusRecorder.createIfNotExist(contractID); LOGGER.info("startup arguments: " + JsonUtil.toJson(contract));
String ret = CMActions.manager.startContract(contract); // 调用CMActions 里的启动合约的方法,启动结果
LOGGER.info("startup result: " + ret);
//IMPORTANT!!!!!!!!!!
// meta should get after manger.startContract, because startContract reInitilized it!
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(contractID);
//IMPORTANT!!!!!!!!!!
meta.setContractExecutor(createContractExecutor(contract, contractID, jo.get("master").getAsString(), multiContractMeta.getMembers())); // 分配不同的Executor meta.setContractExecutor(createContractExecutor(contract, contractID, jo.get("master").getAsString(), multiContractMeta.getMembers())); // 分配不同的Executor
// TODO 合约终止后从数据库中移除但是为了测试可以人为制造合约终止但不从数据库中移除异常停止 // TODO 合约终止后从数据库中移除但是为了测试可以人为制造合约终止但不从数据库中移除异常停止
KeyValueDBUtil.instance.setValue(CMTables.UnitContracts.toString(), contractID, "exist"); KeyValueDBUtil.instance.setValue(CMTables.UnitContracts.toString(), contractID, "exist");
if (CMActions.manager.getClient(contract.getID()) != null) { if (CMActions.manager.getClient(contract.getID()) != null) {
result.onResult( result.onResult("{\"action\":\"onStartContractTrustfully\",\"result\":\"success\",\"requestID\":\"" + jo.get("requestID").getAsString() + "\",\"pubKey\":\"" + GlobalConf.instance.keyPair.getPublicKeyStr() + "\"}");
"{\"action\":\"onStartContractTrustfully\",\"result\":\"success\",\"requestID\":\""
+ jo.get("requestID").getAsString()
+ "\",\"pubKey\":\""
+ GlobalConf.instance.keyPair.getPublicKeyStr()
+ "\"}");
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} else { } else {
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
@ -385,19 +351,15 @@ public class MasterClientTCPAction {
} }
private String dumpToDisk(Contract contract, JsonObject jo) { private String dumpToDisk(Contract contract, JsonObject jo) {
String scriptName = String scriptName = String.format("Script_%s", Math.abs(contract.getScriptStr().hashCode()));
String.format("Script_%s", Math.abs(contract.getScriptStr().hashCode()));
try { try {
jo.addProperty("isPrivate", true); jo.addProperty("isPrivate", true);
File scriptDir = File scriptDir = new File(GlobalConf.instance.privateCompiledDir, jo.get("pubKey").getAsString());
new File(
GlobalConf.instance.privateCompiledDir, jo.get("pubKey").getAsString());
if (!scriptDir.exists()) { if (!scriptDir.exists()) {
scriptDir.mkdirs(); scriptDir.mkdirs();
} }
FileOutputStream fout = FileOutputStream fout = new FileOutputStream(new File(scriptDir, scriptName + ".ypk"), false);
new FileOutputStream(new File(scriptDir, scriptName + ".ypk"), false);
ZipOutputStream zout = new ZipOutputStream(fout); ZipOutputStream zout = new ZipOutputStream(fout);
zout.putNextEntry(new ZipEntry("/manifest.json")); zout.putNextEntry(new ZipEntry("/manifest.json"));
zout.write(("{\"main\":\"" + scriptName + ".yjs\"}").getBytes()); zout.write(("{\"main\":\"" + scriptName + ".yjs\"}").getBytes());
@ -428,17 +390,10 @@ public class MasterClientTCPAction {
@Action(async = true) @Action(async = true)
public void executeContractLocally(JsonObject jo, ResultCallback result) { public void executeContractLocally(JsonObject jo, ResultCallback result) {
final ContractRequest request = final ContractRequest request = JsonUtil.fromJson(jo.get("data").toString(), ContractRequest.class);
JsonUtil.fromJson(jo.get("data").toString(), ContractRequest.class); // LOGGER.info("[MasterCientTCPAction] executeContractLocally " + JsonUtil.toJson(jo));
LOGGER.info("[MasterCientTCPAction] executeContractLocally " + JsonUtil.toJson(jo));
LOGGER.info( // LOGGER.info("[MasterClient] executeLocally,uniReq:" + jo.get("uniReqID").getAsString() + " ->reqID:" + request.getRequestID() + " " + jo.get("data").toString());
"[MasterClient] executeLocally,uniReq:"
+ jo.get("uniReqID").getAsString()
+ " ->reqID:"
+ request.getRequestID()
+ " "
+ jo.get("data").toString());
// requestOne and responseOne do not need sequencing // requestOne and responseOne do not need sequencing
if (!request.needSeq) { if (!request.needSeq) {
@ -456,8 +411,7 @@ public class MasterClientTCPAction {
result.onResult(JsonUtil.toJson(ret)); result.onResult(JsonUtil.toJson(ret));
} else { // reqeust all response all need seq } else { // reqeust all response all need seq
String contractID = request.getContractID(); String contractID = request.getContractID();
MultiContractMeta cei = MultiContractMeta cei = CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID);
CMActions.manager.multiContractRecorder.getMultiContractMeta(contractID);
boolean putToQueue = false; boolean putToQueue = false;
// 对于多点合约的请求 // 对于多点合约的请求
if (request.getRequestID().endsWith("_mul")) { if (request.getRequestID().endsWith("_mul")) {
@ -469,14 +423,12 @@ public class MasterClientTCPAction {
// cei.curExeSeq + " cei.getLastExeSeq()=" + cei.getLastExeSeq() + " // cei.curExeSeq + " cei.getLastExeSeq()=" + cei.getLastExeSeq() + "
// 非第一个请求"); // 非第一个请求");
MultiRequestInfo mri = MultiRequestInfo mri = MultiRequestInfo.reqInfos.get(request.getRequestID());
MultiRequestInfo.reqInfos.get(request.getRequestID());
if (request.seq == cei.curExeSeq) { if (request.seq == cei.curExeSeq) {
// 正在执行多点请求时收到多点请求说明这个请求不是第一个到的同requestID的请求s // 正在执行多点请求时收到多点请求说明这个请求不是第一个到的同requestID的请求s
mri.callbackMap.put(jo.get("uniReqID").getAsString(), result); mri.callbackMap.put(jo.get("uniReqID").getAsString(), result);
mri.putFlag(jo.get("uniReqID").getAsString(), false); mri.putFlag(jo.get("uniReqID").getAsString(), false);
} else if (request.seq > cei.curExeSeq } else if (request.seq > cei.curExeSeq && request.seq > cei.getLastExeSeq()) {
&& request.seq > cei.getLastExeSeq()) {
mri.callbackMap.put(jo.get("uniReqID").getAsString(), result); mri.callbackMap.put(jo.get("uniReqID").getAsString(), result);
mri.putFlag(jo.get("uniReqID").getAsString(), false); mri.putFlag(jo.get("uniReqID").getAsString(), false);
} }
@ -484,8 +436,7 @@ public class MasterClientTCPAction {
// logger.info("【收到多点合约请求】request.seq=" + request.seq + " cei.curExeSeq=" + // logger.info("【收到多点合约请求】request.seq=" + request.seq + " cei.curExeSeq=" +
// cei.curExeSeq + " cei.getLastExeSeq()=" + cei.getLastExeSeq() + " // cei.curExeSeq + " cei.getLastExeSeq()=" + cei.getLastExeSeq() + "
// 是第一个请求"); // 是第一个请求");
MultiRequestInfo mri = MultiRequestInfo mri = new MultiRequestInfo(request.getRequestID(), request.seq);
new MultiRequestInfo(request.getRequestID(), request.seq);
MultiRequestInfo.reqInfos.put(request.getRequestID(), mri); MultiRequestInfo.reqInfos.put(request.getRequestID(), mri);
cei.addRequestQueue(request, jo.get("uniReqID").getAsString(), result); cei.addRequestQueue(request, jo.get("uniReqID").getAsString(), result);
LOGGER.info("队列中加入请求 " + request.seq); LOGGER.info("队列中加入请求 " + request.seq);
@ -500,13 +451,7 @@ public class MasterClientTCPAction {
} }
} else { } else {
synchronized (cei) { synchronized (cei) {
LOGGER.info( LOGGER.info("合约" + contractID + " 请求序号为 " + request.seq + " 上一次执行请求序号为 " + cei.getLastExeSeq());
"合约"
+ contractID
+ " 请求序号为 "
+ request.seq
+ " 上一次执行请求序号为 "
+ cei.getLastExeSeq());
// cei.printContent(); // cei.printContent();
if (request.seq <= cei.getLastExeSeq()) { if (request.seq <= cei.getLastExeSeq()) {
@ -540,8 +485,7 @@ public class MasterClientTCPAction {
@Action(async = true) @Action(async = true)
public void receiveContractExecutionServer(JsonObject jsonObject, ResultCallback resultCallback) { public void receiveContractExecutionServer(JsonObject jsonObject, ResultCallback resultCallback) {
MasterServerTCPAction.sync.wakeUp( MasterServerTCPAction.sync.wakeUp(jsonObject.get("responseID").getAsString(), jsonObject.get("data").getAsString());
jsonObject.get("responseID").getAsString(), jsonObject.get("data").getAsString());
} }
@Action(async = true) @Action(async = true)
@ -561,56 +505,32 @@ public class MasterClientTCPAction {
@Action(async = true) @Action(async = true)
public void reRouteContract(JsonObject jo, ResultCallback result) { public void reRouteContract(JsonObject jo, ResultCallback result) {
LOGGER.info("Receive Reroute Info:" + jo.toString()); LOGGER.info("Receive Reroute Info:" + jo.toString());
MasterServerTCPAction.sync.instrumentWakeUp( MasterServerTCPAction.sync.instrumentWakeUp(jo.get("responseID").getAsString(), (resultCallback, result1) -> {
jo.get("responseID").getAsString(), resultCallback.cancelTimeOut();
(resultCallback, result1) -> { LOGGER.info("try To reRoute");
resultCallback.cancelTimeOut();
LOGGER.info("try To reRoute");
JsonObject cr = result1.get("data").getAsJsonObject(); JsonObject cr = result1.get("data").getAsJsonObject();
if (resultCallback instanceof SyncResult.ContractResultCallback) { if (resultCallback instanceof SyncResult.ContractResultCallback) {
SyncResult.ContractResultCallback cb = SyncResult.ContractResultCallback cb = (SyncResult.ContractResultCallback) resultCallback;
(SyncResult.ContractResultCallback) resultCallback; if (cb.getReRouteCount() > 0) {
if (cb.getReRouteCount() > 0) { ContractResult contractResult = new ContractResult(ContractResult.Status.Error, new JsonPrimitive("Contract " + cr.get("contractID").getAsString() + "can't be located in router"));
ContractResult contractResult = resultCallback.onResult(JsonUtil.toJson(contractResult));
new ContractResult( return;
ContractResult.Status.Error, } else cb.incReRouteCount();
new JsonPrimitive( LOGGER.info("inc reRoute:" + cb.getReRouteCount());
"Contract " }
+ cr.get("contractID").getAsString() String pubkey = CMActions.manager.nodeCenterConn.reRouteContract(cr.get("contractID").getAsString());
+ "can't be located in router")); LOGGER.info("ReRoute Result:" + cr.get("contractID").getAsString() + " pubKey:" + pubkey);
resultCallback.onResult(JsonUtil.toJson(contractResult));
return;
} else cb.incReRouteCount();
LOGGER.info("inc reRoute:" + cb.getReRouteCount());
}
String pubkey =
CMActions.manager.nodeCenterConn.reRouteContract(
cr.get("contractID").getAsString());
LOGGER.info(
"ReRoute Result:"
+ cr.get("contractID").getAsString()
+ " pubKey:"
+ pubkey);
if (pubkey == null) { if (pubkey == null) {
ContractResult contractResult = ContractResult contractResult = new ContractResult(ContractResult.Status.Error, new JsonPrimitive("Contract " + cr.get("contractID").getAsString() + "can't be located in router using reroute"));
new ContractResult( resultCallback.onResult(JsonUtil.toJson(contractResult));
ContractResult.Status.Error, return;
new JsonPrimitive( }
"Contract " LOGGER.debug("Receive Reroute Result:" + pubkey);
+ cr.get("contractID").getAsString() ContractRequest contractRequest = JsonUtil.fromJson(cr, ContractRequest.class);
+ "can't be located in router using reroute")); CMActions.manager.masterStub.executeByOtherNodeAsync(pubkey, contractRequest, resultCallback);
resultCallback.onResult(JsonUtil.toJson(contractResult)); }, jo);
return;
}
LOGGER.debug("Receive Reroute Result:" + pubkey);
ContractRequest contractRequest =
JsonUtil.fromJson(cr, ContractRequest.class);
CMActions.manager.masterStub.executeByOtherNodeAsync(
pubkey, contractRequest, resultCallback);
},
jo);
} }
// public String requestContractExecution(ContractRequest c) { // public String requestContractExecution(ContractRequest c) {

View File

@ -202,6 +202,8 @@ public class MasterServerRecoverMechAction {
public static void unitModeCheck(String contractID) { public static void unitModeCheck(String contractID) {
String stateful = CMActions.manager.getContractStateful(contractID); String stateful = CMActions.manager.getContractStateful(contractID);
//just disable unitModeCheck
if (stateful!=null) return;
if (stateful.equals("false")) { if (stateful.equals("false")) {
LOGGER.info("无状态集群合约无需运行模式检查及切换!"); LOGGER.info("无状态集群合约无需运行模式检查及切换!");
return; return;

View File

@ -184,7 +184,7 @@ public class MasterServerTCPAction {
@Action(async = true) @Action(async = true)
public void receiveTrustfullyResult(JsonObject jo, ResultCallback cb) { public void receiveTrustfullyResult(JsonObject jo, ResultCallback cb) {
String responseID = jo.get("responseID").getAsString(); String responseID = jo.get("responseID").getAsString();
LOGGER.info("========== ExecuteContractLocally wakeUp:" + responseID); // LOGGER.info("========== ExecuteContractLocally wakeUp:" + responseID);
MasterServerTCPAction.sync.wakeUp(responseID, jo.toString()); MasterServerTCPAction.sync.wakeUp(responseID, jo.toString());
} }

View File

@ -97,7 +97,7 @@ public class _UNUSED_ExecutionAction implements OnHashCallback {
c.setScript(content); c.setScript(content);
} }
content = CMActions.manager.startContractAndRedirect(c, System.out); content = CMActions.manager.startContract(c);
LOGGER.info("[START] result: " + content); LOGGER.info("[START] result: " + content);
result = JsonUtil.fromJson(content, ContractResult.class); result = JsonUtil.fromJson(content, ContractResult.class);
unitContractMessage.msgType = UnitContractMessageType.ContractUnitResponse.getValue(); unitContractMessage.msgType = UnitContractMessageType.ContractUnitResponse.getValue();

View File

@ -30,7 +30,6 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpResponseStatus.OK;
@ -60,17 +59,21 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
}; };
HttpFileHandleAdapter otherFileService = new HttpFileHandleAdapter( HttpFileHandleAdapter otherFileService = new HttpFileHandleAdapter(
new File("./WebContent/").getAbsolutePath(), fileFilter) { new File("./WebContent/").getAbsolutePath(), fileFilter) {
@URIPath({"/client/", "/doc/"}) @URIPath({"/client/", "/doc/", "/blog/"})
private void handleFile(ChannelHandlerContext ctx, FullHttpRequest request) private void handleFile(ChannelHandlerContext ctx, FullHttpRequest request)
throws Exception { throws Exception {
channelRead0(ctx, request); channelRead0(ctx, request);
} }
}; };
UserManagerAction userManagerAction = new UserManagerAction(null);
MasterWSAction masterWSAction = new MasterWSAction(null);
actionExecutor = actionExecutor =
new ActionExecutor<ResultCallback, JsonObject>( new ActionExecutor<ResultCallback, JsonObject>(
ContractManagerFrameHandler.executorService, ContractManagerFrameHandler.executorService,
new CMActions(), new CMActions(),
ManagerActions.instance, ManagerActions.instance,
new FileActions(null),
userManagerAction, masterWSAction,
GRPCPool.instance, GRPCPool.instance,
new HttpFileAction(), new HttpFileAction(),
new BDIndexerAction(), new BDIndexerAction(),
@ -115,11 +118,11 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
return flag && flag2; return flag && flag2;
} }
}; };
if (wsPluginActions != null)
for (String str : wsPluginActions) { for (String str : wsPluginActions) {
Object obj = createInstanceByClzName(str); Object obj = createInstanceByClzName(str);
actionExecutor.appendHandler(obj); actionExecutor.appendHandler(obj);
} }
uriHandlers = new URIHandler(); uriHandlers = new URIHandler();
DOIPOverHttpHandler doipOverHttpHandler = new DOIPOverHttpHandler(); DOIPOverHttpHandler doipOverHttpHandler = new DOIPOverHttpHandler();
@ -171,6 +174,7 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
fullResponse.headers().remove("Access-Control-Allow-Origin"); fullResponse.headers().remove("Access-Control-Allow-Origin");
fullResponse.headers().remove("Access-Control-Allow-Headers"); fullResponse.headers().remove("Access-Control-Allow-Headers");
fullResponse.headers().add("Access-Control-Allow-Origin", "*"); fullResponse.headers().add("Access-Control-Allow-Origin", "*");
fullResponse.headers().add("Access-Control-Allow-Methods", "*");
fullResponse fullResponse
.headers() .headers()
.add("Access-Control-Allow-Headers", .add("Access-Control-Allow-Headers",
@ -183,55 +187,28 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
@URIPath({"/SCIDE/CMManager", "/SCIDE/SCManager"}) @URIPath({"/SCIDE/CMManager", "/SCIDE/SCManager"})
public void handleHttpGet(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { public void handleHttpGet(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
QueryStringDecoder decoderQuery = new QueryStringDecoder(msg.uri()); JsonObject transformedParam = ArgParser.parseGetAndVerify(msg, new ArgParser.VerifiedCallback() {
Map<String, List<String>> parameters = decoderQuery.parameters(); @Override
JsonObject transformedParam = new JsonObject(); public void onResult(boolean verified, JsonObject transformedParam) {
for (String key : parameters.keySet()) { LOGGER.info("verify signature: " + verified + " " + transformedParam.toString());
List<String> val = parameters.get(key); if (verified) {
if (null != val) { // 查permission
transformedParam.addProperty(key, val.get(0)); String pubkey = transformedParam.get("pubKey").getAsString();
} String ret = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubkey);
} long permission;
if (ret != null && ret.length() > 0) {
// 匿名用户权限为0 permission = 0x86000d41L | Role.compoundValue(ret.split(","));
transformedParam.addProperty("permission", 0); } else {
transformedParam.remove("verifiedPubKey"); assert ret != null;
permission = Role.compoundValue(ret.split(","));
// 验签 有pubKey就必须有sign }
String uri = URLDecoder.decode(msg.uri(), "UTF-8").split("\\?")[1]; transformedParam.addProperty("permission", permission);
if (transformedParam.has("pubKey")) { LOGGER.info("user permission: " + permission);
int index = uri.lastIndexOf('&'); transformedParam.addProperty(
String str = uri.substring(0, index); "verifiedPubKey", transformedParam.get("pubKey").getAsString());
LOGGER.info("before verifying: " + str);
boolean verify = false;
try {
verify =
SM2Util.plainStrVerify(
transformedParam.get("pubKey").getAsString(),
str,
transformedParam.get("sign").getAsString());
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.debug(ExceptionUtil.exceptionToString(e));
}
LOGGER.info("verify signature: " + verify);
if (verify) {
// 查permission
String pubkey = transformedParam.get("pubKey").getAsString();
String ret = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubkey);
long permission;
if (ret != null && ret.length() > 0) {
permission = 0x86000d41L | Role.compoundValue(ret.split(","));
} else {
assert ret != null;
permission = Role.compoundValue(ret.split(","));
} }
transformedParam.addProperty("permission", permission);
LOGGER.info("user permission: " + permission);
transformedParam.addProperty(
"verifiedPubKey", transformedParam.get("pubKey").getAsString());
} }
} });
handleReq(transformedParam, ctx, msg); handleReq(transformedParam, ctx, msg);
} }
@ -244,8 +221,6 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
// 倒数第二个参数是pubKey倒数第一个参数是sign // 倒数第二个参数是pubKey倒数第一个参数是sign
// 有pubKey就必须签名 // 有pubKey就必须签名
String uri = URLDecoder.decode(msg.uri(), "UTF-8"); String uri = URLDecoder.decode(msg.uri(), "UTF-8");
LOGGER.info("handle " + uri);
ByteBuf content = msg.content(); ByteBuf content = msg.content();
byte[] reqContent = new byte[content.readableBytes()]; byte[] reqContent = new byte[content.readableBytes()];
content.readBytes(reqContent); content.readBytes(reqContent);
@ -307,7 +282,11 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
DefaultFullHttpResponse response = DefaultFullHttpResponse response =
new DefaultFullHttpResponse( new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, OK, Unpooled.wrappedBuffer(ret)); HttpVersion.HTTP_1_1, OK, Unpooled.wrappedBuffer(ret));
response.headers().add("Access-Control-Allow-Origin", "*");
response.headers().add("Access-Control-Allow-Methods", "*");
ChannelFuture f = ctx.write(response); ChannelFuture f = ctx.write(response);
response.headers().add("Access-Control-Allow-Origin", "*");
response.headers().add("Access-Control-Allow-Methods", "*");
f.addListener(ChannelFutureListener.CLOSE); f.addListener(ChannelFutureListener.CLOSE);
return; return;
} else { } else {
@ -317,14 +296,28 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
HttpResultCallback cb; HttpResultCallback cb;
if (action.equals("downloadContract")) { if (action.equals("downloadContract")) {
cb = new FileDownloaderCallback(ctx, req); cb = new FileDownloaderCallback(ctx, req);
} else if (action.equals("distributeContract")) {
cb = new HttpServerSentEventResultCallback(ctx, null);
cb.addHeader("Access-Control-Allow-Origin", "*");
cb.addHeader("Access-Control-Allow-Methods", "*");
cb.addHeader("Content-Type", "text/event-stream");
cb.addHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
cb.addHeader("Transfer-Encoding", "chunked");
((HttpServerSentEventResultCallback) cb).writeInitialHead();
} else if (map.has("callback")) { } else if (map.has("callback")) {
cb = new HttpResultCallback(ctx, map.get("callback").getAsString()); cb = new HttpResultCallback(ctx, map.get("callback").getAsString());
cb.addHeader("Access-Control-Allow-Origin", "*");
cb.addHeader("Access-Control-Allow-Methods", "*");
cb.addHeader("Content-Type", "application/json"); cb.addHeader("Content-Type", "application/json");
} else { } else {
cb = new HttpResultCallback(ctx, null); cb = new HttpResultCallback(ctx, null);
cb.addHeader("Content-Type", "application/json"); cb.addHeader("Content-Type", "application/json");
cb.addHeader("Access-Control-Allow-Origin", "*");
cb.addHeader("Access-Control-Allow-Methods", "*");
} }
if (map.get("action").getAsString().equals("downloadUUID")) { if (map.get("action").getAsString().equals("downloadUUID")) {
cb.addHeader("Access-Control-Allow-Origin", "*");
cb.addHeader("Access-Control-Allow-Methods", "*");
cb.addHeader("content-disposition", "attachment;filename=encodeduuid.key"); cb.addHeader("content-disposition", "attachment;filename=encodeduuid.key");
} }
actionExecutor.handle(action, map, cb); actionExecutor.handle(action, map, cb);
@ -335,6 +328,8 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1,
OK, OK,
Unpooled.wrappedBuffer(e.getMessage().getBytes())); Unpooled.wrappedBuffer(e.getMessage().getBytes()));
response.headers().add("Access-Control-Allow-Origin", "*");
response.headers().add("Access-Control-Allow-Methods", "*");
ChannelFuture f = ctx.write(response); ChannelFuture f = ctx.write(response);
f.addListener(ChannelFutureListener.CLOSE); f.addListener(ChannelFutureListener.CLOSE);
} catch (Exception e) { } catch (Exception e) {
@ -345,6 +340,8 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1,
OK, OK,
Unpooled.wrappedBuffer(JsonUtil.toJson(ret).getBytes())); Unpooled.wrappedBuffer(JsonUtil.toJson(ret).getBytes()));
response.headers().add("Access-Control-Allow-Origin", "*");
response.headers().add("Access-Control-Allow-Methods", "*");
ChannelFuture f = ctx.write(response); ChannelFuture f = ctx.write(response);
f.addListener(ChannelFutureListener.CLOSE); f.addListener(ChannelFutureListener.CLOSE);
} }

View File

@ -20,10 +20,7 @@ import org.zz.gmhelper.SM2Util;
import java.io.*; import java.io.*;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.EnumSet; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -32,6 +29,28 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
public class DOIPOverHttpHandler { public class DOIPOverHttpHandler {
private static final Logger LOGGER = LogManager.getLogger(DOIPOverHttpHandler.class); private static final Logger LOGGER = LogManager.getLogger(DOIPOverHttpHandler.class);
Map<String, ZipFile> zipFilePool = new HashMap<>(); Map<String, ZipFile> zipFilePool = new HashMap<>();
Map<String, Long> lastVisit = new HashMap<>();
public synchronized void pruneZipPool() {
Set<String> toPrune = new HashSet<>();
long current = System.currentTimeMillis();
for (String str : zipFilePool.keySet()) {
Long last = lastVisit.get(str);
if (last != null && current - last > 30L * 24L * 3600L * 1000L) {
toPrune.add(str);
}
}
for (String str : toPrune) {
try {
ZipFile zf = zipFilePool.get(str);
zipFilePool.remove(str);
lastVisit.remove(str);
zf.close();
} catch (Exception e) {
}
}
}
@URIPath({"/contracts/", "/DOIP/"}) @URIPath({"/contracts/", "/DOIP/"})
public void mockDOIP(ChannelHandlerContext ctx, FullHttpRequest request) { public void mockDOIP(ChannelHandlerContext ctx, FullHttpRequest request) {
@ -142,7 +161,6 @@ public class DOIPOverHttpHandler {
return; return;
} }
// TODO @杨环宇 把zipFilePool用起来做一个延迟关闭的东西避免频繁打开文件的操作
private void sendAssets(JsonObject arg, ChannelHandlerContext ctx) throws Exception { private void sendAssets(JsonObject arg, ChannelHandlerContext ctx) throws Exception {
ContractMeta meta = ContractMeta meta =
@ -153,9 +171,8 @@ public class DOIPOverHttpHandler {
return; return;
} }
String path = arg.get("argument").getAsString(); String path = arg.get("argument").getAsString();
ZipFile zipFile = new ZipFile(new File(meta.contract.getScriptStr())); ZipFile zipFile = getZipFileFromPool(meta.contract.getScriptStr());
ZipEntry zipEntry = zipFile.getEntry(path); ZipEntry zipEntry = zipFile.getEntry(path);
if (zipEntry == null) { if (zipEntry == null) {
HttpFileHandleAdapter.sendError(ctx, HttpResponseStatus.NOT_FOUND); HttpFileHandleAdapter.sendError(ctx, HttpResponseStatus.NOT_FOUND);
return; return;
@ -170,7 +187,7 @@ public class DOIPOverHttpHandler {
@Override @Override
public void operationComplete(Future<? super Void> arg0) throws Exception { public void operationComplete(Future<? super Void> arg0) throws Exception {
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
zipFile.close(); in.close();
} }
}); });
// 写入文件尾部 // 写入文件尾部
@ -178,6 +195,22 @@ public class DOIPOverHttpHandler {
return; return;
} }
private ZipFile getZipFileFromPool(String scriptStr) throws Exception {
try {
ZipFile cachedFile = zipFilePool.get(scriptStr);
if (cachedFile == null) {
cachedFile =
new ZipFile(new File(scriptStr));
zipFilePool.put(scriptStr, cachedFile);
}
lastVisit.put(scriptStr, System.currentTimeMillis());
return cachedFile;
} catch (Exception e) {
e.printStackTrace();
}
return new ZipFile(new File(scriptStr));
}
private void injectExtraArgs(JsonObject transformedParam, String fulluri) { private void injectExtraArgs(JsonObject transformedParam, String fulluri) {
String[] data = fulluri.split("/"); String[] data = fulluri.split("/");
@ -213,7 +246,7 @@ public class DOIPOverHttpHandler {
String path = fulluri.substring(index); String path = fulluri.substring(index);
path = path.replaceAll("\\?.*$", ""); path = path.replaceAll("\\?.*$", "");
if (path.equals("/assets/")) if (path.equals("/assets/"))
path+="index.html"; path += "index.html";
transformedParam.addProperty("argument", path); transformedParam.addProperty("argument", path);
} }
if (assetPath.startsWith("ypk?")) { if (assetPath.startsWith("ypk?")) {

View File

@ -540,9 +540,7 @@ public class NodeCenterClientController implements NodeCenterConn {
} }
public void queryNCRepoDOI(JsonObject json, ResultCallback result) { public void queryNCRepoDOI(JsonObject json, ResultCallback result) {
LOGGER.debug("sendProject: position ---- 3");
String projectName = json.get("projectName").getAsString(); String projectName = json.get("projectName").getAsString();
LOGGER.debug("sendProject: position ---- 3\tprojectName=" + projectName);
String parPath = GlobalConf.instance.publicCompiledDir; String parPath = GlobalConf.instance.publicCompiledDir;
boolean isPrivate = false; boolean isPrivate = false;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) {
@ -563,7 +561,7 @@ public class NodeCenterClientController implements NodeCenterConn {
LOGGER.debug("tempZip = " + tempZip.getAbsolutePath()); LOGGER.debug("tempZip = " + tempZip.getAbsolutePath());
try { try {
FileInputStream fin = new FileInputStream(tempZip); FileInputStream fin = new FileInputStream(tempZip);
byte[] buff = new byte[30 * 1024]; byte[] buff = new byte[500 * 1024];
long total = tempZip.length(); long total = tempZip.length();
LOGGER.debug("temp length = " + total); LOGGER.debug("temp length = " + total);
long count = 0; long count = 0;
@ -663,9 +661,8 @@ public class NodeCenterClientController implements NodeCenterConn {
} }
@Action(async = true) @Action(async = true)
public void onDistribute(JsonObject json, ResultCallback rc) { public void onDistribute(JsonObject json, ResultCallback rc) throws IOException {
if (json.has("over")) { if (json.has("over")) {
String distributeID = null; String distributeID = null;
if (json.has("distributeID")) if (json.has("distributeID"))
distributeID = json.get("distributeID").getAsString(); distributeID = json.get("distributeID").getAsString();
@ -673,6 +670,9 @@ public class NodeCenterClientController implements NodeCenterConn {
ResultCallback to = distributeReqMap.get(distributeID); ResultCallback to = distributeReqMap.get(distributeID);
distributeReqMap.remove(distributeID); distributeReqMap.remove(distributeID);
to.onResult(json.get("content").getAsString()); to.onResult(json.get("content").getAsString());
if (to instanceof Closeable) {
((Closeable) to).close();
}
} else { } else {
String distributeID = json.get("distributeID").getAsString(); String distributeID = json.get("distributeID").getAsString();
distributeReqMap.get(distributeID).onResult(json.get("content").getAsString()); distributeReqMap.get(distributeID).onResult(json.get("content").getAsString());

View File

@ -57,7 +57,7 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
fileAction, fileAction,
ManagerActions.instance, ManagerActions.instance,
userManagerAction, userManagerAction,
new MasterWSAction(userManagerAction), // 多节点执行 new MasterWSAction(this), // 多节点执行
new CMLogAction(), new CMLogAction(),
new ProcessAction(), new ProcessAction(),
GRPCPool.instance, GRPCPool.instance,

View File

@ -132,7 +132,7 @@ public class NetworkManager {
} }
}, },
0, 0,
10, 30 + (int) (20 * Math.random()),
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
@ -217,7 +217,6 @@ public class NetworkManager {
public void connectToAgent(String master, String contractID) { public void connectToAgent(String master, String contractID) {
LOGGER.info("master=" + master); LOGGER.info("master=" + master);
// LOGGER.debug("master=" + master + "\n\trouter=" + slaverRouter.get(master));
Bootstrap b; Bootstrap b;
AgentConnector connector = null; AgentConnector connector = null;
synchronized (CONNECTORS) { synchronized (CONNECTORS) {

View File

@ -1,6 +1,7 @@
package org.bdware.server; package org.bdware.server;
import org.bdware.sc.ContractManager; import org.bdware.sc.ContractManager;
import org.bdware.sc.ContractPort;
import org.bdware.server.action.Action; import org.bdware.server.action.Action;
import org.bdware.server.action.ActionExecutor; import org.bdware.server.action.ActionExecutor;
import org.bdware.server.http.CMHttpHandler; import org.bdware.server.http.CMHttpHandler;
@ -12,6 +13,7 @@ import org.bdware.server.ws.ContractManagerFrameHandler;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
@ -82,8 +84,8 @@ public class PermissionHelper {
} }
@Test @Test
public void listFrontAgentHttpAPIAction() { public void listFrontAgentHttpAPIAction() throws IOException {
ContractManager manager = new ContractManager(); ContractManager.cPort = new ContractPort(1616);
CMHttpHandler handler = new CMHttpHandler(); CMHttpHandler handler = new CMHttpHandler();
parse(handler.actionExecutor.getHandlers(), true); parse(handler.actionExecutor.getHandlers(), true);
} }