T - type of SimpleDataStructure objects stored in bucketspublic class KBucketSet<T extends SimpleDataStructure> extends Object
| Constructor and Description |
|---|
KBucketSet(I2PAppContext context,
T us,
int max,
int b)Use the default trim strategy, which removes a random entry. |
KBucketSet(I2PAppContext context,
T us,
int max,
int b,
KBucketTrimmer<T> trimmer)Use the supplied trim strategy. |
| Modifier and Type | Method and Description |
|---|---|
boolean | add(T peer)Add a peer to the appropriate bucket. |
void | clear()Clear all buckets. |
(package private) T | generateRandomKey(KBucket<T> bucket)Generate a random key to go within this bucket
Package private for testing only. |
Set<T> | getAll()Return all entries in all buckets. |
void | getAll(SelectionCollector<T> collector)Add all entries in all buckets to the provided collector. |
Set<T> | getAll(Set<T> toIgnore)Get all entries in all buckets, excluding the specified entries. |
(package private) List<KBucket<T>> | getBuckets()Returned list is a copy of the bucket list, closest first,
with the actual buckets (not a copy). |
List<T> | getClosest(int max)The keys closest to us. |
List<T> | getClosest(int max,
Collection<T> toIgnore)The keys closest to us. |
List<T> | getClosest(T key,
int max)The keys closest to the key. |
List<T> | getClosest(T key,
int max,
Collection<T> toIgnore)The keys closest to the key. |
List<T> | getExploreKeys(long age)For every bucket that hasn't been updated in this long,
or isn't close to full,
generate a random key that would be a member of that bucket. |
(package private) int | getRange(T key)The number of bits minus 1 (range number) for the xor of the key. |
boolean | remove(T entry)Remove a peer from its bucket. |
int | size()The current number of entries. |
String | toString() |
public KBucketSet(I2PAppContext context, T us, int max, int b)
context - the router contextus - the local identity (typically a SHA1Hash or Hash)
The class must have a zero-argument constructor.max - the Kademlia value "k", the max per bucket, k >= 4b - the Kademlia value "b", split buckets an extra 2**(b-1) times,
b > 0, use 1 for bittorrent, Kademlia paper recommends 5public KBucketSet(I2PAppContext context, T us, int max, int b, KBucketTrimmer<T> trimmer)
context - the router contextus - the local identitymax - the Kademlia value "k", the max per bucketb - the Kademlia value "b"trimmer - the trim strategypublic boolean add(T peer)
peer - the peerpublic void clear()
T generateRandomKey(KBucket<T> bucket)
bucket - the bucketpublic void getAll(SelectionCollector<T> collector)
collector - the collector to add entries topublic Set<T> getAll(Set<T> toIgnore)
toIgnore - entries to excludeList<KBucket<T>> getBuckets()
public List<T> getClosest(int max)
max - maximum number of keys to returnpublic List<T> getClosest(int max, Collection<T> toIgnore)
max - maximum number of keys to returntoIgnore - entries to excludepublic List<T> getClosest(T key, int max)
key - the target keymax - maximum number of keys to returnpublic List<T> getClosest(T key, int max, Collection<T> toIgnore)
key - the target keymax - maximum number of keys to returntoIgnore - entries to excludepublic List<T> getExploreKeys(long age)
age - the maximum age in millisecondsint getRange(T key)
key - the keypublic boolean remove(T entry)
entry - the peer to removepublic int size()