refactor: move pbft classes

This commit is contained in:
CaiHQ 2021-11-28 14:52:09 +08:00
parent 7efdeff5bc
commit 1dc3790784
7 changed files with 47 additions and 27 deletions

View File

@ -36,6 +36,6 @@ public class EventActions {
CMActions.manager.subEventByClient(topic, rcb.getChannel()); CMActions.manager.subEventByClient(topic, rcb.getChannel());
ret.addProperty("status", "Success"); ret.addProperty("status", "Success");
ret.addProperty("data", topic); ret.addProperty("data", topic);
rcb.onResult(ret.toString()); rcb.onResult(ret);
} }
} }

View File

@ -35,7 +35,6 @@ import org.bdware.server.http.URIPath;
import org.bdware.server.nodecenter.Response; import org.bdware.server.nodecenter.Response;
import org.bdware.server.permission.Role; import org.bdware.server.permission.Role;
import org.bdware.server.ws.ContractManagerFrameHandler; import org.bdware.server.ws.ContractManagerFrameHandler;
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;
@ -631,27 +630,24 @@ public class FileActions {
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void lockEdit(JsonObject args, ResultCallback resultCallback) { public void lockEdit(JsonObject args, ResultCallback resultCallback) {
if (!args.has("pubKey")) { if (!args.has("pubKey")) {
resultCallback.onResult( ReplyUtil.replyWithStatus(resultCallback, "onLockEdit", false, "missing pubkey");
"{\"action\":\"onLockEdit\",\"status\":\"failed\",\"data\":\"missing pubKey\"}");
return; return;
} }
String pubKey = args.get("pubKey").getAsString(); String pubKey = args.get("pubKey").getAsString();
KeyValueDBUtil.instance.setValue(CMTables.LockedUser.toString(), pubKey, "locked"); KeyValueDBUtil.instance.setValue(CMTables.LockedUser.toString(), pubKey, "locked");
resultCallback.onResult( ReplyUtil.replyWithStatus(resultCallback, "onLockEdit", true, pubKey);
"{\"action\":\"onLockEdit\",\"status\":\"success\",\"data\":\"" + pubKey + "\"}");
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void unlockEdit(JsonObject args, ResultCallback resultCallback) { public void unlockEdit(JsonObject args, ResultCallback resultCallback) {
if (!args.has("pubKey")) { if (!args.has("pubKey")) {
resultCallback.onResult( ReplyUtil.replyWithStatus(resultCallback, "onUnlockEdit", false, "missing pubkey");
"{\"action\":\"onUnLockEdit\",\"status\":\"failed\",\"data\":\"missing pubKey\"}");
return; return;
} }
String pubKey = args.get("pubKey").getAsString(); String pubKey = args.get("pubKey").getAsString();
KeyValueDBUtil.instance.delete(CMTables.LockedUser.toString(), pubKey); KeyValueDBUtil.instance.delete(CMTables.LockedUser.toString(), pubKey);
resultCallback.onResult( ReplyUtil.replyWithStatus(resultCallback, "onUnlockEdit", true, pubKey);
"{\"action\":\"onUnlockEdit\",\"status\":\"success\",\"data\":\"" + pubKey + "\"}");
} }
@Action(userPermission = 1L << 17, async = true) @Action(userPermission = 1L << 17, async = true)
@ -677,7 +673,7 @@ public class FileActions {
Map<String, String> r = new HashMap<>(); Map<String, String> r = new HashMap<>();
r.put("action", "onCompile"); r.put("action", "onCompile");
r.put("result", compileInternal(parPath, projectName, isPrivate, false)); r.put("result", compileInternal(parPath, projectName, isPrivate, false));
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
} }
@Action(userPermission = 1L << 17, async = true) @Action(userPermission = 1L << 17, async = true)
@ -718,11 +714,11 @@ public class FileActions {
} }
} }
} else { } else {
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
return; return;
} }
if (manifest == null) { if (manifest == null) {
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
return; return;
} }
@ -744,7 +740,7 @@ public class FileActions {
if (doi == null) { if (doi == null) {
r.put("result", "get doi register failed!"); r.put("result", "get doi register failed!");
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
return; return;
} }
@ -793,7 +789,7 @@ public class FileActions {
changeSet.remove(dir.getAbsolutePath()); changeSet.remove(dir.getAbsolutePath());
r.put("result", doi); r.put("result", doi);
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
} }
@Action(userPermission = 1L << 17) @Action(userPermission = 1L << 17)
@ -803,7 +799,7 @@ public class FileActions {
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
ReplyUtil.injectRequestID(response, json);
File f; File f;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) {
@ -812,6 +808,7 @@ public class FileActions {
} else { } else {
f = new File(GlobalConf.instance.publicCompiledDir); f = new File(GlobalConf.instance.publicCompiledDir);
} }
ReplyUtil.injectRequestID(response, json);
returnFileListResponse(resultCallback, response, dirs, f); returnFileListResponse(resultCallback, response, dirs, f);
} }
@ -824,6 +821,7 @@ public class FileActions {
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
ReplyUtil.injectRequestID(response, json);
File f; File f;
@ -858,6 +856,8 @@ public class FileActions {
response.action = "onGetProject"; response.action = "onGetProject";
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
String project = json.get("project").getAsString(); String project = json.get("project").getAsString();
@ -891,6 +891,8 @@ public class FileActions {
String project = json.get("project").getAsString(); String project = json.get("project").getAsString();
response.data = "[]"; response.data = "[]";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
ListProjectResp resp = new ListProjectResp(); ListProjectResp resp = new ListProjectResp();
// List<String> dirs = new ArrayList<>(); // List<String> dirs = new ArrayList<>();
@ -928,6 +930,9 @@ public class FileActions {
Response response = new Response(); Response response = new Response();
response.action = "onListFile"; response.action = "onListFile";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
ListProjectResp resp = new ListProjectResp(); ListProjectResp resp = new ListProjectResp();
String parPath; String parPath;
@ -964,6 +969,7 @@ public class FileActions {
String url; String url;
Response response = new Response(); Response response = new Response();
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
String projectDir; String projectDir;
@ -1078,6 +1084,7 @@ public class FileActions {
response.action = "onRenameFile"; response.action = "onRenameFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
String parPath; String parPath;
if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) { if (json.has("isPrivate") && json.get("isPrivate").getAsBoolean()) {
@ -1314,6 +1321,7 @@ public class FileActions {
e.printStackTrace(); e.printStackTrace();
} }
} }
ReplyUtil.injectRequestID(response, json);
resultCallback.onResult(JsonUtil.toJson(response)); resultCallback.onResult(JsonUtil.toJson(response));
} }
@ -1336,7 +1344,7 @@ public class FileActions {
ret.put("data", dirs); ret.put("data", dirs);
} }
ret.put("action", "onListMemoryFiles"); ret.put("action", "onListMemoryFiles");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(userPermission = 1L << 23) @Action(userPermission = 1L << 23)
@ -1346,6 +1354,7 @@ public class FileActions {
response.data = "failed"; response.data = "failed";
String contractName = json.get("contractName").getAsString(); String contractName = json.get("contractName").getAsString();
String path = GlobalConf.instance.memoryDir + "/" + contractName; String path = GlobalConf.instance.memoryDir + "/" + contractName;
ReplyUtil.injectRequestID(response, json);
try { try {
String fileName = json.get("file").getAsString(); String fileName = json.get("file").getAsString();
@ -1379,6 +1388,7 @@ public class FileActions {
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
File file = new File(GlobalConf.instance.privateDir + "/" + handler.getPubKey(), fileName); File file = new File(GlobalConf.instance.privateDir + "/" + handler.getPubKey(), fileName);
LOGGER.debug("[FileActions] from " + file.getAbsolutePath()); LOGGER.debug("[FileActions] from " + file.getAbsolutePath());
@ -1406,6 +1416,7 @@ public class FileActions {
response.action = "onUploadFile"; response.action = "onUploadFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
String fileName = json.get("fileName").getAsString(); String fileName = json.get("fileName").getAsString();
if (!checkFileType(fileName)) { if (!checkFileType(fileName)) {
@ -1480,6 +1491,8 @@ public class FileActions {
response.action = "onSaveFile"; response.action = "onSaveFile";
response.data = "failed"; response.data = "failed";
response.isPrivate = false; response.isPrivate = false;
ReplyUtil.injectRequestID(response, json);
try { try {
boolean isAppend = json.get("isAppend").getAsBoolean(); boolean isAppend = json.get("isAppend").getAsBoolean();
String path = json.get("path").getAsString(); String path = json.get("path").getAsString();

View File

@ -47,7 +47,8 @@ public class UserManagerAction {
@Action(userPermission = 0) @Action(userPermission = 0)
public void login(JsonObject json, ResultCallback resultCallback) { public void login(JsonObject json, ResultCallback resultCallback) {
if (sessionID == null) { if (sessionID == null) {
resultCallback.onResult("{\"action\":\"onLogin\",\"data\":\"failed\"}"); resultCallback.onResult("{\"action\":\"onLogin\",\"status\":\"failed, no session\"," +
"\"data\":\"" + Role.Anonymous.name() + "\"}");
} }
LOGGER.debug("[NodeManagerAction] session:" + (sessionID)); LOGGER.debug("[NodeManagerAction] session:" + (sessionID));
String pubKey = json.get("pubKey").getAsString(); String pubKey = json.get("pubKey").getAsString();
@ -64,7 +65,9 @@ public class UserManagerAction {
} else { } else {
handler.setPermission(0); handler.setPermission(0);
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onLogin\",\"data\":\"" + Role.Anonymous.name() + "\"}"); "{\"action\":\"onLogin\",\"status\":\"verify sign failed\"," +
"\"data\":\"" + Role.Anonymous.name() + "\"}");
} }
} }

View File

@ -11,7 +11,11 @@ import org.bdware.sc.bean.ContractRequest;
import org.bdware.sc.conn.Node; import org.bdware.sc.conn.Node;
import org.bdware.sc.conn.OnHashCallback; import org.bdware.sc.conn.OnHashCallback;
import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.conn.ResultCallback;
import org.bdware.sc.sequencing.*; import org.bdware.sc.consistency.Committer;
import org.bdware.sc.consistency.pbft.PBFTAlgorithm;
import org.bdware.sc.consistency.pbft.PBFTMember;
import org.bdware.sc.consistency.pbft.PBFTMessage;
import org.bdware.sc.consistency.pbft.PBFTType;
import org.bdware.sc.units.*; import org.bdware.sc.units.*;
import org.bdware.sc.util.JsonUtil; import org.bdware.sc.util.JsonUtil;
import org.bdware.server.GlobalConf; import org.bdware.server.GlobalConf;

View File

@ -1,7 +1,7 @@
package org.bdware.units.consensus; package org.bdware.units.consensus;
import org.bdware.sc.conn.Node; import org.bdware.sc.conn.Node;
import org.bdware.sc.sequencing.Committer; import org.bdware.sc.consistency.Committer;
import org.bdware.sc.units.TrustfulExecutorConnection; import org.bdware.sc.units.TrustfulExecutorConnection;
public interface ConsensusAlgorithm { public interface ConsensusAlgorithm {

View File

@ -1,6 +1,6 @@
package org.bdware.units.consensus; package org.bdware.units.consensus;
import org.bdware.sc.sequencing.PBFTType; import org.bdware.sc.consistency.pbft.PBFTType;
import org.bdware.sc.util.JsonUtil; import org.bdware.sc.util.JsonUtil;
import org.bdware.server.GlobalConf; import org.bdware.server.GlobalConf;
import org.bdware.units.beans.MultiPointContractInfo; import org.bdware.units.beans.MultiPointContractInfo;

View File

@ -1,6 +1,6 @@
package org.bdware.units.consensus; package org.bdware.units.consensus;
import org.bdware.sc.sequencing.PBFTType; import org.bdware.sc.consistency.pbft.PBFTType;
import org.bdware.sc.util.JsonUtil; import org.bdware.sc.util.JsonUtil;
import org.bdware.server.GlobalConf; import org.bdware.server.GlobalConf;
import org.bdware.units.beans.MultiPointContractInfo; import org.bdware.units.beans.MultiPointContractInfo;