0.4:
compact request/response support - may not be final format Fix NPE if no ip parameter
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
<delete file="plugin/i2ptunnel.config" />
|
||||
<!-- get version number -->
|
||||
<buildnumber file="scripts/build.number" />
|
||||
<property name="release.number" value="0.3" />
|
||||
<property name="release.number" value="0.4" />
|
||||
|
||||
<!-- make the update xpi2p -->
|
||||
<!-- this contains everything except i2ptunnel.config -->
|
||||
|
@ -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<String, Object> {
|
||||
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();
|
||||
|
@ -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<String> peerhashes = new ArrayList(peerlist.size());
|
||||
for (Peer pe : peerlist) {
|
||||
peerhashes.add(pe.getHash());
|
||||
}
|
||||
m.put("peers", peerhashes);
|
||||
} else {
|
||||
m.put("peers", peerlist);
|
||||
}
|
||||
|
Reference in New Issue
Block a user