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 ClientKey getKey(MyKey key) { try { return segments[key.segmentNumber].getSegmentKeys().getKey(key.blockNumber, null, false); } catch (IOException e) { this.failOnDiskError(e); return null; } }
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 boolean definitelyWantKey(NodeCHK key) { synchronized(this) { if(succeeded || failed || finished) return false; } SplitFileSegmentKeys keys; try { keys = getSegmentKeys(); } catch (IOException e) { parent.failOnDiskError(e); return false; } synchronized(this) { // Synched because of blocksFound return blockChooser.getBlockNumber(keys, key) >= 0; } }
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); }
@Override public boolean run(ClientContext context) { try { // FIXME CPU USAGE Add another API to the segment to avoid re-decoding. SplitFileSegmentKeys keys = segments[blockNo].getSegmentKeys(); if(keys == null) return false; boolean success = segments[blockNo].innerOnGotKey(key.getNodeCHK(), block, keys, blockNumbers[blockNo], data); if(success) { if(logMINOR) Logger.minor(this, "Successfully decoded cross-segment block"); } else { // Not really a big deal, but potentially interesting... Logger.warning(this, "Decoded cross-segment block but not wanted by segment"); } } catch (IOException e) { parent.failOnDiskError(e); return true; } return false; } });
@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; } }
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(); }
SplitFileSegmentKeys keys = getSegmentKeys(); if(keys == null) return false; int blockNumber;
SplitFileSegmentKeys keys = getSegmentKeys(); if(allBlocks == null || keys == null) { return;