/** FIXME not used yet */ private void allocateCrossCheckBlock(SplitFileFetcherCrossSegmentStorage segment, Random random) { int x = 0; for(int i=0;i<10;i++) { x = random.nextInt(segments.length); SplitFileFetcherSegmentStorage seg = segments[x]; int blockNum = seg.allocateCrossCheckBlock(segment, random); if(blockNum >= 0) { segment.addDataBlock(seg, blockNum); return; } } for(int i=0;i<segments.length;i++) { x++; if(x == segments.length) x = 0; SplitFileFetcherSegmentStorage seg = segments[x]; int blockNum = seg.allocateCrossCheckBlock(segment, random); if(blockNum >= 0) { segment.addDataBlock(seg, blockNum); return; } } throw new IllegalStateException("Unable to allocate cross data block!"); }
/** Cancel the download, stop all FEC decodes, and call close() off-thread when done. */ void cancel() { synchronized(this) { cancelled = true; } for(SplitFileFetcherSegmentStorage segment : segments) segment.cancel(); if(crossSegments != null) { for(SplitFileFetcherCrossSegmentStorage segment : crossSegments) segment.cancel(); } }
byte[][] dataBlocks = readBlocks(false); byte[][] checkBlocks = readBlocks(true); if(dataBlocks == null || checkBlocks == null) return; // Failed with disk error. boolean[] dataBlocksFound = wasNonNullFill(dataBlocks); boolean[] checkBlocksFound = wasNonNullFill(checkBlocks); int realTotalDataBlocks = count(dataBlocksFound); int realTotalCrossCheckBlocks = count(checkBlocksFound); int realTotalFound = realTotalDataBlocks + realTotalCrossCheckBlocks; for(int i=0;i<dataBlockCount;i++) { if(!dataBlocksFound[i]) { checkDecodedBlock(i, dataBlocks[i]); dataBlocksFound[i] = true; for(int i=0;i<crossCheckBlockCount;i++) { if(!checkBlocksFound[i]) { checkDecodedBlock(i+dataBlockCount, checkBlocks[i]);
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); } }
for(int i=0;i<segments;i++) { assertEquals(storage.crossSegments[i].dataBlockCount, fetcherStorage.crossSegments[i].dataBlockCount); assertTrue(Arrays.equals(storage.crossSegments[i].getSegmentNumbers(), fetcherStorage.crossSegments[i].getSegmentNumbers())); assertTrue(Arrays.equals(storage.crossSegments[i].getBlockNumbers(), fetcherStorage.crossSegments[i].getBlockNumbers()));
this.crossSegments = new SplitFileFetcherCrossSegmentStorage[crossSegments]; for(int i=0;i<crossSegments;i++) { this.crossSegments[i] = new SplitFileFetcherCrossSegmentStorage(this, i, dis); for(SplitFileFetcherCrossSegmentStorage crossSegment : this.crossSegments) crossSegment.checkBlocks();
failDiskOffThread(e); return null;
new SplitFileFetcherCrossSegmentStorage(i, segLen, crossCheckBlocks, this, fecCodec); crossSegments[i] = seg; for(int j=0;j<segLen;j++) {
for(int i=0;i<segments;i++) { assertEquals(storage.crossSegments[i].dataBlockCount, fetcherStorage.crossSegments[i].dataBlockCount); assertTrue(Arrays.equals(storage.crossSegments[i].getSegmentNumbers(), fetcherStorage.crossSegments[i].getSegmentNumbers())); assertTrue(Arrays.equals(storage.crossSegments[i].getBlockNumbers(), fetcherStorage.crossSegments[i].getBlockNumbers()));
/** FIXME not used yet */ private void allocateCrossDataBlock(SplitFileFetcherCrossSegmentStorage segment, Random random) { int x = 0; for(int i=0;i<10;i++) { x = random.nextInt(segments.length); SplitFileFetcherSegmentStorage seg = segments[x]; int blockNum = seg.allocateCrossDataBlock(segment, random); if(blockNum >= 0) { segment.addDataBlock(seg, blockNum); return; } } for(int i=0;i<segments.length;i++) { x++; if(x == segments.length) x = 0; SplitFileFetcherSegmentStorage seg = segments[x]; int blockNum = seg.allocateCrossDataBlock(segment, random); if(blockNum >= 0) { segment.addDataBlock(seg, blockNum); return; } } throw new IllegalStateException("Unable to allocate cross data block!"); }