SplitFileSegmentKeys readSegmentKeys() throws IOException, ChecksumFailedException { SplitFileSegmentKeys keys = new SplitFileSegmentKeys(blocksForDecode(), checkBlocks, parent.splitfileSingleCryptoKey, parent.splitfileSingleCryptoAlgorithm); byte[] buf = new byte[SplitFileSegmentKeys.storedKeysLength(blocksForDecode(), checkBlocks, parent.splitfileSingleCryptoKey != null)]; parent.preadChecksummed(segmentKeyListOffset, buf, 0, buf.length); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); keys.readKeys(dis, false); keys.readKeys(dis, true); return keys; }
/** Ugly to include this here, but avoids making completed visible ... */ public synchronized int getBlockNumber(SplitFileSegmentKeys keys, NodeCHK key) { return keys.getBlockNumber(key, completed); }
public ClientCHK getKey(int x, boolean[] ignoreSlots, boolean copy) { if(ignoreSlots != null) { if(ignoreSlots[x]) return null; } return getKey(x, copy); }
int dataBlocks = keys.getDataBlocks(); int checkBlocks = keys.getCheckBlocks(); splitfileDataBlocks += dataBlocks; splitfileCheckBlocks += checkBlocks; final int dataBlocks = keys.getDataBlocks() - crossCheckBlocks; final int checkBlocks = keys.getCheckBlocks(); if((dataBlocks > origFetchContext.maxDataBlocksPerSegment) || (checkBlocks > origFetchContext.maxCheckBlocksPerSegment)) crossCheckBlocks, maxRetries != -1, checksumLength, persistent); for(int j=0;j<(dataBlocks+crossCheckBlocks+checkBlocks);j++) { keyListener.addKey(keys.getKey(j, null, false).getNodeKey(false), i, salt);
segments[0] = new SplitFileSegmentKeys(splitfileBlocks, splitfileCheckBlocks, splitfileSingleCryptoKey, splitfileSingleCryptoAlgorithm); } else { int dataBlocksPtr = 0; segments[i] = new SplitFileSegmentKeys(copyDataBlocks, copyCheckBlocks, splitfileSingleCryptoKey, splitfileSingleCryptoAlgorithm); if(logMINOR) Logger.minor(this, "REQUESTING: Segment "+i+" of "+segments.length+" : "+copyDataBlocks+" data blocks "+copyCheckBlocks+" check blocks"); dataBlocksPtr += copyDataBlocks; segments[i].readKeys(dis, false); segments[i].readKeys(dis, true);
int blockNumber = test.blockNumber; byte[] buf = test.buf; ClientCHK decodeKey = blockNumber == -1 ? null : keys.getKey(blockNumber, null, false); if(decodeKey == null || !decodeKey.equals(actualKey)) { 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);
public NodeCHK getNodeKey(int x, boolean[] ignoreSlots, boolean copy) { if(ignoreSlots != null) { if(ignoreSlots[x]) return null; } return getNodeKey(x, copy); }
static int storedKeysLength(int dataBlocks, int checkBlocks, boolean commonDecryptKey, int checksumLength) { return SplitFileSegmentKeys.storedKeysLength(dataBlocks, checkBlocks, commonDecryptKey) + checksumLength; }
/** Deep copy those fields that need to be deep copied after clone() */ private void finishClone(Metadata orig) { if(orig.segments != null) { segments = new SplitFileSegmentKeys[orig.segments.length]; for(int i=0;i<segments.length;i++) { segments[i] = orig.segments[i].clone(); } } if(hashes != null) { hashes = new HashResult[orig.hashes.length]; for(int i=0;i<hashes.length;i++) hashes[i] = orig.hashes[i].clone(); } if(manifestEntries != null) { manifestEntries = new HashMap<String, Metadata>(orig.manifestEntries); for(Map.Entry<String, Metadata> entry : manifestEntries.entrySet()) { entry.setValue((Metadata)entry.getValue().clone()); } } if(clientMetadata != null) clientMetadata = clientMetadata.clone(); }
public void testWriteReadSegmentKeys() throws FetchException, MetadataParseException, IOException, CHKEncodeException, MetadataUnresolvedException, ChecksumFailedException { int dataBlocks = 3, checkBlocks = 3; TestSplitfile test = TestSplitfile.constructSingleSegment(dataBlocks*BLOCK_SIZE, checkBlocks, null, true); StorageCallback cb = test.createStorageCallback(); SplitFileFetcherStorage storage = test.createStorage(cb); SplitFileFetcherSegmentStorage segment = storage.segments[0]; SplitFileSegmentKeys keys = segment.getSegmentKeys(); SplitFileSegmentKeys moreKeys = segment.readSegmentKeys(); assertTrue(keys.equals(moreKeys)); storage.close(); }
public NodeCHK[] listNodeKeys(boolean[] foundKeys, boolean copy) { ArrayList<NodeCHK> list = new ArrayList<NodeCHK>(); for(int i=0;i<dataBlocks+checkBlocks;i++) { NodeCHK k = getNodeKey(i, foundKeys, copy); if(k == null) continue; list.add(k); } return list.toArray(new NodeCHK[list.size()]); }
public synchronized ClientCHK getKey(int blockNum) { SplitFileSegmentKeys keys; try { keys = getSegmentKeys(); } catch (IOException e) { return null; } if(keys == null) return null; return keys.getKey(blockNum, null, false); }
public synchronized void getUnfetchedKeys(List<Key> keys) throws IOException { if(finished || tryDecode) return; SplitFileSegmentKeys keyList = getSegmentKeys(); for(int i=0;i<totalBlocks();i++) { if(!blockChooser.hasSucceeded(i)) keys.add(keyList.getNodeKey(i, null, false)); } }
public ClientKey getKey(MyKey key) { try { return segments[key.segmentNumber].getSegmentKeys().getKey(key.blockNumber, null, false); } catch (IOException e) { this.failOnDiskError(e); return null; } }
@Override protected boolean checkValid(int chosen) { if(!super.checkValid(chosen)) return false; if(chosen == ignoreLastBlock) return false; try { SplitFileSegmentKeys keys = segment.getSegmentKeys(); if(keysFetching.hasKey(keys.getNodeKey(chosen, null, false), segment.parent.fetcher.getSendableGet())) return false; return true; } catch (final IOException e) { segment.parent.jobRunner.queueNormalOrDrop(new PersistentJob() { @Override public boolean run(ClientContext context) { segment.parent.failOnDiskError(e); return true; } }); return false; } }
private void queueHeal(int blockNumber, byte[] data) throws IOException { byte[] cryptoKey; 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); }
if(tryDecode) return false; decodeKey = keys.getKey(blockNumber, null, false);
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); } catch (CHKEncodeException e) { // Impossible! parent.fail(new FetchException(FetchExceptionMode.INTERNAL_ERROR, "Decoded block could not be encoded")); Logger.error(this, "Impossible: Decoded block could not be encoded"); return false; } } return true; }
for(int i=0;i<dataBlocks.length;i++) { if(dataBlocksPresent[i]) continue; ClientCHK decodeKey = keys.getKey(i, null, false);