Codota Logo
net.i2p.kademlia
Code IndexAdd Codota to your IDE (free)

How to use net.i2p.kademlia

Best Java code snippets using net.i2p.kademlia (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: i2p/i2p.i2p

/** @since 0.8.8 */
public void clear() {
  getReadLock();
  try {
    for (KBucket<T> b : _buckets) {
      b.clear();
    }
  } finally { releaseReadLock(); }
  _rangeCalc.clear();
}

origin: i2p/i2p.i2p

public void getAll(SelectionCollector<T> collector) {
  getReadLock();
  try {
    for (KBucket<T> b : _buckets) {
      b.getEntries(collector);
    }
  } finally { releaseReadLock(); }
}

origin: i2p/i2p.i2p

public boolean remove(T entry) {
  KBucket<T> kbucket;
  getReadLock();
  try {
    kbucket = getBucket(entry);
  } finally { releaseReadLock(); }
  if (kbucket == null)  // us
    return false;
  boolean removed = kbucket.remove(entry);
  return removed;
}

origin: i2p/i2p.i2p

/** @since 0.9.10 */
public void testAudit() {
  int errors = 0;
  for (KBucket<Hash> b : set.getBuckets()) {
    for (Hash sds : b.getEntries()) {
      int range = set.getRange(sds);
      if (range < b.getRangeBegin() || range > b.getRangeEnd()) {
        log.error("Hash " + sds + " with range " + range +
             " does not belong in " + b);
        errors++;
      }
    }
  }
  assertTrue(errors == 0);
}
origin: i2p/i2p.i2p

/** @since 0.9.10 */
public void testGenRandom() {
  int errors = 0;
  for (KBucket<Hash> b : set.getBuckets()) {
    for (int j = 0; j < 4000; j++) {
      Hash rand = set.generateRandomKey(b);
      int range = set.getRange(rand);
      if (range < b.getRangeBegin() || range > b.getRangeEnd()) {
        log.error("Generate random key failed range=" + range + " for " + rand + " meant for bucket " + b);
        errors++;
      }
    }
  }
  assertTrue(errors == 0);
}
origin: i2p/i2p.i2p

/**
 *  No lock required.
 *  FIXME will split the closest buckets too far if B &gt; 1 and K &lt; 2**B
 *  Won't ever really happen and if it does it still works.
 */
private boolean shouldSplit(KBucket<T> b) {
  return
      b.getRangeBegin() != b.getRangeEnd() &&
      b.getKeyCount() > BUCKET_SIZE;
}
origin: i2p/i2p.i2p

  public int compare(KBucket<T> l, KBucket<T> r) {
    if (l.getRangeEnd() < r.getRangeBegin())
      return -1;
    if (l.getRangeBegin() > r.getRangeEnd())
      return 1;
    return 0;
  }
}
origin: i2p/i2p.i2p

public void testSelf() {
  // new implementation will never include myself
  assertFalse(set.add(usHash));
}
origin: i2p/i2p.i2p

/** @since 0.9.10 */
public void testExplore() {
  List<Hash> keys = set.getExploreKeys(-1000);
  assertTrue(keys.size() > 0);
}
origin: i2p/i2p.i2p

/**
 *  The current number of entries.
 */
public int size() {
  int rv = 0;
  getReadLock();
  try {
    for (KBucket<T> b : _buckets) {
      rv += b.getKeyCount();
    }
  } finally { releaseReadLock(); }
  return rv;
}

origin: i2p/i2p.i2p

/**
 *  DHT - get random keys to explore
 */
public List<NID> getExploreKeys() {
  return _kad.getExploreKeys(MAX_BUCKET_AGE);
}
origin: i2p/i2p.i2p

/**
 *  Grabs the write lock.
 *  Caller must NOT have the read lock.
 *  The bucket should be splittable (range start != range end).
 *  @param r the range start of the bucket to be split
 */
private void split(int r) {
  if (!getWriteLock())
    return;
  try {
    locked_split(r);
  } finally { releaseWriteLock(); }
}
origin: i2p/i2p.i2p

  public boolean trim(KBucket<T> kbucket, T toAdd) {
    if (kbucket.getLastChanged() > _ctx.clock().now() - 5*60*1000)
      return false;
    return super.trim(kbucket, toAdd);
  }
}
origin: i2p/i2p.i2p

/**
 *  This is fast and doesn't use synchronization,
 *  but it includes both routerinfos and leasesets.
 *  Use it to avoid deadlocks.
 *  No - not true - the KBS contains RIs only.
 */
protected int getKBucketSetSize() {  
  if (_kb == null) return 0;
  return _kb.size();
}

origin: i2p/i2p.i2p

/**
 *  Sets last-changed if rv is true OR if the peer is already present.
 *  Calls the trimmer if begin == end and we are full.
 *  If begin != end then add it and caller must do bucket splitting.
 *  @return true if added
 */
public boolean add(T peer) {
  if (_begin != _end || _entries.size() < _max ||
    _entries.contains(peer) || _trimmer.trim(this, peer)) {
    // do this even if already contains, to call setLastChanged()
    boolean rv = _entries.add(peer);
    setLastChanged();
    return rv;
  }
  return false;
}

origin: i2p/i2p.i2p

public void getEntries(SelectionCollector<T> collector) {
  for (T h : _entries) {
     collector.add(h);
  }
}

origin: i2p/i2p.i2p

/**
 * Use the default trim strategy, which removes a random entry.
 * @param us the local identity (typically a SHA1Hash or Hash)
 *           The class must have a zero-argument constructor.
 * @param max the Kademlia value "k", the max per bucket, k &gt;= 4
 * @param b the Kademlia value "b", split buckets an extra 2**(b-1) times,
 *           b &gt; 0, use 1 for bittorrent, Kademlia paper recommends 5
 */
public KBucketSet(I2PAppContext context, T us, int max, int b) {
  this(context, us, max, b, new RandomTrimmer<T>(context, max));
}
origin: i2p/i2p.i2p

/**
 *  The number of bits minus 1 (range number) for the xor of the key.
 *  Package private for testing only. Others shouldn't need this.
 *  @return 0 to max-1 or -1 for us
 */
int getRange(T key) {
  return _rangeCalc.getRange(key);
}

origin: i2p/i2p.i2p

public void testRandom(){
  addRandom(1000);
}
origin: i2p/i2p.i2p

/**
 *  @return a copy in a new set
 */
public Set<T> getAll() {
  Set<T> all = new HashSet<T>(256);
  getReadLock();
  try {
    for (KBucket<T> b : _buckets) {
      all.addAll(b.getEntries());
    }
  } finally { releaseReadLock(); }
  return all;
}
net.i2p.kademlia

Most used classes

  • KBucketSet
    In-memory storage of buckets sorted by the XOR metric from the base (us) passed in via the construct
  • KBucket
    Group, without inherent ordering, a set of keys a certain distance away from a local key, using XOR
  • XORComparator
    Help sort Hashes in relation to a base key using the XOR metric
  • KBucketImpl
    A concurrent implementation using ConcurrentHashSet. The max size (K) may be temporarily exceeded du
  • KBucketSet$BucketComparator
    For Collections.binarySearch. Returns equal for any overlap.
  • KBucketSet$Range,
  • KBucketSetTest$RTester,
  • KBucketSetTest,
  • KBucketTrimmer,
  • RandomTrimmer,
  • RejectTrimmer,
  • SelectionCollector
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now