@Provides
 @Named("openkad.local.color")
 @Singleton
 int provideLocalColor(
     @Named("openkad.local.node") Node localNode, @Named("openkad.color.nrcolors") int nrColors) {
   return localNode.getKey().getColor(nrColors);
 }
Ejemplo n.º 2
0
 /**
  * Uses the keyFactory to generate keys which will fit to different buckets
  *
  * @return a list of random keys where no 2 keys will fit into the same bucket
  */
 public List<Key> randomKeysForAllBuckets() {
   List<Key> $ = new ArrayList<Key>();
   for (int i = 0; i < kbuckets.length; ++i) {
     Key key = keyFactory.generate(i).xor(localNode.getKey());
     $.add(key);
   }
   return $;
 }
Ejemplo n.º 3
0
  public void markAsDead(Node n) {
    int i = getKBucketIndex(n.getKey());
    if (i == -1) return;

    kbuckets[i].markDead(n);
  }
Ejemplo n.º 4
0
 private int getKBucketIndex(Key key) {
   return key.xor(localNode.getKey()).getFirstSetBitIndex();
 }