diff --git a/src/main/base/org/bdware/sc/util/HashUtil.java b/src/main/base/org/bdware/sc/util/HashUtil.java index 57f457a..403dec1 100644 --- a/src/main/base/org/bdware/sc/util/HashUtil.java +++ b/src/main/base/org/bdware/sc/util/HashUtil.java @@ -96,8 +96,8 @@ public class HashUtil { return h; } - public static String sha3(String value) { - return Hex.toHexString(DIGEST_SHA3.digest(value.getBytes(StandardCharsets.UTF_8))); + public static String sha3(String... value) { + return Hex.toHexString(DIGEST_SHA3.digest(String.join("", value).getBytes(StandardCharsets.UTF_8))); } public static String sha3ToFixedLen(String value, int len) { diff --git a/src/main/entry/org/bdware/sc/NodeCenterConn.java b/src/main/entry/org/bdware/sc/NodeCenterConn.java index b98cb22..a8acfdf 100644 --- a/src/main/entry/org/bdware/sc/NodeCenterConn.java +++ b/src/main/entry/org/bdware/sc/NodeCenterConn.java @@ -22,6 +22,15 @@ public interface NodeCenterConn { JsonObject checkIsContract(String requestID, String json); + /** + * get k nearest nodes to the key in the hash function range + * + * @param key the key + * @param k the number of required node ids + * @return ids of k nearest nodes + */ + String[] getClusterByKey(String key, int k); + class NodeKey { public String id; public BigInteger biId; diff --git a/src/main/entry/org/bdware/sc/bean/ContractExecType.java b/src/main/entry/org/bdware/sc/bean/ContractExecType.java index 0411edb..3300d05 100644 --- a/src/main/entry/org/bdware/sc/bean/ContractExecType.java +++ b/src/main/entry/org/bdware/sc/bean/ContractExecType.java @@ -11,51 +11,20 @@ public enum ContractExecType implements Serializable { RequestAllResponseAll, Shading;//分片执行模式 - public static boolean needSeq(ContractExecType ct) { - boolean res = true; - switch (ct) { - case Sole: - case RequestOnce: - case ResponseOnce: - res = false; - break; - case RequestAllResponseAll: - case RequestAllResponseFirst: - case RequestAllResponseHalf: - case Shading: - default: - break; - } - return res; - } - public static ContractExecType getContractTypeByInt(int i) { - switch (i) { - case 1: - return RequestOnce; - case 2: - return ResponseOnce; - case 3: - return RequestAllResponseFirst; - case 4: - return RequestAllResponseHalf; - case 5: - return RequestAllResponseAll; - case 6: - return Shading; - default: - return Sole; + ContractExecType[] values = ContractExecType.values(); + if (i < 0 || i >= values.length) { + return Sole; } + return ContractExecType.values()[i]; } public boolean needSeq() { - boolean res = true; switch (this) { case Sole: case RequestOnce: case ResponseOnce: - res = false; - break; + return false; case RequestAllResponseAll: case RequestAllResponseFirst: case RequestAllResponseHalf: @@ -63,6 +32,6 @@ public enum ContractExecType implements Serializable { default: break; } - return res; + return true; } }