Package dijjer.io.xfer

Examples of dijjer.io.xfer.PartiallyReceivedBlock


  protected byte[] makePacket(int p) {
    return new byte[] {(byte)p, (byte)p};
  }
 
  public void testAll() {
    PartiallyReceivedBlock prb = new PartiallyReceivedBlock(2, 2);
    prb.addPacket(0, new Buffer(makePacket(1)));
    LinkedList pr = prb.addListener(new PartiallyReceivedBlock.PacketReceivedListener() {
      public void packetReceived(int packetNo) {
        System.out.println("Received packet "+packetNo);
      }
     
     
      public void receiveAborted(int reason, String description) {
        System.out.println("Receive aborted - "+reason+" "+description);
      }
    });
    prb.addPacket(1, new Buffer(makePacket(2)));
    byte[] block = prb.getBlock();
    for (int x=0; x<block.length; x++) {
      System.out.print(block[x]);
    }
    System.out.println();
  }
View Full Code Here


    Peer p3 = new Peer(InetAddress.getLocalHost(), 8002);
    byte[] block = new byte[1024 * 256];
    for (int x = 0; x < block.length; x++) {
      block[x] = (byte) x;
    }
    PartiallyReceivedBlock prb1 = new PartiallyReceivedBlock(256, 1024, block);
    final BlockTransmitter bt = new BlockTransmitter(usm1, p2, 0, prb1);
    (new Thread() {

      public void run() {
        try {
          bt.send();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }).start();
    PartiallyReceivedBlock prb2 = new PartiallyReceivedBlock(256, 1024);
    final BlockReceiver br = new BlockReceiver(usm2, p1, 0, prb2);
    final BlockTransmitter bt2 = new BlockTransmitter(usm2, p3, 0, prb2);
    PartiallyReceivedBlock prb3 = new PartiallyReceivedBlock(256, 1024);
    final BlockReceiver br2 = new BlockReceiver(usm3, p2, 0, prb3);
    (new Thread() {

      public void run() {
        try {
View Full Code Here

*/
public class InputStreamBlockReceiverTest extends TestCase {
  public void testISBR() throws Exception {
    byte[] ba1 = new byte[1000];
    ByteArrayInputStream bais = new ByteArrayInputStream(ba1);
    PartiallyReceivedBlock prb1 = new PartiallyReceivedBlock(100, 10);
    InputStreamBlockReceiver isbr1 = new InputStreamBlockReceiver(prb1, bais);
    isbr1.start();
    assertTrue(prb1.allReceived());
    byte[] ba2 = prb1.getBlock();
    for(int x=0; x<ba2.length; x++) {
      assertEquals(ba1[x], ba2[x]);
    }
   
    bais.reset();
    PartiallyReceivedBlock prb2 = new PartiallyReceivedBlock(100, 11);
    InputStreamBlockReceiver isbr2 = new InputStreamBlockReceiver(prb2, bais);
    isbr2.start();
   
    byte[] ba3 = prb2.getBlock();
    for (int x=0; x<ba1.length; x++) {
      assertEquals(ba1[x], ba3[x]);
    }
    for (int x=ba1.length; x<ba3.length; x++) {
      assertEquals(ba3[x], (byte)0);
View Full Code Here

      if (checkHash != null) {
        _retrievedHashes.put(new Integer(blockNo), checkHash);
      }
      Logger.info("Done with retrieval of hash " + blockNo);
    } else {
      PartiallyReceivedBlock block;
      BlockInfo bi;
      synchronized (this) {
        blockNo = _nextBlockToDownload++;
        bi = new BlockInfo(_url, _length, _lastModified, blockNo);
        block = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
        _pending.addLast(new BlockPair(bi, block));
        this.notify();
      }
      try {
        // If the remote transfer fails we don't want the transfer to the client to be aborted, rather
        // we want to rerequest with TTL of 0, so we tell the PartiallyRetrievedBlock to ignore any
        // abort
        block.setIgnoreAbort(true);
        if (Dispatcher.getDispatcher().retrieveData(bi, 15, block, this)) {
          _fromCacheCount++;
        }
        block.setIgnoreAbort(false);
      } catch (Exception e) {
        Logger.warning("Error during download of block " + blockNo + ": " + e.getMessage());
        try {
          Logger.info("Retrying block " + blockNo + " with TTL of 0");
          Dispatcher.getDispatcher().retrieveData(new BlockInfo(_url, _length, _lastModified, blockNo), 0,
View Full Code Here

    return _length;
  }

  private void handleHashVerificationFailure(VeryLongInteger retrievedHash, VeryLongInteger actualHash, BlockInfo bi) {
    // Find out what the hash should be
    PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
    try {
      (new HttpBlockReceiver(bi, prb)).start();
    } catch (Exception e) {
      Logger.warning("Exception while trying to deal with hash verification failure", e);
    }
    VeryLongInteger confirmHash = new VeryLongInteger(prb.getBlock());
    boolean dataHashFailure = !confirmHash.equals(actualHash);
    boolean hashHashFailure = !confirmHash.equals(retrievedHash);
    Logger.info("Sending corruptionNotification for " + bi + " (" + dataHashFailure + ", " + hashHashFailure + ")");
    for (Iterator i = ((ArrayList) RoutingTable.getRoutingTable().getPeers().clone()).iterator(); i.hasNext();) {
      Peer p = (Peer) i.next();
View Full Code Here

        new AbstractThread() {

          protected boolean loop() throws InterruptedException {
            try {
              _usm.send(m.getSource(), DMT.createAcknowledgeRequest(m.getInt(DMT.UID)));
              PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK,
                  Dijjer.PACKET_SIZE);
              retrieveData(new BlockInfo(m), m.getInt(DMT.TTL), m.getSource(), m.getInt(DMT.UID),
                  (LinkedList) m.getObject(DMT.FORWARDERS), prb, null);
              _seenUids.remove(uid);
            } catch (Exception e) {
View Full Code Here

        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");
View Full Code Here

      Logger.warning("Exception while processing corruptionNotification", e);
    }
  }

  protected VeryLongInteger retrieveHashFromServer(BlockInfo bi) throws RetrievalException {
    PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
    HttpBlockReceiver hbr = new HttpBlockReceiver(bi, prb);
    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.io.xfer.PartiallyReceivedBlock

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.