forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 0a3db5b65f8fdc3e91000c9dff9e679401b52f72)
to branch 'i2p.i2p.zzz.test' (head 8648a7d67ffff19124cafdd14648c13dedccd2ba)
This commit is contained in:
@ -61,6 +61,7 @@ public class MetaInfo
|
|||||||
private final int piece_length;
|
private final int piece_length;
|
||||||
private final byte[] piece_hashes;
|
private final byte[] piece_hashes;
|
||||||
private final long length;
|
private final long length;
|
||||||
|
private final boolean privateTorrent;
|
||||||
private Map<String, BEValue> infoMap;
|
private Map<String, BEValue> infoMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +72,7 @@ public class MetaInfo
|
|||||||
* @param lengths null for single-file torrent
|
* @param lengths null for single-file torrent
|
||||||
*/
|
*/
|
||||||
MetaInfo(String announce, String name, String name_utf8, List<List<String>> files, List<Long> lengths,
|
MetaInfo(String announce, String name, String name_utf8, List<List<String>> files, List<Long> lengths,
|
||||||
int piece_length, byte[] piece_hashes, long length)
|
int piece_length, byte[] piece_hashes, long length, boolean privateTorrent)
|
||||||
{
|
{
|
||||||
this.announce = announce;
|
this.announce = announce;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -82,6 +83,7 @@ public class MetaInfo
|
|||||||
this.piece_length = piece_length;
|
this.piece_length = piece_length;
|
||||||
this.piece_hashes = piece_hashes;
|
this.piece_hashes = piece_hashes;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
this.privateTorrent = privateTorrent;
|
||||||
|
|
||||||
// TODO if we add a parameter for other keys
|
// TODO if we add a parameter for other keys
|
||||||
//if (other != null) {
|
//if (other != null) {
|
||||||
@ -160,6 +162,10 @@ public class MetaInfo
|
|||||||
else
|
else
|
||||||
name_utf8 = null;
|
name_utf8 = null;
|
||||||
|
|
||||||
|
// BEP 27
|
||||||
|
val = info.get("private");
|
||||||
|
privateTorrent = val != null && val.getString().equals("1");
|
||||||
|
|
||||||
val = info.get("piece length");
|
val = info.get("piece length");
|
||||||
if (val == null)
|
if (val == null)
|
||||||
throw new InvalidBEncodingException("Missing piece length number");
|
throw new InvalidBEncodingException("Missing piece length number");
|
||||||
@ -318,6 +324,14 @@ public class MetaInfo
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is it a private torrent?
|
||||||
|
* @since 0.9
|
||||||
|
*/
|
||||||
|
public boolean isPrivate() {
|
||||||
|
return privateTorrent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of lists of file name hierarchies or null if it is
|
* Returns a list of lists of file name hierarchies or null if it is
|
||||||
* a single name. It has the same size as the list returned by
|
* a single name. It has the same size as the list returned by
|
||||||
@ -439,7 +453,7 @@ public class MetaInfo
|
|||||||
{
|
{
|
||||||
return new MetaInfo(announce, name, name_utf8, files,
|
return new MetaInfo(announce, name, name_utf8, files,
|
||||||
lengths, piece_length,
|
lengths, piece_length,
|
||||||
piece_hashes, length);
|
piece_hashes, length, privateTorrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -475,6 +489,10 @@ public class MetaInfo
|
|||||||
info.put("name", name);
|
info.put("name", name);
|
||||||
if (name_utf8 != null)
|
if (name_utf8 != null)
|
||||||
info.put("name.utf-8", name_utf8);
|
info.put("name.utf-8", name_utf8);
|
||||||
|
// BEP 27
|
||||||
|
if (privateTorrent)
|
||||||
|
info.put("private", "1");
|
||||||
|
|
||||||
info.put("piece length", Integer.valueOf(piece_length));
|
info.put("piece length", Integer.valueOf(piece_length));
|
||||||
info.put("pieces", piece_hashes);
|
info.put("pieces", piece_hashes);
|
||||||
if (files == null)
|
if (files == null)
|
||||||
|
@ -101,7 +101,8 @@ public class Storage
|
|||||||
* @param announce may be null
|
* @param announce may be null
|
||||||
* @param listener may be null
|
* @param listener may be null
|
||||||
*/
|
*/
|
||||||
public Storage(I2PSnarkUtil util, File baseFile, String announce, StorageListener listener)
|
public Storage(I2PSnarkUtil util, File baseFile, String announce,
|
||||||
|
boolean privateTorrent, StorageListener listener)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
_util = util;
|
_util = util;
|
||||||
@ -157,7 +158,7 @@ public class Storage
|
|||||||
|
|
||||||
byte[] piece_hashes = fast_digestCreate();
|
byte[] piece_hashes = fast_digestCreate();
|
||||||
metainfo = new MetaInfo(announce, baseFile.getName(), null, files,
|
metainfo = new MetaInfo(announce, baseFile.getName(), null, files,
|
||||||
lengthsList, piece_size, piece_hashes, total);
|
lengthsList, piece_size, piece_hashes, total, privateTorrent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +668,7 @@ public class I2PSnarkServlet extends Default {
|
|||||||
try {
|
try {
|
||||||
// This may take a long time to check the storage, but since it already exists,
|
// This may take a long time to check the storage, but since it already exists,
|
||||||
// it shouldn't be THAT bad, so keep it in this thread.
|
// it shouldn't be THAT bad, so keep it in this thread.
|
||||||
Storage s = new Storage(_manager.util(), baseFile, announceURL, null);
|
Storage s = new Storage(_manager.util(), baseFile, announceURL, req.getParameter("private") != null, null);
|
||||||
s.close(); // close the files... maybe need a way to pass this Storage to addTorrent rather than starting over
|
s.close(); // close the files... maybe need a way to pass this Storage to addTorrent rather than starting over
|
||||||
MetaInfo info = s.getMetaInfo();
|
MetaInfo info = s.getMetaInfo();
|
||||||
File torrentFile = new File(_manager.getDataDir(), s.getBaseName() + ".torrent");
|
File torrentFile = new File(_manager.getDataDir(), s.getBaseName() + ".torrent");
|
||||||
|
Reference in New Issue
Block a user