mirror of
https://gitee.com/BDWare/cm
synced 2026-03-19 20:39:25 +00:00
fix: fix bugs in DHTUtil
fix the bug in DHTUtil which is wrong arguments when calling constructor of BigInteger
This commit is contained in:
@@ -12,7 +12,10 @@ public class DHTUtil {
|
||||
private static final Map<String, BigInteger> ID_INTEGER_CACHE = new HashMap<>();
|
||||
|
||||
public static String[] getClusterByKey(String key, int k) {
|
||||
String[] nodes = ContractManager.instance.masterStub.listNodes();
|
||||
return getClusterByKey(key, k, ContractManager.instance.masterStub.listNodes());
|
||||
}
|
||||
|
||||
protected static String[] getClusterByKey(String key, int k, String[] nodes) {
|
||||
if (nodes.length == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -41,7 +44,7 @@ public class DHTUtil {
|
||||
if (l + 1 == r) {
|
||||
BigInteger bigL = getBigInteger(nodes[l]),
|
||||
bigR = getBigInteger(nodes[r]);
|
||||
bigH = new BigInteger(hash);
|
||||
bigH = new BigInteger(hash, 16);
|
||||
if (bigR.subtract(bigH).compareTo(bigH.subtract(bigL)) > -1) {
|
||||
selected = nodes[l];
|
||||
m = l;
|
||||
@@ -76,7 +79,7 @@ public class DHTUtil {
|
||||
ret.add(nodes[l--]);
|
||||
} else {
|
||||
if (null == bigH) {
|
||||
bigH = new BigInteger(hash);
|
||||
bigH = new BigInteger(hash, 16);
|
||||
}
|
||||
if (getBigInteger(nodes[r]).subtract(bigH)
|
||||
.compareTo(bigH.subtract(getBigInteger(nodes[l]))) > -1) {
|
||||
@@ -93,7 +96,7 @@ public class DHTUtil {
|
||||
private static BigInteger getBigInteger(String id) {
|
||||
String bigInt = id.substring(2);
|
||||
if (!ID_INTEGER_CACHE.containsKey(bigInt)) {
|
||||
ID_INTEGER_CACHE.put(bigInt, new BigInteger(bigInt));
|
||||
ID_INTEGER_CACHE.put(bigInt, new BigInteger(bigInt, 16));
|
||||
}
|
||||
return ID_INTEGER_CACHE.get(bigInt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user