Author: nextgens
Date: 2006-01-20 19:32:04 +0000 (Fri, 20 Jan 2006)
New Revision: 7888
Removed:
branches/async-client-layer/
trunk/freenet/src/freenet/client/StartableSplitfileBlock.java
Modified:
trunk/freenet/src/freenet/client/ArchiveHandler.java
trunk/freenet/src/freenet/client/ClientMetadata.java
trunk/freenet/src/freenet/client/FECCodec.java
trunk/freenet/src/freenet/client/InsertSegment.java
trunk/freenet/src/freenet/client/Metadata.java
trunk/freenet/src/freenet/client/RetryTracker.java
trunk/freenet/src/freenet/client/RetryTrackerCallback.java
trunk/freenet/src/freenet/client/SplitInserter.java
trunk/freenet/src/freenet/client/StdSplitfileBlock.java
Log:
Reverting changes : latest good revision is 7884
Modified: trunk/freenet/src/freenet/client/ArchiveHandler.java
===================================================================
--- trunk/freenet/src/freenet/client/ArchiveHandler.java 2006-01-20
19:11:02 UTC (rev 7887)
+++ trunk/freenet/src/freenet/client/ArchiveHandler.java 2006-01-20
19:32:04 UTC (rev 7888)
@@ -6,7 +6,7 @@
* The public face (to Fetcher, for example) of ArchiveStoreContext.
* Just has methods for fetching stuff.
*/
-public interface ArchiveHandler {
+interface ArchiveHandler {
/**
* Get the metadata for this ZIP manifest, as a Bucket.
@@ -36,9 +36,4 @@
throws ArchiveFailureException, ArchiveRestartException,
MetadataParseException, FetchException;
- /**
- * Get the archive type.
- */
- public abstract short getArchiveType();
-
}
\ No newline at end of file
Modified: trunk/freenet/src/freenet/client/ClientMetadata.java
===================================================================
--- trunk/freenet/src/freenet/client/ClientMetadata.java 2006-01-20
19:11:02 UTC (rev 7887)
+++ trunk/freenet/src/freenet/client/ClientMetadata.java 2006-01-20
19:32:04 UTC (rev 7888)
@@ -13,7 +13,7 @@
}
/** Create an empty ClientMetadata instance */
- public ClientMetadata() {
+ ClientMetadata() {
mimeType = null;
}
Modified: trunk/freenet/src/freenet/client/FECCodec.java
===================================================================
--- trunk/freenet/src/freenet/client/FECCodec.java 2006-01-20 19:11:02 UTC
(rev 7887)
+++ trunk/freenet/src/freenet/client/FECCodec.java 2006-01-20 19:32:04 UTC
(rev 7888)
@@ -11,7 +11,7 @@
* @author root
*
*/
-public abstract class FECCodec {
+abstract class FECCodec {
/**
* Get a codec where we know both the number of data blocks and the
number
Modified: trunk/freenet/src/freenet/client/InsertSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/InsertSegment.java 2006-01-20 19:11:02 UTC
(rev 7887)
+++ trunk/freenet/src/freenet/client/InsertSegment.java 2006-01-20 19:32:04 UTC
(rev 7888)
@@ -12,22 +12,22 @@
public class InsertSegment {
final FECCodec codec;
- final StartableSplitfileBlock[] origDataBlocks;
+ final SplitfileBlock[] origDataBlocks;
final int blockLength;
final BucketFactory bf;
/** Check blocks. Will be created by encode(...). */
- final StartableSplitfileBlock[] checkBlocks;
+ final SplitfileBlock[] checkBlocks;
final boolean getCHKOnly;
// just for debugging
final int segNo;
- public InsertSegment(short splitfileAlgo, StartableSplitfileBlock[]
origDataBlocks, int blockLength, BucketFactory bf, boolean getCHKOnly, int
segNo) {
+ public InsertSegment(short splitfileAlgo, SplitfileBlock[]
origDataBlocks, int blockLength, BucketFactory bf, boolean getCHKOnly, int
segNo) {
this.origDataBlocks = origDataBlocks;
codec = FECCodec.getCodec(splitfileAlgo, origDataBlocks.length);
if(codec != null)
- checkBlocks = new
StartableSplitfileBlock[codec.countCheckBlocks()];
+ checkBlocks = new
SplitfileBlock[codec.countCheckBlocks()];
else
- checkBlocks = new StartableSplitfileBlock[0];
+ checkBlocks = new SplitfileBlock[0];
this.blockLength = blockLength;
this.bf = bf;
this.getCHKOnly = getCHKOnly;
Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java 2006-01-20 19:11:02 UTC
(rev 7887)
+++ trunk/freenet/src/freenet/client/Metadata.java 2006-01-20 19:32:04 UTC
(rev 7888)
@@ -19,104 +19,13 @@
/** Metadata parser/writer class. */
-public class Metadata implements Cloneable {
+public class Metadata {
static final long FREENET_METADATA_MAGIC = 0xf053b2842d91482bL;
static final int MAX_SPLITFILE_PARAMS_LENGTH = 32768;
/** Soft limit, to avoid memory DoS */
static final int MAX_SPLITFILE_BLOCKS = 100*1000;
- // Actual parsed data
-
- // document type
- byte documentType;
- static final byte SIMPLE_REDIRECT = 0;
- static final byte MULTI_LEVEL_METADATA = 1;
- static final byte SIMPLE_MANIFEST = 2;
- static final byte ZIP_MANIFEST = 3;
- static final byte ZIP_INTERNAL_REDIRECT = 4;
-
- // 2 bytes of flags
- /** Is a splitfile */
- boolean splitfile;
- /** Is a DBR */
- boolean dbr;
- /** No MIME type; on by default as not all doctypes have MIME */
- boolean noMIME = true;
- /** Compressed MIME type */
- boolean compressedMIME;
- /** Has extra client-metadata */
- boolean extraMetadata;
- /** Keys stored in full (otherwise assumed to be CHKs) */
- boolean fullKeys;
- /** Non-final splitfile chunks can be non-full */
- boolean splitUseLengths;
- static final short FLAGS_SPLITFILE = 1;
- static final short FLAGS_DBR = 2;
- static final short FLAGS_NO_MIME = 4;
- static final short FLAGS_COMPRESSED_MIME = 8;
- static final short FLAGS_EXTRA_METADATA = 16;
- static final short FLAGS_FULL_KEYS = 32;
- static final short FLAGS_SPLIT_USE_LENGTHS = 64;
- static final short FLAGS_COMPRESSED = 128;
-
- /** Container archive type */
- short archiveType;
- static final short ARCHIVE_ZIP = 0;
- static final short ARCHIVE_TAR = 1; // FIXME for future use
-
- /** Compressed splitfile codec */
- short compressionCodec = -1;
- static public final short COMPRESS_GZIP = 0;
- static final short COMPRESS_BZIP2 = 1; // FIXME for future use
-
- /** The length of the splitfile */
- long dataLength;
- /** The decompressed length of the compressed data */
- long decompressedLength;
-
- /** The MIME type, as a string */
- String mimeType;
-
- /** The compressed MIME type - lookup index for the MIME types table.
- * Must be between 0 and 32767.
- */
- short compressedMIMEValue;
- boolean hasCompressedMIMEParams;
- short compressedMIMEParams;
-
- /** The simple redirect key */
- FreenetURI simpleRedirectKey;
-
- short splitfileAlgorithm;
- static public final short SPLITFILE_NONREDUNDANT = 0;
- static public final short SPLITFILE_ONION_STANDARD = 1;
-
- /** Splitfile parameters */
- byte[] splitfileParams;
- int splitfileBlocks;
- int splitfileCheckBlocks;
- FreenetURI[] splitfileDataKeys;
- FreenetURI[] splitfileCheckKeys;
-
- // Manifests
- int manifestEntryCount;
- /** Manifest entries by name */
- HashMap manifestEntries;
-
- /** ZIP internal redirect: name of file in ZIP */
- String nameInArchive;
-
- ClientMetadata clientMetadata;
-
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException e) {
- throw new Error("Yes it is!");
- }
- }
-
/** Parse a block of bytes into a Metadata structure.
* Constructor method because of need to catch impossible exceptions.
* @throws MetadataParseException If the metadata is invalid.
@@ -598,6 +507,89 @@
} else throw new IllegalArgumentException("Full keys
must be enabled to write non-CHKs");
}
}
+ // Actual parsed data
+
+ // document type
+ byte documentType;
+ static final byte SIMPLE_REDIRECT = 0;
+ static final byte MULTI_LEVEL_METADATA = 1;
+ static final byte SIMPLE_MANIFEST = 2;
+ static final byte ZIP_MANIFEST = 3;
+ static final byte ZIP_INTERNAL_REDIRECT = 4;
+
+ // 2 bytes of flags
+ /** Is a splitfile */
+ boolean splitfile;
+ /** Is a DBR */
+ boolean dbr;
+ /** No MIME type; on by default as not all doctypes have MIME */
+ boolean noMIME = true;
+ /** Compressed MIME type */
+ boolean compressedMIME;
+ /** Has extra client-metadata */
+ boolean extraMetadata;
+ /** Keys stored in full (otherwise assumed to be CHKs) */
+ boolean fullKeys;
+ /** Non-final splitfile chunks can be non-full */
+ boolean splitUseLengths;
+ static final short FLAGS_SPLITFILE = 1;
+ static final short FLAGS_DBR = 2;
+ static final short FLAGS_NO_MIME = 4;
+ static final short FLAGS_COMPRESSED_MIME = 8;
+ static final short FLAGS_EXTRA_METADATA = 16;
+ static final short FLAGS_FULL_KEYS = 32;
+ static final short FLAGS_SPLIT_USE_LENGTHS = 64;
+ static final short FLAGS_COMPRESSED = 128;
+
+ /** Container archive type */
+ short archiveType;
+ static final short ARCHIVE_ZIP = 0;
+ static final short ARCHIVE_TAR = 1; // FIXME for future use
+
+ /** Compressed splitfile codec */
+ short compressionCodec = -1;
+ static public final short COMPRESS_GZIP = 0;
+ static final short COMPRESS_BZIP2 = 1; // FIXME for future use
+
+ /** The length of the splitfile */
+ long dataLength;
+ /** The decompressed length of the compressed data */
+ long decompressedLength;
+
+ /** The MIME type, as a string */
+ String mimeType;
+
+ /** The compressed MIME type - lookup index for the MIME types table.
+ * Must be between 0 and 32767.
+ */
+ short compressedMIMEValue;
+ boolean hasCompressedMIMEParams;
+ short compressedMIMEParams;
+
+ /** The simple redirect key */
+ FreenetURI simpleRedirectKey;
+
+ short splitfileAlgorithm;
+ static final short SPLITFILE_NONREDUNDANT = 0;
+ static final short SPLITFILE_ONION_STANDARD = 1;
+
+ /** Splitfile parameters */
+ byte[] splitfileParams;
+ int splitfileBlocks;
+ int splitfileCheckBlocks;
+ FreenetURI[] splitfileDataKeys;
+ FreenetURI[] splitfileCheckKeys;
+
+ // Manifests
+ int manifestEntryCount;
+ /** Manifest entries by name */
+ HashMap manifestEntries;
+
+ /** ZIP internal redirect: name of file in ZIP */
+ String nameInArchive;
+
+ ClientMetadata clientMetadata;
+
/** Is a manifest? */
public boolean isSimpleManifest() {
return documentType == SIMPLE_MANIFEST;
@@ -807,20 +799,4 @@
public boolean isCompressed() {
return compressionCodec >= 0;
}
-
- public boolean splitUseLengths() {
- return splitUseLengths;
- }
-
- public short getCompressionCodec() {
- return compressionCodec;
- }
-
- public long dataLength() {
- return dataLength;
- }
-
- public byte[] splitfileParams() {
- return splitfileParams;
- }
}
Modified: trunk/freenet/src/freenet/client/RetryTracker.java
===================================================================
--- trunk/freenet/src/freenet/client/RetryTracker.java 2006-01-20 19:11:02 UTC
(rev 7887)
+++ trunk/freenet/src/freenet/client/RetryTracker.java 2006-01-20 19:32:04 UTC
(rev 7888)
@@ -26,16 +26,16 @@
* Return a random block.
* Call synchronized on RetryTracker.
*/
- StartableSplitfileBlock getBlock() {
+ SplitfileBlock getBlock() {
int len = blocks.size();
int x = random.nextInt(len);
- StartableSplitfileBlock block =
(StartableSplitfileBlock) blocks.remove(x);
+ SplitfileBlock block = (SplitfileBlock)
blocks.remove(x);
if(blocks.isEmpty())
removeLevel(level);
return block;
}
- void add(StartableSplitfileBlock block) {
+ void add(SplitfileBlock block) {
blocks.add(block);
}
@@ -44,7 +44,7 @@
* Remove self if run out of blocks.
* Call synchronized on RetryTracker.
*/
- void remove(StartableSplitfileBlock block) {
+ void remove(SplitfileBlock block) {
blocks.remove(block);
if(blocks.isEmpty())
removeLevel(level);
@@ -167,7 +167,7 @@
/**
* Add a block at retry level zero.
*/
- public synchronized void addBlock(StartableSplitfileBlock block) {
+ public synchronized void addBlock(SplitfileBlock block) {
if(killed) return;
Level l = makeLevel(0);
l.add(block);
@@ -179,7 +179,7 @@
* Move it out of the running list and back into the relevant list,
unless
* we have run out of retries.
*/
- public void nonfatalError(StartableSplitfileBlock block, int
reasonCode) {
+ public void nonfatalError(SplitfileBlock block, int reasonCode) {
synchronized(this) {
nonfatalErrors.inc(reasonCode);
runningBlocks.remove(block);
@@ -204,7 +204,7 @@
* Move it into the fatal error list.
* @param reasonCode A client-specific code indicating the type of
failure.
*/
- public void fatalError(StartableSplitfileBlock block, int reasonCode) {
+ public void fatalError(SplitfileBlock block, int reasonCode) {
synchronized(this) {
fatalErrors.inc(reasonCode);
runningBlocks.remove(block);
@@ -238,7 +238,7 @@
|| (runningBlocks.isEmpty() && levels.isEmpty()
&& finishOnEmpty)) {
killed = true;
Logger.minor(this, "Finishing");
- StartableSplitfileBlock[] running = runningBlocks();
+ SplitfileBlock[] running = runningBlocks();
for(int i=0;i<running.length;i++) {
running[i].kill();
}
@@ -253,7 +253,7 @@
}
} else {
while(runningBlocks.size() < maxThreads) {
- StartableSplitfileBlock block = getBlock();
+ SplitfileBlock block = getBlock();
if(block == null) break;
Logger.minor(this, "Starting: "+block);
block.start();
@@ -265,7 +265,7 @@
callback.finished(succeededBlocks(), failedBlocks(),
fatalErrorBlocks());
}
- public void success(StartableSplitfileBlock block) {
+ public void success(SplitfileBlock block) {
synchronized(this) {
if(killed) return;
runningBlocks.remove(block);
@@ -284,7 +284,7 @@
* Get the next block to try. This is a randomly selected block from the
* lowest priority currently available. Move it into the running list.
*/
- public synchronized StartableSplitfileBlock getBlock() {
+ public synchronized SplitfileBlock getBlock() {
if(killed) return null;
Integer iMin = new Integer(curMinLevel);
Level l = (Level) levels.get(iMin);
@@ -309,34 +309,34 @@
/**
* Get all running blocks.
*/
- public synchronized StartableSplitfileBlock[] runningBlocks() {
- return (StartableSplitfileBlock[])
- runningBlocks.toArray(new
StartableSplitfileBlock[runningBlocks.size()]);
+ public synchronized SplitfileBlock[] runningBlocks() {
+ return (SplitfileBlock[])
+ runningBlocks.toArray(new
SplitfileBlock[runningBlocks.size()]);
}
/**
* Get all blocks with fatal errors.
- * StartableSplitfileBlock's are assumed to remember their errors, so
we don't.
+ * SplitfileBlock's are assumed to remember their errors, so we don't.
*/
- public synchronized StartableSplitfileBlock[] fatalErrorBlocks() {
- return (StartableSplitfileBlock[])
- failedBlocksFatalErrors.toArray(new
StartableSplitfileBlock[failedBlocksFatalErrors.size()]);
+ public synchronized SplitfileBlock[] fatalErrorBlocks() {
+ return (SplitfileBlock[])
+ failedBlocksFatalErrors.toArray(new
SplitfileBlock[failedBlocksFatalErrors.size()]);
}
/**
* Get all blocks which didn't succeed in the maximum number of tries.
*/
- public synchronized StartableSplitfileBlock[] failedBlocks() {
- return (StartableSplitfileBlock[])
- failedBlocksTooManyRetries.toArray(new
StartableSplitfileBlock[failedBlocksTooManyRetries.size()]);
+ public synchronized SplitfileBlock[] failedBlocks() {
+ return (SplitfileBlock[])
+ failedBlocksTooManyRetries.toArray(new
SplitfileBlock[failedBlocksTooManyRetries.size()]);
}
/**
* Get all successfully downloaded blocks.
*/
- public synchronized StartableSplitfileBlock[] succeededBlocks() {
- return (StartableSplitfileBlock[])
- succeededBlocks.toArray(new
StartableSplitfileBlock[succeededBlocks.size()]);
+ public synchronized SplitfileBlock[] succeededBlocks() {
+ return (SplitfileBlock[])
+ succeededBlocks.toArray(new
SplitfileBlock[succeededBlocks.size()]);
}
public synchronized int succeededBlocksLength() {
@@ -384,7 +384,7 @@
killed = true;
levels.clear();
for(Iterator i=runningBlocks.iterator();i.hasNext();) {
- StartableSplitfileBlock sb = (StartableSplitfileBlock)
i.next();
+ SplitfileBlock sb = (SplitfileBlock) i.next();
sb.kill();
}
runningBlocks.clear();
Modified: trunk/freenet/src/freenet/client/RetryTrackerCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/RetryTrackerCallback.java 2006-01-20
19:11:02 UTC (rev 7887)
+++ trunk/freenet/src/freenet/client/RetryTrackerCallback.java 2006-01-20
19:32:04 UTC (rev 7888)
@@ -11,7 +11,7 @@
* @param failed The blocks which failed.
* @param fatalErrors The blocks which got fatal errors.
*/
- void finished(StartableSplitfileBlock[] succeeded,
StartableSplitfileBlock[] failed, StartableSplitfileBlock[] fatalErrors);
+ void finished(SplitfileBlock[] succeeded, SplitfileBlock[] failed,
SplitfileBlock[] fatalErrors);
/**
* When a block completes etc.
Modified: trunk/freenet/src/freenet/client/SplitInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/SplitInserter.java 2006-01-20 19:11:02 UTC
(rev 7887)
+++ trunk/freenet/src/freenet/client/SplitInserter.java 2006-01-20 19:32:04 UTC
(rev 7888)
@@ -30,7 +30,7 @@
final int blockSize;
final boolean isMetadata;
final Bucket returnMetadata;
- StartableSplitfileBlock[] origDataBlocks;
+ SplitfileBlock[] origDataBlocks;
InsertSegment encodingSegment;
InsertSegment[] segments;
private boolean finishedInserting = false;
@@ -39,7 +39,7 @@
private int failed;
private int fatalErrors;
private int countCheckBlocks;
- private StartableSplitfileBlock[] fatalErrorBlocks;
+ private SplitfileBlock[] fatalErrorBlocks;
private FileInserter inserter;
/**
@@ -232,7 +232,7 @@
*/
private void splitIntoBlocks() throws IOException {
Bucket[] dataBuckets = BucketTools.split(origData,
NodeCHK.BLOCK_SIZE, ctx.bf);
- origDataBlocks = new
StartableSplitfileBlock[dataBuckets.length];
+ origDataBlocks = new SplitfileBlock[dataBuckets.length];
for(int i=0;i<origDataBlocks.length;i++) {
origDataBlocks[i] = new BlockInserter(dataBuckets[i],
i, tracker, ctx, getCHKOnly);
if(origDataBlocks[i].getData() == null)
@@ -259,7 +259,7 @@
int segNo = 0;
for(int i=segmentSize;;i+=segmentSize) {
if(i > dataBlocks) i = dataBlocks;
- StartableSplitfileBlock[] seg = new
StartableSplitfileBlock[i-j];
+ SplitfileBlock[] seg = new SplitfileBlock[i-j];
System.arraycopy(origDataBlocks, j, seg, 0,
i-j);
j = i;
for(int x=0;x<seg.length;x++)
@@ -275,7 +275,7 @@
segments = (InsertSegment[]) segs.toArray(new
InsertSegment[segs.size()]);
}
- public void finished(StartableSplitfileBlock[] succeeded,
StartableSplitfileBlock[] failed, StartableSplitfileBlock[] fatalErrors) {
+ public void finished(SplitfileBlock[] succeeded, SplitfileBlock[]
failed, SplitfileBlock[] fatalErrors) {
synchronized(this) {
finishedInserting = true;
this.succeeded = succeeded.length;
Deleted: trunk/freenet/src/freenet/client/StartableSplitfileBlock.java
===================================================================
--- trunk/freenet/src/freenet/client/StartableSplitfileBlock.java
2006-01-20 19:11:02 UTC (rev 7887)
+++ trunk/freenet/src/freenet/client/StartableSplitfileBlock.java
2006-01-20 19:32:04 UTC (rev 7888)
@@ -1,25 +0,0 @@
-package freenet.client;
-
-import freenet.keys.FreenetURI;
-
-/** Simple interface for a splitfile block */
-public interface StartableSplitfileBlock extends SplitfileBlock {
-
- /** Start the fetch (or insert). Implementation is required to call
relevant
- * methods on RetryTracker when done. */
- abstract void start();
-
- /**
- * Shut down the fetch as soon as reasonably possible.
- */
- abstract public void kill();
-
- abstract public int getRetryCount();
-
- /**
- * Get the URI of the file. For an insert, this is derived during
insert.
- * For a request, it is fixed in the constructor.
- */
- abstract public FreenetURI getURI();
-
-}
Modified: trunk/freenet/src/freenet/client/StdSplitfileBlock.java
===================================================================
--- trunk/freenet/src/freenet/client/StdSplitfileBlock.java 2006-01-20
19:11:02 UTC (rev 7887)
+++ trunk/freenet/src/freenet/client/StdSplitfileBlock.java 2006-01-20
19:32:04 UTC (rev 7888)
@@ -3,7 +3,7 @@
import freenet.support.Bucket;
import freenet.support.Logger;
-public abstract class StdSplitfileBlock implements StartableSplitfileBlock ,
Runnable {
+public abstract class StdSplitfileBlock extends SplitfileBlock implements
Runnable {
Bucket fetchedData;
protected final RetryTracker tracker;