diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerMonitorTask.java b/apps/i2psnark/java/src/org/klomp/snark/PeerMonitorTask.java index 229391cd71f804c394ac3047515f9428c72c2db6..3ee8932f61f1653d5ba9dc3143fdd5c833001ee7 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerMonitorTask.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerMonitorTask.java @@ -23,6 +23,8 @@ package org.klomp.snark; import java.util.Iterator; import java.util.TimerTask; +import net.i2p.data.DataHelper; + /** * TimerTask that monitors the peers and total up/download speeds. * Works together with the main Snark class to report periodical statistics. @@ -83,21 +85,12 @@ class PeerMonitorTask extends TimerTask // Print some statistics long downloaded = coordinator.getDownloaded(); - String totalDown; - if (downloaded >= 10 * 1024 * 1024) - totalDown = (downloaded / (1024 * 1024)) + "MB"; - else - totalDown = (downloaded / 1024 )+ "KB"; + String totalDown = DataHelper.formatSize(downloaded) + "B"; long uploaded = coordinator.getUploaded(); - String totalUp; - if (uploaded >= 10 * 1024 * 1024) - totalUp = (uploaded / (1024 * 1024)) + "MB"; - else - totalUp = (uploaded / 1024) + "KB"; + String totalUp = DataHelper.formatSize(uploaded) + "B"; int needP = coordinator.storage.needed(); - long needMB - = needP * coordinator.metainfo.getPieceLength(0) / (1024 * 1024); + long needMB = needP * coordinator.metainfo.getPieceLength(0) / (1024 * 1024); int totalP = coordinator.metainfo.getPieces(); long totalMB = coordinator.metainfo.getTotalLength() / (1024 * 1024); diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerState.java b/apps/i2psnark/java/src/org/klomp/snark/PeerState.java index 054b58262b3ed013db52214738a6f76766cad0e5..378cd8758c94dbed20080b2fc6e2fd40c1ffe4b0 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerState.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerState.java @@ -60,9 +60,9 @@ class PeerState // If we have te resend outstanding requests (true after we got choked). private boolean resend = false; - private final static int MAX_PIPELINE = 3; // this is for outbound requests + private final static int MAX_PIPELINE = 5; // this is for outbound requests private final static int MAX_PIPELINE_BYTES = 128*1024; // this is for inbound requests - public final static int PARTSIZE = 32*1024; // Snark was 16K, i2p-bt uses 64KB + public final static int PARTSIZE = 16*1024; // outbound request private final static int MAX_PARTSIZE = 64*1024; // Don't let anybody request more than this PeerState(Peer peer, PeerListener listener, MetaInfo metainfo, diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index 60c44f3d5976fa2a9fa9d805757d8e2e42261be6..a96793a35fe08a1efdc336182af2427b2a9a9142 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -362,7 +362,7 @@ public class SnarkManager implements Snark.CompleteListener { public Properties getConfig() { return _config; } /** hardcoded for sanity. perhaps this should be customizable, for people who increase their ulimit, etc. */ - private static final int MAX_FILES_PER_TORRENT = 256; + private static final int MAX_FILES_PER_TORRENT = 512; /** set of filenames that we are dealing with */ public Set listTorrentFiles() { synchronized (_snarks) { return new HashSet(_snarks.keySet()); } } @@ -543,16 +543,18 @@ public class SnarkManager implements Snark.CompleteListener { return "Too many files in " + info.getName() + " (" + files.size() + "), deleting it"; } else if (info.getPieces() <= 0) { return "No pieces in " + info.getName() + "? deleting it"; - } else if (info.getPieceLength(0) > 1*1024*1024) { - return "Pieces are too large in " + info.getName() + " (" + info.getPieceLength(0)/1024 + "KB), deleting it"; - } else if (info.getTotalLength() > 10*1024*1024*1024l) { + } else if (info.getPieceLength(0) > Storage.MAX_PIECE_SIZE) { + return "Pieces are too large in " + info.getName() + " (" + DataHelper.formatSize(info.getPieceLength(0)) + + "B), deleting it"; + } else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) { System.out.println("torrent info: " + info.toString()); List lengths = info.getLengths(); if (lengths != null) for (int i = 0; i < lengths.size(); i++) System.out.println("File " + i + " is " + lengths.get(i) + " long"); - return "Torrents larger than 10GB are not supported yet (because we're paranoid): " + info.getName() + ", deleting it"; + return "Torrents larger than " + DataHelper.formatSize(Storage.MAX_TOTAL_SIZE) + + "B are not supported yet (because we're paranoid): " + info.getName() + ", deleting it"; } else { // ok return null; @@ -637,8 +639,7 @@ public class SnarkManager implements Snark.CompleteListener { public void torrentComplete(Snark snark) { File f = new File(snark.torrent); long len = snark.meta.getTotalLength(); - addMessage("Download complete of " + f.getName() - + (len < 5*1024*1024 ? " (size: " + (len/1024) + "KB)" : " (size: " + (len/(1024*1024l)) + "MB)")); + addMessage("Download complete of " + f.getName() + " (size: " + DataHelper.formatSize(len) + "B)"); updateStatus(snark); } diff --git a/apps/i2psnark/java/src/org/klomp/snark/Storage.java b/apps/i2psnark/java/src/org/klomp/snark/Storage.java index 69e5a198f56a5117b800c44200554b9937f60811..51b4f97ebb67776c353070279af35ab057418368 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Storage.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Storage.java @@ -56,10 +56,11 @@ public class Storage boolean changed; /** The default piece size. */ - private static int MIN_PIECE_SIZE = 256*1024; - private static int MAX_PIECE_SIZE = 1024*1024; + private static final int MIN_PIECE_SIZE = 256*1024; + public static final int MAX_PIECE_SIZE = 1024*1024; /** The maximum number of pieces in a torrent. */ - private static long MAX_PIECES = 100*1024/20; + public static final int MAX_PIECES = 10*1024; + public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES; /** * Creates a new storage based on the supplied MetaInfo. This will