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

View File

@ -47,7 +47,8 @@ public class UserManagerAction {
@Action(userPermission = 0)
public void login(JsonObject json, ResultCallback resultCallback) {
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));
String pubKey = json.get("pubKey").getAsString();
@ -64,7 +65,9 @@ public class UserManagerAction {
} else {
handler.setPermission(0);
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.OnHashCallback;
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.util.JsonUtil;
import org.bdware.server.GlobalConf;

View File

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

View File

@ -1,6 +1,6 @@
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.server.GlobalConf;
import org.bdware.units.beans.MultiPointContractInfo;

View File

@ -1,6 +1,6 @@
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.server.GlobalConf;
import org.bdware.units.beans.MultiPointContractInfo;