Merge branch 'master' of gitee.com:BDWare/common

This commit is contained in:
CaiHQ 2021-11-01 16:46:23 +08:00
commit 0dba1fe49a
3 changed files with 17 additions and 39 deletions

View File

@ -96,8 +96,8 @@ public class HashUtil {
return h; return h;
} }
public static String sha3(String value) { public static String sha3(String... value) {
return Hex.toHexString(DIGEST_SHA3.digest(value.getBytes(StandardCharsets.UTF_8))); return Hex.toHexString(DIGEST_SHA3.digest(String.join("", value).getBytes(StandardCharsets.UTF_8)));
} }
public static String sha3ToFixedLen(String value, int len) { public static String sha3ToFixedLen(String value, int len) {

View File

@ -22,6 +22,15 @@ public interface NodeCenterConn {
JsonObject checkIsContract(String requestID, String json); 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 { class NodeKey {
public String id; public String id;
public BigInteger biId; public BigInteger biId;

View File

@ -11,51 +11,20 @@ public enum ContractExecType implements Serializable {
RequestAllResponseAll, RequestAllResponseAll,
Shading;//分片执行模式 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) { public static ContractExecType getContractTypeByInt(int i) {
switch (i) { ContractExecType[] values = ContractExecType.values();
case 1: if (i < 0 || i >= values.length) {
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; return Sole;
} }
return ContractExecType.values()[i];
} }
public boolean needSeq() { public boolean needSeq() {
boolean res = true;
switch (this) { switch (this) {
case Sole: case Sole:
case RequestOnce: case RequestOnce:
case ResponseOnce: case ResponseOnce:
res = false; return false;
break;
case RequestAllResponseAll: case RequestAllResponseAll:
case RequestAllResponseFirst: case RequestAllResponseFirst:
case RequestAllResponseHalf: case RequestAllResponseHalf:
@ -63,6 +32,6 @@ public enum ContractExecType implements Serializable {
default: default:
break; break;
} }
return res; return true;
} }
} }