Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
6e3b85ac97 | |||
48687daccc |
@@ -11,7 +11,7 @@
|
|||||||
<delete file="plugin/i2ptunnel.config" />
|
<delete file="plugin/i2ptunnel.config" />
|
||||||
<!-- get version number -->
|
<!-- get version number -->
|
||||||
<buildnumber file="scripts/build.number" />
|
<buildnumber file="scripts/build.number" />
|
||||||
<property name="release.number" value="0.3" />
|
<property name="release.number" value="0.5" />
|
||||||
|
|
||||||
<!-- make the update xpi2p -->
|
<!-- make the update xpi2p -->
|
||||||
<!-- this contains everything except i2ptunnel.config -->
|
<!-- this contains everything except i2ptunnel.config -->
|
||||||
|
@@ -20,7 +20,10 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import net.i2p.crypto.SHA256Generator;
|
||||||
|
import net.i2p.data.Base64;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
|
|
||||||
@@ -70,6 +73,17 @@ public class Peer extends HashMap<String, Object> {
|
|||||||
return lastSeen;
|
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 {
|
private static class Cleaner implements SimpleTimer.TimedEvent {
|
||||||
public void timeReached() {
|
public void timeReached() {
|
||||||
destCache.clear();
|
destCache.clear();
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
final int MAX_RESPONSES = 25;
|
final int MAX_RESPONSES = 25;
|
||||||
final int INTERVAL = 27*60;
|
final int INTERVAL = 27*60;
|
||||||
final boolean ALLOW_IP_MISMATCH = false;
|
final boolean ALLOW_IP_MISMATCH = false;
|
||||||
|
final boolean ALLOW_COMPACT_RESPONSE = true;
|
||||||
|
|
||||||
// so the chars will turn into bytes correctly
|
// so the chars will turn into bytes correctly
|
||||||
request.setCharacterEncoding("ISO-8859-1");
|
request.setCharacterEncoding("ISO-8859-1");
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
String event = request.getParameter("event");
|
String event = request.getParameter("event");
|
||||||
String ip = request.getParameter("ip");
|
String ip = request.getParameter("ip");
|
||||||
String numwant = request.getParameter("numwant");
|
String numwant = request.getParameter("numwant");
|
||||||
|
boolean compact = ALLOW_COMPACT_RESPONSE && request.getParameter("compact") != null;
|
||||||
// use to enforce destination
|
// use to enforce destination
|
||||||
String him = request.getHeader("X-I2P-DestB64");
|
String him = request.getHeader("X-I2P-DestB64");
|
||||||
String xff = request.getHeader("X-Forwarded-For");
|
String xff = request.getHeader("X-Forwarded-For");
|
||||||
@@ -138,7 +140,7 @@
|
|||||||
|
|
||||||
// spoof check
|
// spoof check
|
||||||
// if him == null, we are not using the I2P HTTP server tunnel, or something is wrong
|
// 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) {
|
if (want <= 0 && (!matchIP) && !fail) {
|
||||||
fail = true;
|
fail = true;
|
||||||
msg = "ip mismatch";
|
msg = "ip mismatch";
|
||||||
@@ -199,7 +201,19 @@
|
|||||||
peerlist.remove(p); // them
|
peerlist.remove(p); // them
|
||||||
if (want < size - 1) {
|
if (want < size - 1) {
|
||||||
Collections.shuffle(peerlist);
|
Collections.shuffle(peerlist);
|
||||||
m.put("peers", peerlist.subList(0, want));
|
peerlist = peerlist.subList(0, want);
|
||||||
|
}
|
||||||
|
if (compact) {
|
||||||
|
// old experimental way - list of hashes
|
||||||
|
//List<String> peerhashes = new ArrayList(peerlist.size());
|
||||||
|
//for (Peer pe : peerlist) {
|
||||||
|
// peerhashes.add(pe.getHash());
|
||||||
|
//}
|
||||||
|
// new way - one big string
|
||||||
|
byte[] peerhashes = new byte[32 * peerlist.size()];
|
||||||
|
for (int i = 0; i < peerlist.size(); i++)
|
||||||
|
System.arraycopy(peerlist.get(i).getHash().getBytes("ISO-8859-1"), 0, peerhashes, i * 32, 32);
|
||||||
|
m.put("peers", peerhashes);
|
||||||
} else {
|
} else {
|
||||||
m.put("peers", peerlist);
|
m.put("peers", peerlist);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user