public class Metadata
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Metadata.DocumentType |
static class |
Metadata.SimpleManifestComposer
Helper for composing manifests
It is a replacement for mkRedirectionManifestWithMetadata, used in BaseManifestPutter |
static class |
Metadata.SplitfileAlgorithm |
Modifier and Type | Field and Description |
---|---|
static int |
MAX_SIZE_IN_MANIFEST |
static short |
SPLITFILE_PARAMS_CROSS_SEGMENT |
static short |
SPLITFILE_PARAMS_SEGMENT_DEDUCT_BLOCKS |
static short |
SPLITFILE_PARAMS_SIMPLE_SEGMENT |
int |
topBlocksRequired |
int |
topBlocksTotal |
InsertContext.CompatibilityMode |
topCompatibilityMode |
long |
topCompressedSize |
boolean |
topDontCompress |
long |
topSize |
Constructor and Description |
---|
Metadata(java.io.DataInputStream dis,
long length)
Parse some metadata from a DataInputStream
|
Metadata(Metadata.DocumentType docType,
ArchiveManager.ARCHIVE_TYPE archiveType,
Compressor.COMPRESSOR_TYPE compressionCodec,
FreenetURI uri,
ClientMetadata cm) |
Metadata(Metadata.DocumentType docType,
ArchiveManager.ARCHIVE_TYPE archiveType,
Compressor.COMPRESSOR_TYPE compressionCodec,
FreenetURI uri,
ClientMetadata cm,
long origDataLength,
long origCompressedDataLength,
int reqBlocks,
int totalBlocks,
boolean topDontCompress,
InsertContext.CompatibilityMode topCompatibilityMode,
HashResult[] hashes)
Create another kind of simple Metadata object (a redirect or similar object).
|
Metadata(Metadata.DocumentType docType,
ArchiveManager.ARCHIVE_TYPE archiveType,
Compressor.COMPRESSOR_TYPE compressionCodec,
java.lang.String arg,
ClientMetadata cm)
Create a really simple Metadata object.
|
Metadata(Metadata.SplitfileAlgorithm algo,
ClientCHK[] dataURIs,
ClientCHK[] checkURIs,
int segmentSize,
int checkSegmentSize,
int deductBlocksFromSegments,
ClientMetadata cm,
long dataLength,
ArchiveManager.ARCHIVE_TYPE archiveType,
Compressor.COMPRESSOR_TYPE compressionCodec,
long decompressedLength,
boolean isMetadata,
HashResult[] hashes,
byte[] hashThisLayerOnly,
long origDataSize,
long origCompressedDataSize,
int requiredBlocks,
int totalBlocks,
boolean topDontCompress,
InsertContext.CompatibilityMode topCompatibilityMode,
byte splitfileCryptoAlgorithm,
byte[] splitfileCryptoKey,
boolean specifySplitfileKey,
int crossSegmentBlocks)
Create metadata for a splitfile.
|
Modifier and Type | Method and Description |
---|---|
void |
clearSplitfileKeys() |
java.lang.Object |
clone() |
static Metadata |
construct(Bucket data)
Parse a bucket of data into a Metadata structure.
|
static Metadata |
construct(byte[] data)
Parse a block of bytes into a Metadata structure.
|
int |
countDocuments() |
long |
dataLength() |
java.lang.String |
dump() |
void |
dump(int indent,
java.lang.StringBuffer sb) |
static java.util.HashMap<java.lang.String,java.lang.Object> |
forceMap(java.lang.Object o)
Casts the given object to
HashMap<String, Object> , for dismissing
compiler warnings. |
java.lang.String |
getArchiveInternalName()
Return the name of the document referred to in the archive,
if this is a archive internal redirect.
|
ArchiveManager.ARCHIVE_TYPE |
getArchiveType()
What kind of archive is it?
|
int |
getCheckBlocksPerSegment() |
ClientMetadata |
getClientMetadata()
Return the client metadata (MIME type etc).
|
Compressor.COMPRESSOR_TYPE |
getCompressionCodec() |
int |
getCrossCheckBlocks() |
static byte[] |
getCrossSegmentSeed(byte[] hash) |
static byte[] |
getCrossSegmentSeed(HashResult[] hashes,
byte[] hashThisLayerOnly) |
static byte[] |
getCryptoKey(byte[] hash) |
static byte[] |
getCryptoKey(HashResult[] hashes) |
byte[] |
getCustomSplitfileKey()
If there is a custom (not computed from hashes) splitfile key, return it.
|
int |
getDataBlocksPerSegment() |
int |
getDeductBlocksFromSegments() |
Metadata |
getDefaultDocument()
The default document is the one which has an empty name.
|
Metadata |
getDocument(java.lang.String name)
Get the sub-document in a manifest file with the given name.
|
java.util.HashMap<java.lang.String,Metadata> |
getDocuments()
Get all documents in the manifest (ignores default doc).
|
HashResult[] |
getHashes() |
byte[] |
getHashThisLayerOnly() |
InsertContext.CompatibilityMode |
getMaxCompatMode() |
java.lang.String |
getMIMEType() |
InsertContext.CompatibilityMode |
getMinCompatMode() |
short |
getParsedVersion() |
java.lang.String |
getResolvedName()
get the resolved name (".metada-N")
(for KeyExplorer)
|
FreenetURI |
getResolvedURI() |
int |
getSegmentCount() |
SplitFileSegmentKeys[] |
getSegmentKeys() |
FreenetURI |
getSingleTarget()
Return the single target of this URI.
|
ClientCHK[] |
getSplitfileCheckKeys() |
byte |
getSplitfileCryptoAlgorithm() |
byte[] |
getSplitfileCryptoKey() |
ClientCHK[] |
getSplitfileDataKeys() |
Metadata.SplitfileAlgorithm |
getSplitfileType()
Get the splitfile type.
|
java.lang.String |
getSymbolicShortlinkTargetName()
Return the name of the document referred to in the dir,
if this is a symbolic short link.
|
short |
getTopCompatibilityCode() |
InsertContext.CompatibilityMode |
getTopCompatibilityMode() |
boolean |
getTopDontCompress() |
Metadata |
grabDefaultDocument()
Return and remove the default document.
|
Metadata |
grabDocument(java.lang.String name)
Return and remove a specific document.
|
SplitFileSegmentKeys[] |
grabSegmentKeys() |
InsertContext.CompatibilityMode |
guessCompatibilityMode()
Return a best-guess compatibility mode, guaranteed not to be
COMPAT_UNKNOWN or COMPAT_CURRENT.
|
int |
hashCode() |
boolean |
hasTopData() |
boolean |
haveFlags()
have this metadata flags?
|
boolean |
isArchiveInternalRedirect()
Is this a Archive internal redirect?
|
boolean |
isArchiveManifest()
Is this a Archive manifest?
|
boolean |
isArchiveMetadataRedirect()
Is this a archive internal metadata redirect?
|
boolean |
isCompressed() |
boolean |
isMultiLevelMetadata()
Is multi-level/indirect metadata?
|
boolean |
isNoMimeEnabled()
Is noMime enabled?
(for KeyExplorer)
|
boolean |
isResolved() |
boolean |
isSimpleManifest()
Is a manifest?
|
boolean |
isSimpleRedirect()
Is this a simple redirect?
(for KeyExplorer)
|
boolean |
isSimpleSplitfile()
Is this a simple splitfile?
|
boolean |
isSingleFileRedirect()
Does the metadata point to a single URI?
|
boolean |
isSplitfile()
Is this a splitfile manifest?
|
boolean |
isSymbolicShortlink()
Is this a symbilic shortlink?
|
static boolean |
isValidSplitfileCryptoAlgorithm(byte cryptoAlgorithm) |
static Metadata |
mkRedirectionManifest(java.util.HashMap<java.lang.String,java.lang.Object> dir)
Create a Metadata object and add data for redirection to it.
|
static Metadata |
mkRedirectionManifestWithMetadata(java.util.HashMap<java.lang.String,java.lang.Object> dir)
Create a Metadata object and add manifest entries from the given map.
|
void |
resolve(FreenetURI uri) |
void |
resolve(java.lang.String name) |
void |
setArchiveManifest() |
void |
setSimpleRedirect()
Change the document type to a simple redirect.
|
byte[] |
splitfileParams() |
RandomAccessBucket |
toBucket(BucketFactory bf) |
long |
uncompressedDataLength() |
void |
writeTo(java.io.DataOutputStream dos)
Write the metadata as binary.
|
byte[] |
writeToByteArray()
Write the data to a byte array.
|
long |
writtenLength() |
public static final short SPLITFILE_PARAMS_SIMPLE_SEGMENT
public static final short SPLITFILE_PARAMS_SEGMENT_DEDUCT_BLOCKS
public static final short SPLITFILE_PARAMS_CROSS_SEGMENT
public static final int MAX_SIZE_IN_MANIFEST
public final long topSize
public final long topCompressedSize
public final int topBlocksRequired
public final int topBlocksTotal
public final boolean topDontCompress
public final InsertContext.CompatibilityMode topCompatibilityMode
public Metadata(java.io.DataInputStream dis, long length) throws java.io.IOException, MetadataParseException
java.io.IOException
- If an I/O error occurs, or the data is incomplete.MetadataParseException
public Metadata(Metadata.DocumentType docType, ArchiveManager.ARCHIVE_TYPE archiveType, Compressor.COMPRESSOR_TYPE compressionCodec, java.lang.String arg, ClientMetadata cm)
docType
- The document type. Must be something that takes a single argument.
At the moment this means ARCHIVE_INTERNAL_REDIRECT.arg
- The argument; in the case of ARCHIVE_INTERNAL_REDIRECT, the filename in
the archive to read from.public Metadata(Metadata.DocumentType docType, ArchiveManager.ARCHIVE_TYPE archiveType, Compressor.COMPRESSOR_TYPE compressionCodec, FreenetURI uri, ClientMetadata cm)
public Metadata(Metadata.DocumentType docType, ArchiveManager.ARCHIVE_TYPE archiveType, Compressor.COMPRESSOR_TYPE compressionCodec, FreenetURI uri, ClientMetadata cm, long origDataLength, long origCompressedDataLength, int reqBlocks, int totalBlocks, boolean topDontCompress, InsertContext.CompatibilityMode topCompatibilityMode, HashResult[] hashes)
docType
- The document type.uri
- The URI pointed to.cm
- The client metadata, if any.public Metadata(Metadata.SplitfileAlgorithm algo, ClientCHK[] dataURIs, ClientCHK[] checkURIs, int segmentSize, int checkSegmentSize, int deductBlocksFromSegments, ClientMetadata cm, long dataLength, ArchiveManager.ARCHIVE_TYPE archiveType, Compressor.COMPRESSOR_TYPE compressionCodec, long decompressedLength, boolean isMetadata, HashResult[] hashes, byte[] hashThisLayerOnly, long origDataSize, long origCompressedDataSize, int requiredBlocks, int totalBlocks, boolean topDontCompress, InsertContext.CompatibilityMode topCompatibilityMode, byte splitfileCryptoAlgorithm, byte[] splitfileCryptoKey, boolean specifySplitfileKey, int crossSegmentBlocks)
algo
- The splitfile FEC algorithm.dataURIs
- The data URIs, including cross-check blocks for each segment.checkURIs
- The check URIs.segmentSize
- The number of data blocks in a typical segment. Does not include cross-check blocks.checkSegmentSize
- The number of check blocks in a typical segment. Does not include cross-check blocks.deductBlocksFromSegments
- If this is set, the last few segments will lose a data block, so that all
the segments are the same size to within 1 block. In older splitfiles, the last segment could be
significantly smaller, and this impacted on retrievability.cm
- The client metadata i.e. MIME type.dataLength
- The size of the data that this specific splitfile encodes (as opposed to the final data),
after compression if necessary.archiveType
- The archive type, if the splitfile is a container.compressionCodec
- The compression codec used to compress the data.decompressedLength
- The length of this specific splitfile's data after it has been decompressed.isMetadata
- If true, the splitfile is multi-level metadata i.e. it encodes a bucket full of metadata.
This usually happens for really big splitfiles, which can be a pyramid of one block with metadata for a
splitfile full of metadata, that metadata then encodes another splitfile full of metadata, etc. Hence we
can support very large files.hashes
- Various hashes of the final data. There should always be at least an SHA256 hash,
unless we are inserting with an old compatibility mode.hashThisLayerOnly
- Hash of the data in this layer (before compression). Separate from hashes of the
final data. Not currently verified.origDataSize
- The size of the final/original data.origCompressedDataSize
- The size of the final/original data after it was compressed.requiredBlocks
- The number of blocks required on fetch to reconstruct the final data. Hence as soon
as we have the top splitfile metadata (i.e. hopefully in the top block), we can show an accurate progress
bar.totalBlocks
- The total number of blocks inserted during the whole insert for the final/original data.topDontCompress
- Whether dontCompress was enabled. This allows us to figure out reinsert settings
more quickly.topCompatibilityMode
- The compatibility mode applying to the insert. This allows us to figure out
reinsert settings more quickly.splitfileCryptoAlgorithm
- The block level crypto algorithm for all the blocks in the splitfile.splitfileCryptoKey
- The single encryption key used by all blocks in the splitfile. Older splitfiles
don't have this so have to specify the full keys; newer splitfiles just specify the 32 byte routing key
for each data or check key.specifySplitfileKey
- If false, the splitfile crypto key has been automatically computed from the
final or this-layer data hash. If true, it has been specified explicitly, either because it is randomly
generated (this significantly improves security against mobile attacker source tracing and is the default
for splitfiles under SSKs), or because a file is being reinserted.crossSegmentBlocks
- The number of cross-check blocks. If this is specified, we are using
cross-segment redundancy. This greatly improves reliability on files over 80MB, see bug #3370.public java.lang.Object clone()
clone
in class java.lang.Object
public static Metadata construct(byte[] data) throws MetadataParseException
MetadataParseException
- If the metadata is invalid.public static Metadata construct(Bucket data) throws MetadataParseException, java.io.IOException
MetadataParseException
- If the parsing failed because of invalid metadata.java.io.IOException
- If we could not read the metadata from the bucket.public int hashCode()
hashCode
in class java.lang.Object
public static byte[] getCryptoKey(HashResult[] hashes)
public static byte[] getCryptoKey(byte[] hash)
public static byte[] getCrossSegmentSeed(HashResult[] hashes, byte[] hashThisLayerOnly)
public static byte[] getCrossSegmentSeed(byte[] hash)
public static Metadata mkRedirectionManifest(java.util.HashMap<java.lang.String,java.lang.Object> dir) throws java.net.MalformedURLException
dir
- A map of names (string) to either files (same string) or
directories (more HashMap's)java.net.MalformedURLException
- One of the URI:s were malformedpublic static Metadata mkRedirectionManifestWithMetadata(java.util.HashMap<java.lang.String,java.lang.Object> dir)
public byte[] writeToByteArray() throws MetadataUnresolvedException
MetadataUnresolvedException
public long writtenLength() throws MetadataUnresolvedException
MetadataUnresolvedException
public boolean isSimpleManifest()
public Metadata getDocument(java.lang.String name)
MetadataParseException
public Metadata grabDocument(java.lang.String name)
public Metadata getDefaultDocument()
MetadataParseException
public Metadata grabDefaultDocument()
public java.util.HashMap<java.lang.String,Metadata> getDocuments()
MetadataParseException
public boolean isSingleFileRedirect()
public FreenetURI getSingleTarget()
public boolean isArchiveManifest()
public boolean isArchiveMetadataRedirect()
public boolean isArchiveInternalRedirect()
public java.lang.String getArchiveInternalName()
public java.lang.String getSymbolicShortlinkTargetName()
public ClientMetadata getClientMetadata()
public boolean isSplitfile()
public boolean isSimpleSplitfile()
public boolean isMultiLevelMetadata()
public ArchiveManager.ARCHIVE_TYPE getArchiveType()
public void setSimpleRedirect()
public boolean isSimpleRedirect()
public boolean isNoMimeEnabled()
public java.lang.String getResolvedName()
public boolean isSymbolicShortlink()
public void writeTo(java.io.DataOutputStream dos) throws java.io.IOException, MetadataUnresolvedException
java.io.IOException
- If an I/O error occurred while writing the data.MetadataUnresolvedException
public boolean haveFlags()
public Metadata.SplitfileAlgorithm getSplitfileType()
public ClientCHK[] getSplitfileDataKeys()
public ClientCHK[] getSplitfileCheckKeys()
public boolean isCompressed()
public Compressor.COMPRESSOR_TYPE getCompressionCodec()
public long dataLength()
public byte[] splitfileParams()
public long uncompressedDataLength()
public FreenetURI getResolvedURI()
public void resolve(FreenetURI uri)
public void resolve(java.lang.String name)
public RandomAccessBucket toBucket(BucketFactory bf) throws MetadataUnresolvedException, java.io.IOException
MetadataUnresolvedException
java.io.IOException
public boolean isResolved()
public void setArchiveManifest()
public java.lang.String getMIMEType()
public void clearSplitfileKeys()
public int countDocuments()
public java.lang.String dump()
public void dump(int indent, java.lang.StringBuffer sb)
public static java.util.HashMap<java.lang.String,java.lang.Object> forceMap(java.lang.Object o)
HashMap<String, Object>
, for dismissing
compiler warnings. Use only when you are sure the object matches this type!public short getParsedVersion()
public boolean hasTopData()
public HashResult[] getHashes()
public byte[] getCustomSplitfileKey()
public byte[] getSplitfileCryptoKey()
public byte[] getHashThisLayerOnly()
public byte getSplitfileCryptoAlgorithm()
public InsertContext.CompatibilityMode getTopCompatibilityMode()
public boolean getTopDontCompress()
public short getTopCompatibilityCode()
public InsertContext.CompatibilityMode getMinCompatMode()
public InsertContext.CompatibilityMode getMaxCompatMode()
public int getCrossCheckBlocks()
public int getCheckBlocksPerSegment()
public int getDataBlocksPerSegment()
public int getSegmentCount()
public SplitFileSegmentKeys[] grabSegmentKeys() throws FetchException
FetchException
public SplitFileSegmentKeys[] getSegmentKeys() throws FetchException
FetchException
public int getDeductBlocksFromSegments()
public InsertContext.CompatibilityMode guessCompatibilityMode()
public static boolean isValidSplitfileCryptoAlgorithm(byte cryptoAlgorithm)