public 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) |
void |
clear() |
(package private) T |
generateRandomKey(KBucket<T> bucket)
Generate a random key to go within this bucket
Package private for testing only.
|
Set<T> |
getAll() |
void |
getAll(SelectionCollector<T> collector) |
Set<T> |
getAll(Set<T> toIgnore) |
(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) |
int |
size()
The current number of entries.
|
String |
toString() |
public KBucketSet(I2PAppContext context, T us, int max, int b)
us
- 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)
public boolean add(T peer)
public int size()
public boolean remove(T entry)
public void clear()
public void getAll(SelectionCollector<T> collector)
public List<T> getClosest(int max)
public List<T> getClosest(int max, Collection<T> toIgnore)
public List<T> getClosest(T key, int max)
public List<T> getClosest(T key, int max, Collection<T> toIgnore)
List<KBucket<T>> getBuckets()
int getRange(T key)
public List<T> getExploreKeys(long age)
T generateRandomKey(KBucket<T> bucket)