@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); }
/** * 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 $; }
public void markAsDead(Node n) { int i = getKBucketIndex(n.getKey()); if (i == -1) return; kbuckets[i].markDead(n); }
private int getKBucketIndex(Key key) { return key.xor(localNode.getKey()).getFirstSetBitIndex(); }