net.i2p.router.networkdb.kademlia

## Class KBucketImpl

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.KBucketImpl

All Implemented Interfaces:
  KBucket

     class KBucketImpl
    extends Object
    implements KBucket

### Constructor Summary

Constructors
Constructor and Description
`KBucketImpl(I2PAppContext context, Hash local)` for testing - use above constructor for production to get common caching
`KBucketImpl(I2PAppContext context, LocalHash local)`

### Method Summary

Methods
`int` `add(Hash peer)` Todo: shuffling here is a hack and doesn't work since we switched back to a HashSet implementation
`Hash` `generateRandomKey()` Generate a random key to go within this bucket WARNING - Something is seriously broken here.
`Set<Hash>` `getEntries()` Retrieve all routing table entries stored in the bucket
`void` `getEntries(SelectionCollector collector)`
`Set<Hash>` `getEntries(Set toIgnoreHashes)` Retrieve hashes stored in the bucket, excluding the ones specified
`int` `getKeyCount()` Number of keys already contained in this kbuckey
`LocalHash` `getLocal()`
`int` `getRangeBegin()` lowest order high bit for difference keys
`Hash` `getRangeBeginKey()`
`int` `getRangeEnd()` highest high bit for the difference keys
`Hash` `getRangeEndKey()`
`static void` `main(String[] args)` Test harness to make sure its assigning keys to the right buckets WARNING - Something is seriously broken here.
`boolean` `remove(Hash peer)` Remove the key from the bucket
`void` `setEntries(Set<Hash> entries)` Fill the bucket with entries
`void` `setRange(int lowOrderBitLimit, int highOrderBitLimit)` Set the range low and high bits for difference keys
`boolean` `shouldContain(Hash key)` whether or not the key qualifies as part of this bucket
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### KBucketImpl

    public KBucketImpl(I2PAppContext context,
               LocalHash local)

#### KBucketImpl

    public KBucketImpl(I2PAppContext context,
               Hash local)

for testing - use above constructor for production to get common caching

### Method Detail

#### getRangeBegin

    public int getRangeBegin()

Description copied from interface: `KBucket`
lowest order high bit for difference keys

Specified by:
  `getRangeBegin` in interface `KBucket`

#### getRangeEnd

    public int getRangeEnd()

Description copied from interface: `KBucket`
highest high bit for the difference keys

Specified by:
  `getRangeEnd` in interface `KBucket`

#### setRange

    public void setRange(int lowOrderBitLimit,
                int highOrderBitLimit)

Description copied from interface: `KBucket`
Set the range low and high bits for difference keys

Specified by:
  `setRange` in interface `KBucket`

#### getKeyCount

    public int getKeyCount()

Description copied from interface: `KBucket`
Number of keys already contained in this kbuckey

Specified by:
  `getKeyCount` in interface `KBucket`

#### getLocal

    public LocalHash getLocal()

Specified by:
  `getLocal` in interface `KBucket`

#### shouldContain

    public boolean shouldContain(Hash key)

Description copied from interface: `KBucket`
whether or not the key qualifies as part of this bucket

Specified by:
  `shouldContain` in interface `KBucket`

#### getEntries

    public Set<Hash> getEntries()

Description copied from interface: `KBucket`
Retrieve all routing table entries stored in the bucket

Specified by:
  `getEntries` in interface `KBucket`
Returns:
  set of Hash structures

#### getEntries

    public Set<Hash> getEntries(Set toIgnoreHashes)

Description copied from interface: `KBucket`
Retrieve hashes stored in the bucket, excluding the ones specified

Specified by:
  `getEntries` in interface `KBucket`
Returns:
  set of Hash structures

#### getEntries

    public void getEntries(SelectionCollector collector)

Specified by:
  `getEntries` in interface `KBucket`

#### setEntries

    public void setEntries(Set<Hash> entries)

Description copied from interface: `KBucket`
Fill the bucket with entries

Specified by:
  `setEntries` in interface `KBucket`
Parameters:
  `entries` - set of Hash structures

#### add

    public int add(Hash peer)

Todo: shuffling here is a hack and doesn't work since we switched back to a HashSet implementation

Specified by:
  `add` in interface `KBucket`
Returns:
  number of keys in the bucket after the addition

#### remove

    public boolean remove(Hash peer)

Description copied from interface: `KBucket`
Remove the key from the bucket

Specified by:
  `remove` in interface `KBucket`
Returns:
  true if the key existed in the bucket before removing it, else false

#### generateRandomKey

    public Hash generateRandomKey()

Generate a random key to go within this bucket WARNING - Something is seriously broken here. testRand2() fails right away. ExploreKeySelectorJob is now disabled, ExploreJob just searches for a random key instead.

Specified by:
  `generateRandomKey` in interface `KBucket`

#### getRangeBeginKey

    public Hash getRangeBeginKey()

#### getRangeEndKey

    public Hash getRangeEndKey()

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### main

    public static void main(String[] args)

Test harness to make sure its assigning keys to the right buckets WARNING - Something is seriously broken here. testRand2() fails right away.