@Test public void testAddOrUpdate() { for (KBucket bucket: buckets) { KademliaPeer[] peers = destinationMap.get(bucket); bucket.addOrUpdate(peers[0]); assertEquals(1, bucket.size()); assertEquals(peers[0], bucket.iterator().next()); bucket.addOrUpdate(peers[0]); assertEquals(1, bucket.size()); assertEquals(peers[0], bucket.iterator().next()); bucket.addOrUpdate(peers[1]); assertEquals(2, bucket.size()); assertEquals(peers[0], bucket.getPeer(peers[0])); assertEquals(peers[1], bucket.getPeer(peers[1])); } }
void addOrUpdate(KademliaPeer peer) { int index = getPeerIndex(peer); if (index >= 0) { KademliaPeer existingPeer = peers.remove(index); existingPeer.responseReceived(); add(existingPeer); } else { if (!isFull()) add(peer); else addOrUpdateReplacement(peer); } }
KBucket extends AbstractBucket { void addOrUpdate(KademliaPeer peer) { int index = getPeerIndex(peer); if (index >= 0) { KademliaPeer existingPeer = peers.remove(index); existingPeer.responseReceived(); add(existingPeer); } else { if (!isFull()) add(peer); else addOrUpdateReplacement(peer); } } }
KBucket extends AbstractBucket { void addOrUpdate(KademliaPeer peer) { int index = getPeerIndex(peer); if (index >= 0) { KademliaPeer existingPeer = peers.remove(index); existingPeer.responseReceived(); add(existingPeer); } else { if (!isFull()) add(peer); else addOrUpdateReplacement(peer); } } KBucket(BigInteger startId, BigInteger endId, int depth); }
KBucket extends AbstractBucket { void addOrUpdate(KademliaPeer peer) { int index = getPeerIndex(peer); if (index >= 0) { KademliaPeer existingPeer = peers.remove(index); existingPeer.responseReceived(); add(existingPeer); } else { if (!isFull()) add(peer); else addOrUpdateReplacement(peer); } } KBucket(BigInteger startId, BigInteger endId, int depth); void setLastLookupTime(long lastLookupTime); long getLastLookupTime(); @Override String toString(); }
KBucket extends AbstractBucket { void addOrUpdate(KademliaPeer peer) { int index = getPeerIndex(peer); if (index >= 0) { KademliaPeer existingPeer = peers.remove(index); existingPeer.responseReceived(); add(existingPeer); } else { if (!isFull()) add(peer); else addOrUpdateReplacement(peer); } } KBucket(BigInteger startId, BigInteger endId, int depth); void setLastLookupTime(long lastLookupTime); long getLastLookupTime(); @Override String toString();  }