Package freenet.keys

Examples of freenet.keys.ClientCHK


        if(logMINOR) Logger.minor(this, "Completed a cross-segment: decoded="+decoded+" encoded="+encoded);
    }


    private void checkDecodedBlock(int i, byte[] data) {
        ClientCHK key = getKey(i);
        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


                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

       
        for(MyBlock test : maybeBlocks) {
            boolean failed = false;
            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

    private void checkDecodedDataBlocks(byte[][] dataBlocks, boolean[] dataBlocksPresent,
            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;
                    } else {
View Full Code Here

    private boolean checkEncodedDataBlocks(byte[][] checkBlocks, boolean[] checkBlocksPresent,
            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)
                    parent.fetcher.maybeAddToBinaryBlob(block);
View Full Code Here

        byte cryptoAlgorithm;
        if(parent.splitfileSingleCryptoKey != null) {
            cryptoKey = parent.splitfileSingleCryptoKey;
            cryptoAlgorithm = parent.splitfileSingleCryptoAlgorithm;
        } else {
            ClientCHK key = getSegmentKeys().getKey(blockNumber, null, false);
            cryptoKey = key.getCryptoKey();
            cryptoAlgorithm = key.getCryptoAlgorithm();
        }
        parent.fetcher.queueHeal(data, cryptoKey, cryptoAlgorithm);
    }
View Full Code Here

     */
    public boolean onGotKey(NodeCHK key, CHKBlock block) throws IOException {
        SplitFileSegmentKeys keys = getSegmentKeys();
        if(keys == null) return false;
        int blockNumber;
        ClientCHK decodeKey;
        synchronized(this) {
            if(succeeded || failed || finished) return false;
            blockNumber = blockChooser.getBlockNumber(keys, key);
            if(blockNumber == -1) {
                if(logMINOR) Logger.minor(this, "Block not found "+key);
View Full Code Here

        return keys.getKey(blockNum, null, false);
    }

    public synchronized byte[] checkAndGetBlockData(int blockNum) throws IOException {
        if(!blockChooser.hasSucceeded(blockNum)) return null;
        ClientCHK key = getKey(blockNum);
        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;
View Full Code Here

            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);
        Logger.error(RealNodeRequestInsertTest.class, "Inserted to "+node1);
        Logger.minor(RealNodeRequestInsertTest.class, "Data: "+Fields.hashCode(encData)+", Headers: "+Fields.hashCode(encHeaders));
      } catch (freenet.node.LowLevelPutException putEx) {
        Logger.error(RealNodeRequestInsertTest.class, "Insert failed: "+ putEx);
        System.err.println("Insert failed: "+ putEx);
        System.exit(EXIT_INSERT_FAILED);
      }
        }

        // Now queue requests for each key on every node.
        for(int i=0;i<INSERT_KEYS;i++) {
          ClientCHK key = keys[i];
          System.err.println("Queueing requests for "+i+" of "+INSERT_KEYS);
          for(int j=0;j<nodes.length;j++) {
            clients[j].prefetch(key.getURI(), DAYS.toMillis(1), 32768, null);
          }
          long totalRunningRequests = 0;
          for(int j=0;j<nodes.length;j++) {
            totalRunningRequests += nodes[j].clientCore.countQueuedRequests();
          }
View Full Code Here

    // Encode a block
    String test = "test";
    ClientCHKBlock block = encodeBlock(test, newFormat);
    store.put(block.getBlock(), false);

    ClientCHK key = block.getClientKey();

    CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
    String data = decodeBlock(verify, key);
    assertEquals(test, data);
  }
View Full Code Here

TOP

Related Classes of freenet.keys.ClientCHK

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.