diff --git a/build.xml b/build.xml
index 43601a3..77981d1 100644
--- a/build.xml
+++ b/build.xml
@@ -11,7 +11,7 @@
-
+
diff --git a/src/java/net/i2p/zzzot/Peer.java b/src/java/net/i2p/zzzot/Peer.java
index ae6675a..c865e82 100644
--- a/src/java/net/i2p/zzzot/Peer.java
+++ b/src/java/net/i2p/zzzot/Peer.java
@@ -20,7 +20,10 @@ import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
+import net.i2p.crypto.SHA256Generator;
+import net.i2p.data.Base64;
import net.i2p.data.Destination;
+import net.i2p.data.Hash;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
@@ -70,6 +73,17 @@ public class Peer extends HashMap {
return lastSeen;
}
+ /** convert b64.i2p to a Hash, then to a binary string */
+ /* or should we just store it in the constructor? cache it? */
+ public String getHash() {
+ String ip = (String) get("ip");
+ byte[] b = Base64.decode(ip.substring(0, ip.length() - 4));
+ Hash h = SHA256Generator.getInstance().calculateHash(b);
+ try {
+ return new String(h.getData(), "ISO-8859-1");
+ } catch (UnsupportedEncodingException uee) { return null; }
+ }
+
private static class Cleaner implements SimpleTimer.TimedEvent {
public void timeReached() {
destCache.clear();
diff --git a/src/jsp/announce.jsp b/src/jsp/announce.jsp
index 3054b87..9863557 100644
--- a/src/jsp/announce.jsp
+++ b/src/jsp/announce.jsp
@@ -29,6 +29,7 @@
final int MAX_RESPONSES = 25;
final int INTERVAL = 27*60;
final boolean ALLOW_IP_MISMATCH = false;
+ final boolean ALLOW_COMPACT_RESPONSE = true;
// so the chars will turn into bytes correctly
request.setCharacterEncoding("ISO-8859-1");
@@ -48,6 +49,7 @@
String event = request.getParameter("event");
String ip = request.getParameter("ip");
String numwant = request.getParameter("numwant");
+ boolean compact = ALLOW_COMPACT_RESPONSE && request.getParameter("compact") != null;
// use to enforce destination
String him = request.getHeader("X-I2P-DestB64");
String xff = request.getHeader("X-Forwarded-For");
@@ -138,7 +140,7 @@
// spoof check
// if him == null, we are not using the I2P HTTP server tunnel, or something is wrong
- boolean matchIP = ALLOW_IP_MISMATCH || him == null || ip.equals(him);
+ boolean matchIP = ALLOW_IP_MISMATCH || him == null || ip == null || ip.equals(him);
if (want <= 0 && (!matchIP) && !fail) {
fail = true;
msg = "ip mismatch";
@@ -199,7 +201,14 @@
peerlist.remove(p); // them
if (want < size - 1) {
Collections.shuffle(peerlist);
- m.put("peers", peerlist.subList(0, want));
+ peerlist = peerlist.subList(0, want);
+ }
+ if (compact) {
+ List peerhashes = new ArrayList(peerlist.size());
+ for (Peer pe : peerlist) {
+ peerhashes.add(pe.getHash());
+ }
+ m.put("peers", peerhashes);
} else {
m.put("peers", peerlist);
}