* i2psnark:

- More listing fixes
      - Revert choker change
      thx 'backup' !
This commit is contained in:
zzz
2010-06-01 13:56:53 +00:00
parent 05d45fe945
commit 13b54b864e
4 changed files with 58 additions and 27 deletions

View File

@ -118,7 +118,7 @@ class PeerCheckerTask extends TimerTask
// Choke a percentage of them rather than all so it isn't so drastic...
// unless this torrent is over the limit all by itself.
boolean overBWLimitChoke = upload > 0 &&
((overBWLimit && random.nextInt(5) < 2) ||
((overBWLimit && random.nextBoolean()) ||
(coordinator.overUpBWLimit(uploaded)));
// If we are at our max uploaders and we have lots of other

View File

@ -29,7 +29,7 @@ public class SnarkManager implements Snark.CompleteListener {
private static SnarkManager _instance = new SnarkManager();
public static SnarkManager instance() { return _instance; }
/** map of (canonical) filename to Snark instance (unsynchronized) */
/** map of (canonical) filename of the .torrent file to Snark instance (unsynchronized) */
private final Map<String, Snark> _snarks;
private final Object _addSnarkLock;
private /* FIXME final FIXME */ File _configFile;
@ -396,12 +396,30 @@ public class SnarkManager implements Snark.CompleteListener {
/** hardcoded for sanity. perhaps this should be customizable, for people who increase their ulimit, etc. */
private static final int MAX_FILES_PER_TORRENT = 512;
/** set of filenames that we are dealing with */
/** set of canonical .torrent filenames that we are dealing with */
public Set<String> listTorrentFiles() { synchronized (_snarks) { return new HashSet(_snarks.keySet()); } }
/**
* Grab the torrent given the (canonical) filename
* Grab the torrent given the (canonical) filename of the .torrent file
* @return Snark or null
*/
public Snark getTorrent(String filename) { synchronized (_snarks) { return (Snark)_snarks.get(filename); } }
/**
* Grab the torrent given the base name of the storage
* @return Snark or null
* @since 0.7.14
*/
public Snark getTorrentByBaseName(String filename) {
synchronized (_snarks) {
for (Snark s : _snarks.values()) {
if (s.storage.getBaseName().equals(filename))
return s;
}
}
return null;
}
public void addTorrent(String filename) { addTorrent(filename, false); }
public void addTorrent(String filename, boolean dontAutoStart) {
if ((!dontAutoStart) && !_util.connected()) {
@ -595,8 +613,8 @@ public class SnarkManager implements Snark.CompleteListener {
} else if (info.getPieces() > Storage.MAX_PIECES) {
return _("Too many pieces in \"{0}\", limit is {1}, deleting it!", info.getName(), Storage.MAX_PIECES);
} else if (info.getPieceLength(0) > Storage.MAX_PIECE_SIZE) {
return _("Pieces are too large in \"{0}\" ({1}B), deleting it.", info.getName(), DataHelper.formatSize(info.getPieceLength(0))) + ' ' +
_("Limit is {0}B", DataHelper.formatSize(Storage.MAX_PIECE_SIZE));
return _("Pieces are too large in \"{0}\" ({1}B), deleting it.", info.getName(), DataHelper.formatSize2(info.getPieceLength(0))) + ' ' +
_("Limit is {0}B", DataHelper.formatSize2(Storage.MAX_PIECE_SIZE));
} else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) {
System.out.println("torrent info: " + info.toString());
List lengths = info.getLengths();
@ -689,7 +707,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 finished: \"{0}\"", f.getName()) + " (" + _("size: {0}B", DataHelper.formatSize(len)) + ')');
addMessage(_("Download finished: \"{0}\"", f.getName()) + " (" + _("size: {0}B", DataHelper.formatSize2(len)) + ')');
updateStatus(snark);
}

View File

@ -315,12 +315,12 @@ public class Storage
if (!bitfield.get(pc))
rv = Math.min(psz - (start % psz), lengths[i]);
int pieces = metainfo.getPieces();
for (int j = pc + 1; j * psz < end && j < pieces; j++) {
for (int j = pc + 1; (((long)j) * psz) < end && j < pieces; j++) {
if (!bitfield.get(j)) {
if ((j+1)*psz < end)
if (((long)(j+1))*psz < end)
rv += psz;
else
rv += end - (j * psz);
rv += end - (((long)j) * psz);
}
}
return rv;
@ -339,6 +339,18 @@ public class Storage
return bitfield;
}
/**
* The base file or directory name of the data,
* as specified in the .torrent file, but filtered to remove
* illegal characters. This is where the data actually is,
* relative to the snark base dir.
*
* @since 0.7.14
*/
public String getBaseName() {
return filterName(metainfo.getName());
}
/**
* Creates (and/or checks) all files from the metainfo file list.
*/

View File

@ -547,9 +547,11 @@ public class I2PSnarkServlet extends Default {
l = l.substring(skip.length());
if (r.startsWith(skip))
r = r.substring(skip.length());
if (l.toLowerCase().startsWith("the "))
String llc = l.toLowerCase();
if (llc.startsWith("the ") || llc.startsWith("the."))
l = l.substring(4);
if (r.toLowerCase().startsWith("the "))
String rlc = r.toLowerCase();
if (rlc.startsWith("the ") || rlc.startsWith("the."))
r = r.substring(4);
return collator.compare(l, r);
}
@ -681,7 +683,7 @@ public class I2PSnarkServlet extends Default {
out.write("<td align=\"left\" class=\"snarkTorrentName " + rowClass + "\">");
if (remaining == 0 || snark.meta.getFiles() != null) {
out.write("<a href=\"" + snark.meta.getName());
out.write("<a href=\"" + snark.storage.getBaseName());
if (snark.meta.getFiles() != null)
out.write("/");
out.write("\" title=\"");
@ -1091,6 +1093,9 @@ public class I2PSnarkServlet extends Default {
/** dummies for translation */
private static final String HOPS = ngettext("1 hop", "{0} hops");
private static final String TUNNELS = ngettext("1 tunnel", "{0} tunnels");
/** prevents the ngettext line below from getting tagged */
private static final String DUMMY0 = "{0} ";
private static final String DUMMY1 = "1 ";
/** modded from ConfigTunnelsHelper @since 0.7.14 */
private String renderOptions(int min, int max, String strNow, String selName, String name) {
@ -1104,7 +1109,8 @@ public class I2PSnarkServlet extends Default {
buf.append("<option value=\"").append(i).append("\" ");
if (i == now)
buf.append("selected=\"true\" ");
buf.append(">").append(ngettext("1 " + name, "{0} " + name + 's', i));
// constants to prevent tagging
buf.append(">").append(ngettext(DUMMY1 + name, DUMMY0 + name + 's', i));
buf.append("</option>\n");
}
buf.append("</select>\n");
@ -1208,18 +1214,13 @@ public class I2PSnarkServlet extends Default {
title = title.substring("/i2psnark/".length());
// Get the snark associated with this directory
Snark snark = null;
try {
String torrentName;
int slash = title.indexOf('/');
if (slash > 0)
torrentName = title.substring(0, slash) + ".torrent";
else
torrentName = title + ".torrent";
File dataDir = _manager.getDataDir();
String torrentAbsPath = (new File(dataDir, torrentName)).getCanonicalPath();
snark = _manager.getTorrent(torrentAbsPath);
} catch (IOException ioe) {}
String torrentName;
int slash = title.indexOf('/');
if (slash > 0)
torrentName = title.substring(0, slash);
else
torrentName = title;
Snark snark = _manager.getTorrentByBaseName(torrentName);
if (title.endsWith("/"))
title = title.substring(0, title.length() - 1);
title = _("Torrent") + ": " + title;
@ -1371,7 +1372,7 @@ public class I2PSnarkServlet extends Default {
plc.endsWith(".ape"))
icon = "music";
else if (mime.startsWith("video/") || plc.endsWith(".mkv") || plc.endsWith(".m4v") ||
plc.endsWith(".mp4"))
plc.endsWith(".mp4") || plc.endsWith(".wmv"))
icon = "film";
else if (mime.equals("application/zip") || mime.equals("application/x-gtar") ||
mime.equals("application/compress") || mime.equals("application/gzip") ||