Package dijjer.util

Examples of dijjer.util.VeryLongInteger


  }

  public Peer(InetAddress address, int port) {
    _address = address;
    _port = port;
    _hash = new VeryLongInteger(toString());
  }
View Full Code Here


        new AbstractThread() {

          public boolean loop() {
            try {
              _usm.send(m.getSource(), DMT.createRequestHashAck(m.getInt(DMT.UID)));
              VeryLongInteger hash = retrieveHash(new BlockInfo(m), m.getInt(DMT.TTL), m.getInt(DMT.UID),
                  true);
              _usm.send(m.getSource(), DMT.createReplyHash(m.getInt(DMT.UID), hash));
              _seenUids.remove(uid);
            } catch (Exception e) {
              Logger.error(e);
View Full Code Here

    }
  }

  public VeryLongInteger retrieveHash(final BlockInfo bi, int ttl, int uid, boolean cacheResult) throws IOException,
      RetrievalException {
    VeryLongInteger lo = _hs.getHash(bi.getHashHashKey());
    if (lo != null) {
      return lo;
    }
    HashSet exclude = new HashSet(); // We don't want to bother the seeds with
    // requests for hashes
    exclude.addAll(_seedNodes);
    while (true) {
      Peer best = _rt.findClosest(bi.getHashHashKey(), exclude);
      if ((ttl == 0) || (best == null) || (bi.getHashHashKey().closerTo(_rt.getPeer().getHash(), best.getHash()))) {
        // We are going to download and retrieve it ourselves
        VeryLongInteger dataHash = retrieveHashFromServer(bi);
        _hs.put(bi.getHashHashKey(), dataHash);
        return dataHash;
      }
      // Ok, we are going to try forwarding it to the next closest peer
      _usm.send(best, DMT.createRequestHash(uid, bi, ttl - 1));
      Message requestHashAck = _usm.waitFor(MessageFilter.create(5000, DMT.requestHashAck).addType(
          DMT.rejectDueToLoop).setField(DMT.UID, uid));
      if (requestHashAck == null) {
        exclude.add(best);
        _rt.recontactPeer(best);
        continue;
      }
      if (requestHashAck.getSpec().equals(DMT.rejectDueToLoop)) {
        Logger.warning("requestHash (uid: " + uid + ") rejected by " + requestHashAck.getSource()
            + " due to loop");
        exclude.add(best);
        continue;
      }
      Message replyHash = _usm.waitFor(MessageFilter.create(30000, DMT.replyHash).setField(DMT.UID, uid));
      if (replyHash == null) {
        Logger.info("Timed out waiting for replyHash from " + best);
        ttl = 0;
        continue;
      }
      VeryLongInteger dataHash = (VeryLongInteger) replyHash.getObject(DMT.HASH);
      if (cacheResult) {
        _hs.put(bi.getHashHashKey(), dataHash);
      }
      return dataHash;
    }
View Full Code Here

  private void handleCorruptionNotification(BlockInfo bi, int uid, Peer source, boolean forHash) {
    try {
      // Ok, first lets see if its valid
      if (forHash) {
        VeryLongInteger myHash = _hs.getHash(bi.getHashHashKey());
        if (myHash == null) {
          Logger.info("Ignoring corruptionNotification because we don't have the hash in our HashStore");
          return;
        }
        VeryLongInteger actualHash = retrieveHashFromServer(bi);
        if (actualHash.equals(myHash)) {
          Logger.warning("Received bogus corruptionNotification from " + source + ", dropping from RT");
          LinkedList r = new LinkedList();
          r.add(source);
          _rt.removePeers(r, "You sent a bogus corruptionNotification");
          return;
        }
        _hs.delete(bi.getHashHashKey());
      } else {
        byte[] localData = _ds.getDataForBlock(bi.getHashKey());
        if (localData == null) {
          Logger.info("Ignoring corruptionNotification because we don't have the data in our DataStore");
          return;
        }
        VeryLongInteger myHash = new VeryLongInteger(localData);
        PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
        (new HttpBlockReceiver(bi, prb)).start();
        VeryLongInteger actualHash = new VeryLongInteger(prb.getBlock());
        if (actualHash.equals(myHash)) {
          Logger.warning("Received bogus corruptionNotification from " + source + ", dropping from RT");
          LinkedList r = new LinkedList();
          r.add(source);
          _rt.removePeers(r, "You sent a bogus corruptionNotification");
          return;
View Full Code Here

    try {
      hbr.start();
    } catch (IOException e) {
      throw new RetrievalException(RetrievalException.IO_ERROR, e.getMessage());
    }
    return new VeryLongInteger(prb.getBlock());
  }
View Full Code Here

TOP

Related Classes of dijjer.util.VeryLongInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.