Package freenet.io.xfer

Examples of freenet.io.xfer.PartiallyReceivedBlock


        tag.unlockHandler();
        return;
      }
      Message df = DMT.createFNPCHKDataFound(uid, block.getRawHeaders());
      source.sendAsync(df, null, senderCounter);
          PartiallyReceivedBlock prb =
            new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, block.getRawData());
          final BlockTransmitter bt =
            new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, senderCounter, BlockTransmitter.NEVER_CASCADE,
                new BlockTransmitterCompletion() {

          @Override
View Full Code Here


    try {
      // Is a CHK.
      Message df = DMT.createFNPCHKDataFound(uid, rs.getHeaders());
      source.sendAsync(df, null, this);

      PartiallyReceivedBlock prb = rs.getPRB();
      bt =
        new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, this, new ReceiverAbortHandler() {

          @Override
          public boolean onAbort() {
View Full Code Here

      status = RequestSender.SUCCESS; // for byte logging
      // Assume local SSK sending will succeed?
      node.nodeStats.remoteRequest(true, true, true, htl, key.toNormalizedDouble(), realTimeFlag, false);
    } else if(block instanceof CHKBlock) {
      Message df = DMT.createFNPCHKDataFound(uid, block.getRawHeaders());
      PartiallyReceivedBlock prb =
        new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, block.getRawData());
      BlockTransmitter bt =
        new BlockTransmitter(node.usm, node.getTicker(), source, uid, prb, this, BlockTransmitter.NEVER_CASCADE,
            new BlockTransmitterCompletion() {

          @Override
View Full Code Here

        // Now create an CHKInsertSender, or use an existing one, or
        // discover that the data is in the store.

        // From this point onwards, if we return cleanly we must go through finish().
       
        prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE);
        if(htl > 0)
            sender = node.makeInsertSender(key, htl, uid, tag, source, headers, prb, false, false, forkOnCacheable, preferInsert, ignoreLowBackoff, realTimeFlag);
        br = new BlockReceiver(node.usm, source, uid, prb, this, node.getTicker(), false, realTimeFlag, myTimeoutHandler, false);
       
        // Receive the data, off thread
View Full Code Here

          Logger.warning(this, "Did not receive DataInsert on "+uid+" from "+source+" !");
        Message tooSlow = DMT.createFNPRejectedTimeout(uid);
        source.sendAsync(tooSlow, null, this);
        Message m = DMT.createFNPInsertTransfersCompleted(uid, true);
        source.sendAsync(m, null, this);
        prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE);
        br = new BlockReceiver(node.usm, source, uid, prb, this, node.getTicker(), false, realTimeFlag, null, false);
        prb.abort(RetrievalException.NO_DATAINSERT, "No DataInsert", true);
        source.localRejectedOverload("TimedOutAwaitingDataInsert", realTimeFlag);
       
        // Two stage timeout. Don't go fatal unless no response in 60 seconds.
View Full Code Here

  }

  public void realPutCHK(CHKBlock block, boolean canWriteClientCache, boolean forkOnCacheable, boolean preferInsert, boolean ignoreLowBackoff, boolean realTimeFlag) throws LowLevelPutException {
    byte[] data = block.getData();
    byte[] headers = block.getHeaders();
    PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE, data);
    CHKInsertSender is;
    long uid = makeUID();
    InsertTag tag = new InsertTag(false, InsertTag.START.LOCAL, null, realTimeFlag, uid, node);
    if(!tracker.lockUID(uid, false, true, false, true, realTimeFlag, tag)) {
      Logger.error(this, "Could not lock UID just randomly generated: " + uid + " - probably indicates broken PRNG");
View Full Code Here

         
      origTag.senderTransferBegins((NodeCHK)key, this);
         
          try {
           
            prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE);
           
            // FIXME kill the transfer if off-thread (two stage timeout, offers == null) and it's already completed successfully?
            // FIXME we are also plotting to get rid of transfer cancels so maybe not?
            synchronized(this) {
              transferringFrom = pn;
View Full Code Here

      // FIXME: Validate headers
     
      if(!wasFork)
        origTag.senderTransferBegins((NodeCHK)key, this);
     
      final PartiallyReceivedBlock prb = new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, Node.PACKET_SIZE);
     
      boolean failNow = false;
     
      synchronized(this) {
          finalHeaders = waiter.headers;
        if(this.status == SUCCESS || this.prb != null && transferringFrom != null)
          failNow = true;
        if((!wasFork) && (this.prb == null || !this.prb.allReceivedAndNotAborted()))
          this.prb = prb;
        notifyAll();
      }
      if(!wasFork)
        // Don't fire transfer begins on a fork since we have not set headers or prb.
        // If we find the data we will offer it to the requester.
        fireCHKTransferBegins();
     
      final long tStart = System.currentTimeMillis();
      final BlockReceiver br = new BlockReceiver(node.usm, next, uid, prb, this, node.getTicker(), true, realTimeFlag, myTimeoutHandler, true);
     
      if(failNow) {
        if(logMINOR) Logger.minor(this, "Terminating forked transfer on "+this+" from "+next);
        prb.abort(RetrievalException.CANCELLED_BY_RECEIVER, "Cancelling fork", true);
        br.receive(new BlockReceiverCompletion() {

        @Override
        public void blockReceived(byte[] buf) {
            if(!wasFork)
              origTag.senderTransferEnds((NodeCHK)key, RequestSender.this);
          next.noLongerRoutingTo(origTag, false);
        }

        @Override
        public void blockReceiveFailed(RetrievalException e) {
            if(!wasFork)
              origTag.senderTransferEnds((NodeCHK)key, RequestSender.this);
          next.noLongerRoutingTo(origTag, false);
        }
         
        });
        return;
      }
     
      if(logMINOR) Logger.minor(this, "Receiving data");
      if(!wasFork) {
        synchronized(this) {
          transferringFrom = next;
        }
      } else
          if(logMINOR) Logger.minor(this, "Receiving data from fork");
     
      receivingAsync = true;
      br.receive(new BlockReceiverCompletion() {
       
        @Override
        public void blockReceived(byte[] data) {
          try {
            long tEnd = System.currentTimeMillis();
            transferTime = tEnd - tStart;
            boolean haveSetPRB = false;
            synchronized(RequestSender.this) {
              transferringFrom = null;
              if(RequestSender.this.prb == null || !RequestSender.this.prb.allReceivedAndNotAborted()) {
                RequestSender.this.prb = prb;
                haveSetPRB = true;
              }
            }
            if(!wasFork)
              origTag.senderTransferEnds((NodeCHK)key, RequestSender.this);
             next.transferSuccess(realTimeFlag);
            next.successNotOverload(realTimeFlag);
             node.nodeStats.successfulBlockReceive(realTimeFlag, source == null);
            if(logMINOR) Logger.minor(this, "Received data");
            // Received data
            try {
              verifyAndCommit(waiter.headers, data);
              if(logMINOR) Logger.minor(this, "Written to store");
            } catch (KeyVerifyException e1) {
              Logger.normal(this, "Got data but verify failed: "+e1, e1);
              node.failureTable.onFinalFailure(key, next, htl, origHTL, FailureTable.RECENTLY_FAILED_TIME, FailureTable.REJECT_TIME, source);
              if(!wasFork)
                finish(VERIFY_FAILURE, next, false);
              else
                next.noLongerRoutingTo(origTag, false);
              return;
            }
            if(haveSetPRB) // It was a fork, so we didn't immediately send the data.
              fireCHKTransferBegins();
            finish(SUCCESS, next, false);
          } catch (Throwable t) {
              Logger.error(this, "Failed on "+this, t);
              if(!wasFork)
                finish(INTERNAL_ERROR, next, true);
          } finally {
            if(wasFork)
              next.noLongerRoutingTo(origTag, false);
          }
        }
       
        @Override
        public void blockReceiveFailed(
            RetrievalException e) {
          try {
            synchronized(RequestSender.this) {
              transferringFrom = null;
            }
            origTag.senderTransferEnds((NodeCHK)key, RequestSender.this);
            if (e.getReason()==RetrievalException.SENDER_DISCONNECTED)
              Logger.normal(this, "Transfer failed (disconnect): "+e, e);
            else
              // A certain number of these are normal, it's better to track them through statistics than call attention to them in the logs.
              Logger.normal(this, "Transfer failed ("+e.getReason()+"/"+RetrievalException.getErrString(e.getReason())+"): "+e+" from "+next, e);
            if(RequestSender.this.source == null)
              Logger.normal(this, "Local transfer failed: "+e.getReason()+" : "+RetrievalException.getErrString(e.getReason())+"): "+e+" from "+next, e);
            // We do an ordinary backoff in all cases.
            if(!prb.abortedLocally())
              next.localRejectedOverload("TransferFailedRequest"+e.getReason(), realTimeFlag);
            node.failureTable.onFinalFailure(key, next, htl, origHTL, FailureTable.RECENTLY_FAILED_TIME, FailureTable.REJECT_TIME, source);
            if(!wasFork)
              finish(TRANSFER_FAILED, next, false);
            int reason = e.getReason();
            boolean timeout = (!br.senderAborted()) &&
            (reason == RetrievalException.SENDER_DIED || reason == RetrievalException.RECEIVER_DIED || reason == RetrievalException.TIMED_OUT
                || reason == RetrievalException.UNABLE_TO_SEND_BLOCK_WITHIN_TIMEOUT);
            // But we only do a transfer backoff (which is separate, and starts at a higher threshold) if we timed out.
            if(timeout) {
              // Looks like a timeout. Backoff.
              if(logMINOR) Logger.minor(this, "Timeout transferring data : "+e, e);
              next.transferFailed(e.getErrString(), realTimeFlag);
            } else {
              // Quick failure (in that we didn't have to timeout). Don't backoff.
              // Treat as a DNF.
              node.failureTable.onFinalFailure(key, next, htl, origHTL, FailureTable.RECENTLY_FAILED_TIME, FailureTable.REJECT_TIME, source);
            }
            if(!prb.abortedLocally())
              node.nodeStats.failedBlockReceive(true, timeout, realTimeFlag, source == null);
          } catch (Throwable t) {
              Logger.error(this, "Failed on "+this, t);
              if(!wasFork)
                finish(INTERNAL_ERROR, next, true);
View Full Code Here

TOP

Related Classes of freenet.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.