Package freenet.keys

Examples of freenet.keys.ClientCHKBlock


        if(key == null) {
            Logger.error(this, "Key not found");
            failOffThread(new FetchException(FetchExceptionMode.INTERNAL_ERROR, "Key not found"));
            return;
        }
        ClientCHKBlock block = encodeBlock(key, data);
        String decoded = i >= dataBlockCount ? "Encoded" : "Decoded";
        if(block == null || !key.getNodeCHK().equals(block.getKey())) {
            Logger.error(this, decoded+" cross-segment block "+i+" failed!");
            failOffThread(new FetchException(FetchExceptionMode.SPLITFILE_DECODE_ERROR, decoded+" cross-segment block does not match expected key"));
            return;
        } else {
            reportBlockToSegmentOffThread(i, key, block, data);
View Full Code Here


    try {
      Object o = node.makeRequestSender(key.getNodeCHK(), node.maxHTL(), uid, tag, null, localOnly, ignoreStore, false, true, canWriteClientCache, realTimeFlag);
      if(o instanceof CHKBlock)
        try {
          tag.setServedFromDatastore();
          return new ClientCHKBlock((CHKBlock) o, key);
        } catch(CHKVerifyException e) {
          Logger.error(this, "Does not verify: " + e, e);
          throw new LowLevelGetException(LowLevelGetException.DECODE_FAILED);
        }
      if(o == null)
        throw new LowLevelGetException(LowLevelGetException.DATA_NOT_FOUND_IN_STORE);
      rs = (RequestSender) o;
      boolean rejectedOverload = false;
      short waitStatus = 0;
      while(true) {
        waitStatus = rs.waitUntilStatusChange(waitStatus);
        if((!rejectedOverload) && (waitStatus & RequestSender.WAIT_REJECTED_OVERLOAD) != 0) {
          // See below; inserts count both
          requestStarters.rejectedOverload(false, false, realTimeFlag);
          rejectedOverload = true;
        }

        int status = rs.getStatus();

        if(rs.abortedDownstreamTransfers())
          status = RequestSender.TRANSFER_FAILED;

        if(status == RequestSender.NOT_FINISHED)
          continue;

        if(status != RequestSender.TIMED_OUT && status != RequestSender.GENERATED_REJECTED_OVERLOAD && status != RequestSender.INTERNAL_ERROR) {
          if(logMINOR)
            Logger.minor(this, "CHK fetch cost " + rs.getTotalSentBytes() + '/' + rs.getTotalReceivedBytes() + " bytes (" + status + ')');
          nodeStats.localChkFetchBytesSentAverage.report(rs.getTotalSentBytes());
          nodeStats.localChkFetchBytesReceivedAverage.report(rs.getTotalReceivedBytes());
          if(status == RequestSender.SUCCESS)
            // See comments above declaration of successful* : We don't report sent bytes here.
            //nodeStats.successfulChkFetchBytesSentAverage.report(rs.getTotalSentBytes());
            nodeStats.successfulChkFetchBytesReceivedAverage.report(rs.getTotalReceivedBytes());
        }

        if((status == RequestSender.TIMED_OUT) ||
          (status == RequestSender.GENERATED_REJECTED_OVERLOAD)) {
          if(!rejectedOverload) {
            // See below
            requestStarters.rejectedOverload(false, false, realTimeFlag);
            rejectedOverload = true;
            long rtt = System.currentTimeMillis() - startTime;
            double targetLocation=key.getNodeCHK().toNormalizedDouble();
            node.nodeStats.reportCHKOutcome(rtt, false, targetLocation, realTimeFlag);
          }
        } else
          if(rs.hasForwarded() &&
            ((status == RequestSender.DATA_NOT_FOUND) ||
            (status == RequestSender.RECENTLY_FAILED) ||
            (status == RequestSender.SUCCESS) ||
            (status == RequestSender.ROUTE_NOT_FOUND) ||
            (status == RequestSender.VERIFY_FAILURE) ||
            (status == RequestSender.GET_OFFER_VERIFY_FAILURE))) {
            long rtt = System.currentTimeMillis() - startTime;
            double targetLocation=key.getNodeCHK().toNormalizedDouble();
            if(!rejectedOverload)
              requestStarters.requestCompleted(false, false, key.getNodeKey(true), realTimeFlag);
            // Count towards RTT even if got a RejectedOverload - but not if timed out.
            requestStarters.getThrottle(false, false, realTimeFlag).successfulCompletion(rtt);
            node.nodeStats.reportCHKOutcome(rtt, status == RequestSender.SUCCESS, targetLocation, realTimeFlag);
            if(status == RequestSender.SUCCESS) {
              Logger.minor(this, "Successful CHK fetch took "+rtt);
            }
          }

        if(status == RequestSender.SUCCESS)
          try {
            return new ClientCHKBlock(rs.getPRB().getBlock(), rs.getHeaders(), key, true);
          } catch(CHKVerifyException e) {
            Logger.error(this, "Does not verify: " + e, e);
            throw new LowLevelGetException(LowLevelGetException.DECODE_FAILED);
          } catch(AbortedException e) {
            Logger.error(this, "Impossible: " + e, e);
View Full Code Here

        @Override
        public boolean send(NodeClientCore node, final RequestScheduler sched, ClientContext context,
                final ChosenBlock request) {
            final BlockInsert token = (BlockInsert) request.token;
            try {
                ClientCHKBlock clientBlock = token.segment.encodeBlock(token.blockNumber);
                CHKBlock block = clientBlock.getBlock();
                final ClientCHK key = (ClientCHK) clientBlock.getClientKey();
                context.getJobRunner(request.isPersistent()).queueNormalOrDrop(new PersistentJob() {
                   
                    @Override
                    public boolean run(ClientContext context) {
                        onEncode(token, key, context);
View Full Code Here

            int blockNumber = test.blockNumber;
            byte[] buf = test.buf;
            ClientCHK decodeKey = blockNumber == -1 ? null : keys.getKey(blockNumber, null, false);
            // Encode it to check whether the key is the same.
            try {
                ClientCHKBlock block =
                    ClientCHKBlock.encodeSplitfileBlock(buf, decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm());
                ClientCHK actualKey = block.getClientKey();
                if(decodeKey == null || !decodeKey.equals(actualKey)) {
                    // Is it a different block?
                    blockNumber = (short)keys.getBlockNumber(actualKey, null);
                    if(blockNumber == -1) {
                        Logger.error(this, "Block which should be block #"+test.blockNumber+" in slot "+test.slot+" for segment "+this+" is not valid for key "+decodeKey);
View Full Code Here

            SplitFileSegmentKeys keys, boolean capturingBinaryBlob) {
        for(int i=0;i<dataBlocks.length;i++) {
            if(dataBlocksPresent[i]) continue;
            ClientCHK decodeKey = keys.getKey(i, null, false);
            // Encode it to check whether the key is the same.
            ClientCHKBlock block;
            try {
                block = ClientCHKBlock.encodeSplitfileBlock(dataBlocks[i], decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm());
                ClientCHK actualKey = block.getClientKey();
                if(!actualKey.equals(decodeKey)) {
                    if(i == dataBlocks.length-1 && this.segNo == parent.segments.length-1 &&
                            parent.lastBlockMightNotBePadded()) {
                        // Ignore.
                        return;
View Full Code Here

            SplitFileSegmentKeys keys, boolean capturingBinaryBlob) {
        for(int i=0;i<checkBlocks.length;i++) {
            if(checkBlocksPresent[i]) continue;
            ClientCHK decodeKey = keys.getKey(i+blocksForDecode(), null, false);
            // Encode it to check whether the key is the same.
            ClientCHKBlock block;
            try {
                block = ClientCHKBlock.encodeSplitfileBlock(checkBlocks[i], decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm());
                ClientCHK actualKey = block.getClientKey();
                if(!actualKey.equals(decodeKey)) {
                    Logger.error(this, "Splitfile check block "+i+" does not encode to expected key for "+this+" for "+parent);
                    return false;
                }
                if(capturingBinaryBlob)
View Full Code Here

                return false; // Even if this is inaccurate, it will be corrected on a FEC attempt.
            if(tryDecode)
                return false;
            decodeKey = keys.getKey(blockNumber, null, false);
        }
        ClientCHKBlock decodedBlock;
        byte[] decodedData;
        try {
            decodedBlock = new ClientCHKBlock(block, decodeKey);
            decodedData = decodedBlock.memoryDecode();
        } catch (CHKVerifyException e) {
            Logger.error(this, "Verify failed on block for "+decodeKey);
            return false;
        } catch (CHKDecodeException e) {
            Logger.error(this, "Decode failed on block for "+decodeKey);
View Full Code Here

        if(key == null) return null;
        for(int i=0;i<blocksFetched.length;i++) {
            if(blocksFetched[i] == blockNum) {
                byte[] buf = readBlock(i);
                try {
                    ClientCHKBlock block =
                        ClientCHKBlock.encodeSplitfileBlock(buf, key.getCryptoKey(), key.getCryptoAlgorithm());
                    if(!(block.getClientKey().equals(key))) {
                        Logger.error(this, "Block "+blockNum+" in blocksFound["+i+"] is not valid!");
                        blockChooser.onUnSuccess(blockNum);
                        succeeded = false;
                        finished = false;
                    } else {
View Full Code Here

          System.err.println("Inserting "+i+" of "+INSERT_KEYS);
            int node1 = random.nextInt(NUMBER_OF_NODES);
            Node randomNode = nodes[node1];
            String dataString = baseString + i;
            byte[] data = dataString.getBytes("UTF-8");
            ClientCHKBlock b;
            b = ClientCHKBlock.encode(data, false, false, (short)-1, 0, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
            CHKBlock block = b.getBlock();
            ClientCHK chk = b.getClientKey();
            byte[] encData = block.getData();
            byte[] encHeaders = block.getHeaders();
            ClientCHKBlock newBlock = new ClientCHKBlock(encData, encHeaders, chk, true);
            keys[i] = chk;
            Logger.minor(RealNodeRequestInsertTest.class, "Decoded: "+new String(newBlock.memoryDecode(), "UTF-8"));
            Logger.normal(RealNodeRequestInsertTest.class,"CHK: "+chk.getURI());
            Logger.minor(RealNodeRequestInsertTest.class,"Headers: "+HexUtil.bytesToHex(block.getHeaders()));
            // Insert it.
      try {
        randomNode.clientCore.realPut(block, false, FORK_ON_CACHEABLE, false, false, REAL_TIME_FLAG);
View Full Code Here

  }

  private ClientKeyBlock fetch(ClientCHK clientCHK, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore) throws CHKVerifyException {
    CHKBlock block = fetch(clientCHK.getNodeCHK(), false, canReadClientCache, canWriteClientCache, canWriteDatastore, false, null);
    if(block == null) return null;
    return new ClientCHKBlock(block, clientCHK);
  }
View Full Code Here

TOP

Related Classes of freenet.keys.ClientCHKBlock

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.