|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.i2p.kademlia.KBucketImpl<T>
class KBucketImpl<T extends SimpleDataStructure>
A concurrent implementation using ConcurrentHashSet. The max size (K) may be temporarily exceeded due to concurrency, a pending split, or the behavior of the supplied trimmer, as explained below. The creator is responsible for splits. This class has no knowledge of the DHT base used for XORing, and thus there are no validity checks in add/remove. The begin and end values are immutable. All entries in this bucket will have at least one bit different from us in the range [begin, end] inclusive. Splits must be implemented by creating two new buckets and discarding this one. The keys are kept in a Set and are NOT sorted by last-seen. Per-key last-seen-time, failures, etc. must be tracked elsewhere. If this bucket is full (i.e. begin == end && size == max) then add() will call KBucketTrimmer.trim() do (possibly) remove older entries, and indicate whether to add the new entry. If the trimmer returns true without removing entries, this KBucket will exceed the max size. Refactored from net.i2p.router.networkdb.kademlia
Constructor Summary | |
---|---|
KBucketImpl(I2PAppContext context,
int begin,
int end,
int max,
KBucketTrimmer<T> trimmer)
All entries in this bucket will have at least one bit different from us in the range [begin, end] inclusive. |
Method Summary | |
---|---|
boolean |
add(T peer)
Sets last-changed if rv is true OR if the peer is already present. |
void |
clear()
|
Set<T> |
getEntries()
Retrieve all routing table entries stored in the bucket |
void |
getEntries(SelectionCollector<T> collector)
|
int |
getKeyCount()
Number of keys already contained in this kbucket |
long |
getLastChanged()
The last-changed timestamp, which actually indicates last-added or last-seen. |
int |
getRangeBegin()
Lowest order high bit for difference keys. |
int |
getRangeEnd()
Highest high bit for the difference keys. |
boolean |
remove(T peer)
Remove the key from the bucket |
void |
setLastChanged()
Update the last-changed timestamp to now. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public KBucketImpl(I2PAppContext context, int begin, int end, int max, KBucketTrimmer<T> trimmer)
Method Detail |
---|
public int getRangeBegin()
KBucket
getRangeBegin
in interface KBucket<T extends SimpleDataStructure>
public int getRangeEnd()
KBucket
getRangeEnd
in interface KBucket<T extends SimpleDataStructure>
public int getKeyCount()
KBucket
getKeyCount
in interface KBucket<T extends SimpleDataStructure>
public Set<T> getEntries()
KBucket
getEntries
in interface KBucket<T extends SimpleDataStructure>
public void getEntries(SelectionCollector<T> collector)
getEntries
in interface KBucket<T extends SimpleDataStructure>
public void clear()
clear
in interface KBucket<T extends SimpleDataStructure>
public boolean add(T peer)
add
in interface KBucket<T extends SimpleDataStructure>
public boolean remove(T peer)
KBucket
remove
in interface KBucket<T extends SimpleDataStructure>
public void setLastChanged()
setLastChanged
in interface KBucket<T extends SimpleDataStructure>
public long getLastChanged()
getLastChanged
in interface KBucket<T extends SimpleDataStructure>
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |