forked from I2P_Developers/i2p.i2p
i2psnark: Store BEP 47 padding file info in a bitmap (prep for BEP 52),
WIP - unused for now. Don't instantiate files_utf8 unless needed, which it never is
This commit is contained in:
@ -58,6 +58,7 @@ public class MetaInfo
|
|||||||
private final String name_utf8;
|
private final String name_utf8;
|
||||||
private final List<List<String>> files;
|
private final List<List<String>> files;
|
||||||
private final List<List<String>> files_utf8;
|
private final List<List<String>> files_utf8;
|
||||||
|
private final BitField paddingFileBitfield;
|
||||||
private final List<Long> lengths;
|
private final List<Long> lengths;
|
||||||
private final int piece_length;
|
private final int piece_length;
|
||||||
private final byte[] piece_hashes;
|
private final byte[] piece_hashes;
|
||||||
@ -98,6 +99,9 @@ public class MetaInfo
|
|||||||
this.created_by = created_by;
|
this.created_by = created_by;
|
||||||
this.creation_date = I2PAppContext.getGlobalContext().clock().now();
|
this.creation_date = I2PAppContext.getGlobalContext().clock().now();
|
||||||
|
|
||||||
|
// TODO BEP 52 hybrid torrent with piece layers, meta version and file tree
|
||||||
|
this.paddingFileBitfield = null;
|
||||||
|
|
||||||
// TODO if we add a parameter for other keys
|
// TODO if we add a parameter for other keys
|
||||||
//if (other != null) {
|
//if (other != null) {
|
||||||
// otherInfo = new HashMap(2);
|
// otherInfo = new HashMap(2);
|
||||||
@ -261,6 +265,7 @@ public class MetaInfo
|
|||||||
files = null;
|
files = null;
|
||||||
files_utf8 = null;
|
files_utf8 = null;
|
||||||
lengths = null;
|
lengths = null;
|
||||||
|
paddingFileBitfield = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -276,8 +281,9 @@ public class MetaInfo
|
|||||||
throw new InvalidBEncodingException("zero size files list");
|
throw new InvalidBEncodingException("zero size files list");
|
||||||
|
|
||||||
List<List<String>> m_files = new ArrayList<List<String>>(size);
|
List<List<String>> m_files = new ArrayList<List<String>>(size);
|
||||||
List<List<String>> m_files_utf8 = new ArrayList<List<String>>(size);
|
List<List<String>> m_files_utf8 = null;
|
||||||
List<Long> m_lengths = new ArrayList<Long>(size);
|
List<Long> m_lengths = new ArrayList<Long>(size);
|
||||||
|
BitField paddingBitfield = null;
|
||||||
long l = 0;
|
long l = 0;
|
||||||
for (int i = 0; i < list.size(); i++)
|
for (int i = 0; i < list.size(); i++)
|
||||||
{
|
{
|
||||||
@ -323,6 +329,7 @@ public class MetaInfo
|
|||||||
|
|
||||||
val = desc.get("path.utf-8");
|
val = desc.get("path.utf-8");
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
|
m_files_utf8 = new ArrayList<List<String>>(size);
|
||||||
path_list = val.getList();
|
path_list = val.getList();
|
||||||
path_length = path_list.size();
|
path_length = path_list.size();
|
||||||
if (path_length > 0) {
|
if (path_length > 0) {
|
||||||
@ -333,11 +340,23 @@ public class MetaInfo
|
|||||||
m_files_utf8.add(Collections.unmodifiableList(file));
|
m_files_utf8.add(Collections.unmodifiableList(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BEP 47
|
||||||
|
val = desc.get("attr");
|
||||||
|
if (val != null) {
|
||||||
|
String s = val.getString();
|
||||||
|
if (s.contains("p")) {
|
||||||
|
if (paddingBitfield == null)
|
||||||
|
paddingBitfield = new BitField(size);
|
||||||
|
paddingBitfield.set(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
files = Collections.unmodifiableList(m_files);
|
files = Collections.unmodifiableList(m_files);
|
||||||
files_utf8 = Collections.unmodifiableList(m_files_utf8);
|
files_utf8 = m_files_utf8 != null ? Collections.unmodifiableList(m_files_utf8) : null;
|
||||||
lengths = Collections.unmodifiableList(m_lengths);
|
lengths = Collections.unmodifiableList(m_lengths);
|
||||||
length = l;
|
length = l;
|
||||||
|
paddingFileBitfield = paddingBitfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
info_hash = calculateInfoHash();
|
info_hash = calculateInfoHash();
|
||||||
@ -428,6 +447,16 @@ public class MetaInfo
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this file a padding file?
|
||||||
|
* @since 0.9.48
|
||||||
|
*/
|
||||||
|
public boolean isPaddingFile(int filenum) {
|
||||||
|
if (paddingFileBitfield == null)
|
||||||
|
return false;
|
||||||
|
return paddingFileBitfield.get(filenum);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of Longs indication the size of the individual
|
* Returns a list of Longs indication the size of the individual
|
||||||
* files, or null if it is a single file. It has the same size as
|
* files, or null if it is a single file. It has the same size as
|
||||||
@ -563,6 +592,7 @@ public class MetaInfo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total length of the torrent in bytes.
|
* Returns the total length of the torrent in bytes.
|
||||||
|
* This includes any padding files.
|
||||||
*/
|
*/
|
||||||
public long getTotalLength()
|
public long getTotalLength()
|
||||||
{
|
{
|
||||||
@ -697,6 +727,8 @@ public class MetaInfo
|
|||||||
info.put("files", new BEValue(l));
|
info.put("files", new BEValue(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO BEP 52 meta version and file tree
|
||||||
|
|
||||||
// TODO if we add the ability for other keys in the first constructor
|
// TODO if we add the ability for other keys in the first constructor
|
||||||
//if (otherInfo != null)
|
//if (otherInfo != null)
|
||||||
// info.putAll(otherInfo);
|
// info.putAll(otherInfo);
|
||||||
|
Reference in New Issue
Block a user