forked from I2P_Developers/i2p.i2p
i2psnark: Stub out BEP 52 message numbers
Hide BEP 48 padding directory from UI Check for and reject BEP 52 info multihashes for now Use cached fai.isDirectory for efficiency Use storage.getFileCount() instead of meta.getFiles() to prep for padding files Add notes for padding file TODOs
This commit is contained in:
@ -49,6 +49,9 @@ class Message
|
|||||||
final static byte REJECT = 16; // Fast (BEP 6)
|
final static byte REJECT = 16; // Fast (BEP 6)
|
||||||
final static byte ALLOWED_FAST = 17; // Fast (BEP 6)
|
final static byte ALLOWED_FAST = 17; // Fast (BEP 6)
|
||||||
final static byte EXTENSION = 20; // BEP 10
|
final static byte EXTENSION = 20; // BEP 10
|
||||||
|
final static byte HASH_REQUEST = 21; // BEP 52
|
||||||
|
final static byte HASHES = 22; // BEP 52
|
||||||
|
final static byte HASH_REJECT = 23; // BEP 52
|
||||||
|
|
||||||
// Not all fields are used for every message.
|
// Not all fields are used for every message.
|
||||||
// KEEP_ALIVE doesn't have a real wire representation
|
// KEEP_ALIVE doesn't have a real wire representation
|
||||||
@ -278,6 +281,13 @@ class Message
|
|||||||
return "REJECT(" + piece + ',' + begin + ',' + length + ')';
|
return "REJECT(" + piece + ',' + begin + ',' + length + ')';
|
||||||
case ALLOWED_FAST:
|
case ALLOWED_FAST:
|
||||||
return "ALLOWED_FAST(" + piece + ')';
|
return "ALLOWED_FAST(" + piece + ')';
|
||||||
|
// BEP 52 below here
|
||||||
|
case HASH_REQUEST:
|
||||||
|
return "HASH_REQUEST";
|
||||||
|
case HASHES:
|
||||||
|
return "HASHES";
|
||||||
|
case HASH_REJECT:
|
||||||
|
return "HASH_REJECT";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN (" + type + ')';
|
return "UNKNOWN (" + type + ')';
|
||||||
}
|
}
|
||||||
|
@ -1088,6 +1088,12 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
// b32
|
// b32
|
||||||
newURL = newURL.toUpperCase(Locale.US);
|
newURL = newURL.toUpperCase(Locale.US);
|
||||||
addMagnet(MagnetURI.MAGNET_FULL + newURL, dir);
|
addMagnet(MagnetURI.MAGNET_FULL + newURL, dir);
|
||||||
|
} else if (newURL.length() == 68 && newURL.startsWith("1220") &&
|
||||||
|
newURL.replaceAll("[a-fA-F0-9]", "").length() == 0) {
|
||||||
|
// hex v2 multihash
|
||||||
|
// TODO
|
||||||
|
_manager.addMessage("Version 2 info hashes are not supported");
|
||||||
|
//addMagnet(MagnetURI.MAGNET_FULL_V2 + newURL, dir);
|
||||||
} else {
|
} else {
|
||||||
// try as file path, hopefully we're on the same box
|
// try as file path, hopefully we're on the same box
|
||||||
if (newURL.startsWith("file://"))
|
if (newURL.startsWith("file://"))
|
||||||
@ -3282,6 +3288,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
else
|
else
|
||||||
buf.append(_t("Complete")).append("</b>");
|
buf.append(_t("Complete")).append("</b>");
|
||||||
buf.append("</td><td><span>");
|
buf.append("</td><td><span>");
|
||||||
|
// TODO adjust for padding files
|
||||||
buf.append("<b>")
|
buf.append("<b>")
|
||||||
.append(_t("Size"))
|
.append(_t("Size"))
|
||||||
.append(":</b> ")
|
.append(":</b> ")
|
||||||
@ -3300,6 +3307,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
} else {
|
} else {
|
||||||
buf.append('0');
|
buf.append('0');
|
||||||
}
|
}
|
||||||
|
// TODO adjust for padding files
|
||||||
// not including skipped files, but -1 when not running
|
// not including skipped files, but -1 when not running
|
||||||
long needed = snark.getNeededLength();
|
long needed = snark.getNeededLength();
|
||||||
if (needed < 0) {
|
if (needed < 0) {
|
||||||
@ -3313,6 +3321,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
.append(":</b> ")
|
.append(":</b> ")
|
||||||
.append(formatSize(needed));
|
.append(formatSize(needed));
|
||||||
}
|
}
|
||||||
|
// TODO adjust for padding files
|
||||||
long skipped = snark.getSkippedLength();
|
long skipped = snark.getSkippedLength();
|
||||||
if (skipped > 0) {
|
if (skipped > 0) {
|
||||||
buf.append("</span> <span>");
|
buf.append("</span> <span>");
|
||||||
@ -3321,9 +3330,8 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
.append(":</b> ")
|
.append(":</b> ")
|
||||||
.append(formatSize(skipped));
|
.append(formatSize(skipped));
|
||||||
}
|
}
|
||||||
if (meta != null) {
|
if (storage != null) {
|
||||||
List<List<String>> files = meta.getFiles();
|
int fileCount = storage.getFileCount();
|
||||||
int fileCount = files != null ? files.size() : 1;
|
|
||||||
buf.append("</span> <span>");
|
buf.append("</span> <span>");
|
||||||
buf.append("<b>")
|
buf.append("<b>")
|
||||||
.append(_t("Files"))
|
.append(_t("Files"))
|
||||||
@ -3455,7 +3463,16 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
long[] remainingArray = (arrays != null) ? arrays[0] : null;
|
long[] remainingArray = (arrays != null) ? arrays[0] : null;
|
||||||
long[] previewArray = (arrays != null) ? arrays[1] : null;
|
long[] previewArray = (arrays != null) ? arrays[1] : null;
|
||||||
for (int i = 0; i < ls.length; i++) {
|
for (int i = 0; i < ls.length; i++) {
|
||||||
fileList.add(new Sorters.FileAndIndex(ls[i], storage, remainingArray, previewArray));
|
File f = ls[i];
|
||||||
|
if (isTopLevel) {
|
||||||
|
// Hide (assumed) padding directory if it's in the filesystem.
|
||||||
|
// Storage now will not create padding files, but
|
||||||
|
// may have been created by an old version or other client.
|
||||||
|
String n = f.getName();
|
||||||
|
if ((n.equals(".pad") || n.equals("_pad")) && f.isDirectory())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fileList.add(new Sorters.FileAndIndex(f, storage, remainingArray, previewArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showSort = fileList.size() > 1;
|
boolean showSort = fileList.size() > 1;
|
||||||
@ -3616,7 +3633,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String path = addPaths(decodedBase, item.getName());
|
String path = addPaths(decodedBase, item.getName());
|
||||||
if (item.isDirectory() && !path.endsWith("/"))
|
if (fai.isDirectory && !path.endsWith("/"))
|
||||||
path=addPaths(path,"/");
|
path=addPaths(path,"/");
|
||||||
path = encodePath(path);
|
path = encodePath(path);
|
||||||
String icon = toIcon(item);
|
String icon = toIcon(item);
|
||||||
@ -3676,14 +3693,14 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
if (preview != null)
|
if (preview != null)
|
||||||
buf.append(preview);
|
buf.append(preview);
|
||||||
buf.append("</td><td align=right class=\"snarkFileSize\">");
|
buf.append("</td><td align=right class=\"snarkFileSize\">");
|
||||||
if (!item.isDirectory())
|
if (!fai.isDirectory)
|
||||||
buf.append(formatSize(length));
|
buf.append(formatSize(length));
|
||||||
buf.append("</td><td class=\"snarkFileStatus\">");
|
buf.append("</td><td class=\"snarkFileStatus\">");
|
||||||
buf.append(status);
|
buf.append(status);
|
||||||
buf.append("</td>");
|
buf.append("</td>");
|
||||||
if (showPriority) {
|
if (showPriority) {
|
||||||
buf.append("<td class=\"priority\">");
|
buf.append("<td class=\"priority\">");
|
||||||
if ((!complete) && (!item.isDirectory())) {
|
if ((!complete) && (!fai.isDirectory)) {
|
||||||
if (!inOrder) {
|
if (!inOrder) {
|
||||||
buf.append("<label class=\"priorityHigh\" title=\"").append(_t("Download file at high priority")).append("\">" +
|
buf.append("<label class=\"priorityHigh\" title=\"").append(_t("Download file at high priority")).append("\">" +
|
||||||
"\n<input type=\"radio\" class=\"prihigh\" value=\"5\" name=\"pri.").append(fileIndex).append("\" ");
|
"\n<input type=\"radio\" class=\"prihigh\" value=\"5\" name=\"pri.").append(fileIndex).append("\" ");
|
||||||
|
Reference in New Issue
Block a user