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;
}
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) {

View File

@ -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;

View File

@ -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:
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;
}
}