@Provides
 @Named("openkad.net.udp.sock")
 @Singleton
 DatagramSocket provideKadDatagramSocket(
     @Named("openkad.scheme.name") String kadScheme, @Named("openkad.local.node") Node localNode)
     throws SocketException {
   System.out.println("binding: " + localNode.getPort(kadScheme));
   return new DatagramSocket(localNode.getPort(kadScheme));
 }
 @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);
 }
Example #3
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 $;
 }
  @Provides
  @Named("openkad.local.node")
  @Singleton
  Node provideLocalNode(
      @Named("openkad.scheme.name") String kadScheme,
      @Named("openkad.net.udp.port") int udpPort,
      @Named("openkad.local.key") String base64Key,
      KeyFactory keyFactory)
      throws UnknownHostException, IOException {

    Integer a =
        new Integer(udpPort + InetAddress.getByName("localhost").getHostAddress().hashCode());
    String v = a.toString();
    Key key = base64Key.isEmpty() ? keyFactory.create(v) : keyFactory.get(base64Key);
    Node n = new Node(key);

    n.setInetAddress(InetAddress.getByName("localhost"));
    n.addEndpoint(kadScheme, udpPort);

    return n;
  }
Example #5
0
  public void markAsDead(Node n) {
    int i = getKBucketIndex(n.getKey());
    if (i == -1) return;

    kbuckets[i].markDead(n);
  }
Example #6
0
 private int getKBucketIndex(Key key) {
   return key.xor(localNode.getKey()).getFirstSetBitIndex();
 }