i2psnark: Add max files per torrent config

No UI, must edit config file and restart.
ref: http://zzz.i2p/topics/3549

Contains code adapted from I2P+. License:
Permission is granted to upstream to incorporate I2P+ modifications under the license
of the applicable upstream subsystem as specified in LICENSE.txt.
This commit is contained in:
zzz
2023-01-22 10:30:58 -05:00
parent be5a10194a
commit 9963503ebf
3 changed files with 22 additions and 8 deletions

View File

@ -77,6 +77,7 @@ public class I2PSnarkUtil implements DisconnectListener {
private DHT _dht;
private long _startedTime;
private final DisconnectListener _discon;
private int _maxFilesPerTorrent = SnarkManager.DEFAULT_MAX_FILES_PER_TORRENT;
private static final int EEPGET_CONNECT_TIMEOUT = 45*1000;
private static final int EEPGET_CONNECT_TIMEOUT_SHORT = 5*1000;
@ -242,6 +243,11 @@ public class I2PSnarkUtil implements DisconnectListener {
/** @since 0.9.1 */
public File getTempDir() { return _tmpDir; }
/** @since 0.9.58 */
public int getMaxFilesPerTorrent() { return _maxFilesPerTorrent; }
/** @since 0.9.58 */
public void setMaxFilesPerTorrent(int max) { _maxFilesPerTorrent = Math.max(max, 1); }
/**
* Connect to the router, if we aren't already
*/

View File

@ -129,7 +129,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
private static final String PROP_META_ACTIVITY = "activity";
private static final String CONFIG_FILE_SUFFIX = ".config";
private static final String CONFIG_FILE = "i2psnark" + CONFIG_FILE_SUFFIX;
public static final String CONFIG_FILE = "i2psnark" + CONFIG_FILE_SUFFIX;
private static final String COMMENT_FILE_SUFFIX = ".comments.txt.gz";
public static final String PROP_FILES_PUBLIC = "i2psnark.filesPublic";
public static final String PROP_OLD_AUTO_START = "i2snark.autoStart"; // oops
@ -164,6 +164,8 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
private static final String PROP_COMMENTS = "i2psnark.comments";
/** @since 0.9.31 */
private static final String PROP_COMMENTS_NAME = "i2psnark.commentsName";
/** @since 0.9.58 */
public static final String PROP_MAX_FILES_PER_TORRENT = "i2psnark.maxFilesPerTorrent";
public static final int MIN_UP_BW = 10;
public static final int DEFAULT_MAX_UP_BW = 25;
@ -171,6 +173,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
public static final int DEFAULT_REFRESH_DELAY_SECS = 15;
private static final int DEFAULT_PAGE_SIZE = 50;
public static final int DEFAULT_TUNNEL_QUANTITY = 3;
public static final int DEFAULT_MAX_FILES_PER_TORRENT = 2000;
public static final String CONFIG_DIR_SUFFIX = ".d";
private static final String SUBDIR_PREFIX = "s";
private static final String B64 = Base64.ALPHABET_I2P;
@ -1000,6 +1003,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
// _util.setProxy(eepHost, eepPort);
_util.setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
_util.setMaxFilesPerTorrent(getInt(PROP_MAX_FILES_PER_TORRENT, DEFAULT_MAX_FILES_PER_TORRENT));
_util.setStartupDelay(getInt(PROP_STARTUP_DELAY, DEFAULT_STARTUP_DELAY));
_util.setFilesPublic(areFilesPublic());
_util.setOpenTrackers(getListConfig(PROP_OPENTRACKERS, DEFAULT_OPENTRACKERS));
@ -1479,9 +1483,6 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
}
}
/** hardcoded for sanity. perhaps this should be customizable, for people who increase their ulimit, etc. */
public static final int MAX_FILES_PER_TORRENT = 2000;
/**
* Set of canonical .torrent filenames that we are dealing with.
* An unsynchronized copy.
@ -2450,8 +2451,11 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
*/
private String validateTorrent(MetaInfo info) {
List<List<String>> files = info.getFiles();
if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) {
return _t("Too many files in \"{0}\" ({1})!", info.getName(), files.size());
if (files != null && files.size() > _util.getMaxFilesPerTorrent()) {
return _t("Too many files in \"{0}\" ({1})!", info.getName(), files.size()) +
" - limit is " + _util.getMaxFilesPerTorrent() + ", zip them or set " +
PROP_MAX_FILES_PER_TORRENT + '=' + files.size() + " in " +
_configFile.getAbsolutePath() + " and restart";
} else if ( (files == null) && (info.getName().endsWith(".torrent")) ) {
return _t("Torrent file \"{0}\" cannot end in \".torrent\"!", info.getName());
} else if (info.getPieces() <= 0) {

View File

@ -288,9 +288,13 @@ public class Storage implements Closeable
* @throws IOException if too many total files
*/
private void addFiles(List<File> l, File f) throws IOException {
int max = _util.getMaxFilesPerTorrent();
if (!f.isDirectory()) {
if (l.size() >= SnarkManager.MAX_FILES_PER_TORRENT)
throw new IOException("Too many files, limit is " + SnarkManager.MAX_FILES_PER_TORRENT + ", zip them?");
if (l.size() >= max)
throw new IOException(_util.getString("Too many files in \"{0}\" ({1})!", metainfo.getName(), l.size()) +
" - limit is " + max + ", zip them or set " +
SnarkManager.PROP_MAX_FILES_PER_TORRENT + '=' + l.size() + " in " +
SnarkManager.CONFIG_FILE + " and restart");
l.add(f);
} else {
File[] files = f.listFiles();