I understand this questions is strange, not my usual style. I am currently doing a project using a chord implementation in peersim. The code below shows a big integer and some operation being carried out on it. My chordId
is a hash of an object, why would you want to use add()
? what purpose does this serve?
BigInteger base;
if (j == 0)
base = BigInteger.ONE;
else {
base = BigInteger.valueOf(2);
for (int exp = 1; exp < j; exp++) {
base = base.multiply(BigInteger.valueOf(2));
}
}
BigInteger pot = cp.chordId.add(base);
Prior to his the chord Id was just a random integer of the idlength which was 128 bit.
My question therefore is what is the piece of code above add()
used for???
[EDIT]
To put it into a bit of perspective to make this question clearer:
cp.fingerTable[j] = findId(pot, 0, Network.size() - 1);
is called which attempts to find the Id of Pot however it is always returning in error because the chordId created in this method does not exist. I am unsure of what to replace pot with or whether to take it out completely.
[EDIT2]
findId
looks like this (this is not my code hence my confusion :))
public Node findId(BigInteger id, int nodeOne, int nodeTwo) {
if (nodeOne >= (nodeTwo - 1))
return Network.get(nodeOne);
int middle = (nodeOne + nodeTwo) / 2;
if (((middle) >= Network.size() - 1))
System.out.print("ERROR: Middle is bigger than Network.size");
if (((middle) <= 0))
return Network.get(0);
try {
BigInteger newId = ((ChordProtocol) ((Node) Network.get(middle))
.getProtocol(pid)).chordId;
BigInteger lowId;
if (middle > 0)
lowId = ((ChordProtocol) ((Node) Network.get(middle - 1))
.getProtocol(pid)).chordId;
else
lowId = newId;
BigInteger highId = ((ChordProtocol) ((Node) Network
.get(middle + 1)).getProtocol(pid)).chordId;
if (id.compareTo(newId) == 0
|| ((id.compareTo(newId) == 1) && (id.compareTo(highId) == -1))) {
return Network.get(middle);
}
if ((id.compareTo(newId) == -1) && (id.compareTo(lowId) == 1)) {
if (middle > 0)
return Network.get(middle - 1);
else
return Network.get(0);
}
if (id.compareTo(newId) == -1) {
return findId(id, nodeOne, middle);
} else if (id.compareTo(newId) == 1) {
return findId(id, middle, nodeTwo);
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}