public void put(CHKBlock b, boolean isOldBlock) throws IOException { try { store.put(b, b.getRawData(), b.getRawHeaders(), false, isOldBlock); } catch (KeyCollisionException e) { Logger.error(this, "Impossible for CHKStore: "+e, e); } }
public static CHKBlock construct(byte[] data, byte[] header, byte cryptoAlgorithm) throws CHKVerifyException { return new CHKBlock(data, header, null, true, cryptoAlgorithm); }
@Override public boolean equals(Object o) { if(!(o instanceof ClientCHKBlock)) return false; ClientCHKBlock block = (ClientCHKBlock) o; if(!key.equals(block.key)) return false; return block.block.equals(this.block); }
/** * Construct from a CHKBlock and a key. */ public ClientCHKBlock(CHKBlock block, ClientCHK key2) throws CHKVerifyException { this(block.getData(), block.getHeaders(), key2, true); }
byte[] data = block.getBlock().getRawData(); byte[] header = block.getBlock().getRawHeaders(); byte[] routingKey = block.getBlock().getRoutingKey(); long sizeBlock = data.length+header.length+block.getBlock().getFullKey().length+routingKey.length; long sumSizeBlock = sizeBlock; int howManyBlocks = ((int) (cachingFreenetStoreMaxSize / sizeBlock)) + 1; test = "test" + i; block = encodeBlockCHK(test); data = block.getBlock().getRawData(); header = block.getBlock().getRawHeaders(); routingKey = block.getBlock().getRoutingKey(); sizeBlock = data.length+header.length+block.getBlock().getFullKey().length+routingKey.length; sumSizeBlock += sizeBlock; store.put(block.getBlock(), false);
@Override public CHKBlock construct(byte[] data, byte[] headers, byte[] routingKey, byte[] fullKey, boolean canReadClientCache, boolean canReadSlashdotCache, BlockMetadata meta, DSAPublicKey ignored) throws KeyVerifyException { if(data == null || headers == null) throw new CHKVerifyException("Need either data and headers"); return CHKBlock.construct(data, headers, NodeCHK.cryptoAlgorithmFromFullKey(fullKey)); }
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; try { long startTime = System.currentTimeMillis(); is = node.makeInsertSender(block.getKey(), node.maxHTL(), uid, tag, null, headers, prb, false, canWriteClientCache, forkOnCacheable, preferInsert, ignoreLowBackoff, realTimeFlag); boolean hasReceivedRejectedOverload = false; requestStarters.requestCompleted(false, true, block.getKey(), realTimeFlag); boolean deep = node.shouldStoreDeep(block.getKey(), null, is == null ? new PeerNode[0] : is.getRoutedTo()); try { node.store(block, deep, canWriteClientCache, false, false);
@Override public Key getKey() { return block.getKey(); } }
public static KeyBlock createBlock(short keyType, byte[] keyBytes, byte[] headersBytes, byte[] dataBytes, byte[] pubkeyBytes) throws KeyVerifyException { byte type = (byte)(keyType >> 8); byte subtype = (byte)(keyType & 0xFF); if(type == NodeCHK.BASE_TYPE) { // For CHKs, the subtype is the crypto algorithm. return CHKBlock.construct(dataBytes, headersBytes, subtype); } else if(type == NodeSSK.BASE_TYPE) { DSAPublicKey pubKey; try { pubKey = new DSAPublicKey(pubkeyBytes); } catch (IOException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } catch (CryptFormatException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } NodeSSK key = new NodeSSK(pubKey.asBytesHash(), keyBytes, pubKey, subtype); return new SSKBlock(dataBytes, headersBytes, key, false); } else { throw new KeyVerifyException("No such key type "+Integer.toHexString(type)); } }
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()));
@Override public byte[] getFullKey() { return getKey().getFullKey(); }
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,
private void checkBlock(byte[] data, boolean newAlgo) throws CHKEncodeException, InvalidCompressionCodecException, CHKVerifyException, CHKDecodeException, IOException { byte cryptoAlgorithm = newAlgo ? Key.ALGO_AES_CTR_256_SHA256 : Key.ALGO_AES_PCFB_256_SHA256; byte[] copyOfData = new byte[data.length]; System.arraycopy(data, 0, copyOfData, 0, data.length); ClientCHKBlock encodedBlock = ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm); // Not modified in-place. assert(Arrays.equals(data, copyOfData)); ClientCHK key = encodedBlock.getClientKey(); if(newAlgo) { // Check with no JCA. ClientCHKBlock otherEncodedBlock = ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm, true); assertTrue(key.equals(otherEncodedBlock.getClientKey())); assertTrue(Arrays.equals(otherEncodedBlock.getBlock().data, encodedBlock.getBlock().data)); assertTrue(Arrays.equals(otherEncodedBlock.getBlock().headers, encodedBlock.getBlock().headers)); } // Verify it. CHKBlock block = CHKBlock.construct(encodedBlock.getBlock().data, encodedBlock.getBlock().headers, cryptoAlgorithm); ClientCHKBlock checkBlock = new ClientCHKBlock(block, key); ArrayBucket checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false); assert(Arrays.equals(checkData.toByteArray(), data)); if(newAlgo) { checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false, true); assert(Arrays.equals(checkData.toByteArray(), data)); } }
/** * Construct from data retrieved, and a key. * Do not do full decode. Verify what can be verified without doing * a full decode. * @param key2 The client key. * @param header The header. * @param data The data. */ public ClientCHKBlock(byte[] data, byte[] header, ClientCHK key2, boolean verify) throws CHKVerifyException { block = new CHKBlock(data, header, key2.getNodeCHK(), verify, key2.cryptoAlgorithm); this.key = key2; }
@Override public byte[] getRoutingKey() { return getKey().getRoutingKey(); }
private void verifyAndCommit(byte[] headers, byte[] data) throws KeyVerifyException { if(!isSSK) { CHKBlock block = new CHKBlock(data, headers, (NodeCHK)key); synchronized(this) { finalHeaders = headers; } if(logMINOR) Logger.minor(this, "Verified"); // Cache only in the cache, not the store. The reason for this is that // requests don't go to the full distance, and therefore pollute the // store; simulations it is best to only include data from requests // which go all the way i.e. inserts. node.storeShallow(block, canWriteClientCache, canWriteDatastore, tryOffersOnly); if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0) node.queueRandomReinsert(block); } else /*if (key instanceof NodeSSK)*/ { synchronized(this) { finalHeaders = headers; finalSskData = data; } try { SSKBlock block = new SSKBlock(data, headers, (NodeSSK)key, false); if(logMINOR) Logger.minor(this, "Verified SSK"); node.storeShallow(block, canWriteClientCache, canWriteDatastore, tryOffersOnly); } catch (KeyCollisionException e) { Logger.normal(this, "Collision on "+this); } } }
private void store(CHKBlock block, boolean deep, boolean canWriteClientCache, boolean canWriteDatastore, boolean forULPR) { try { double loc = block.getKey().toNormalizedDouble(); if (canWriteClientCache) { chkClientcache.put(block, false);
if(!canCommit) return null; if(!prb.allReceived()) return null; block = new CHKBlock(prb.getBlock(), headers, key); } catch (CHKVerifyException e) { Logger.error(this, "Verify failed in CHKInsertHandler: "+e+" - headers: "+HexUtil.bytesToHex(headers), e);
else { new CHKBlock(prb.getBlock(), headers, (NodeCHK) key); Logger.error(this,