forked from I2P_Developers/i2p.i2p
NetDb: Add same-port check in peer selector
Convert FloodfillPeerSelector MaskedIPSet to use the one now in util
This commit is contained in:
19
history.txt
19
history.txt
@@ -1,4 +1,23 @@
|
||||
2016-11-27 zzz
|
||||
* NetDb: Add same-port check in peer selector
|
||||
|
||||
2016-11-26 zzz
|
||||
* NetDb:
|
||||
- Add advanced lookup form
|
||||
- Add port and sig type lookups
|
||||
- Fix /16 and /8 lookup
|
||||
- Fix tab highlighted for all lookups
|
||||
- Add sybil points for banlist
|
||||
|
||||
2016-11-25 zzz
|
||||
* SU3File: Add types for blocklist (proposal #130)
|
||||
|
||||
2016-11-24 zzz
|
||||
* Sybil tool enhancements
|
||||
* Blocklist feed tweaks
|
||||
|
||||
2016-11-23 zzz
|
||||
* Console: Support RI lookup by caps or IP
|
||||
* NetDB: Penalize new and slow peers
|
||||
* News: Add command line utility support
|
||||
* Router: Support blocklist in the news feed (proposal #129)
|
||||
|
@@ -18,10 +18,10 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 11;
|
||||
public final static long BUILD = 12;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
public final static String EXTRA = "-rc";
|
||||
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
|
||||
public static void main(String args[]) {
|
||||
System.out.println("I2P Router version: " + FULL_VERSION);
|
||||
|
@@ -25,6 +25,7 @@ import net.i2p.kademlia.SelectionCollector;
|
||||
import net.i2p.kademlia.XORComparator;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.peermanager.PeerProfile;
|
||||
import net.i2p.router.util.MaskedIPSet;
|
||||
import net.i2p.router.util.RandomIterator;
|
||||
import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateStat;
|
||||
@@ -226,7 +227,7 @@ class FloodfillPeerSelector extends PeerSelector {
|
||||
// 5 == FNDF.MAX_TO_FLOOD + 1
|
||||
int limit = Math.max(5, howMany);
|
||||
limit = Math.min(limit, ffs.size());
|
||||
Set<Integer> maskedIPs = new HashSet<Integer>(limit + 4);
|
||||
MaskedIPSet maskedIPs = new MaskedIPSet(limit * 3);
|
||||
// split sorted list into 3 sorted lists
|
||||
for (int i = 0; found < howMany && i < limit; i++) {
|
||||
Hash entry = sorted.first();
|
||||
@@ -235,16 +236,16 @@ class FloodfillPeerSelector extends PeerSelector {
|
||||
sorted.remove(entry);
|
||||
// put anybody in the same /16 at the end
|
||||
RouterInfo info = _context.netDb().lookupRouterInfoLocally(entry);
|
||||
Set<Integer> entryIPs = maskedIPSet(entry, info, 2);
|
||||
MaskedIPSet entryIPs = new MaskedIPSet(_context, entry, info, 2);
|
||||
boolean sameIP = false;
|
||||
for (Integer ip : entryIPs) {
|
||||
for (String ip : entryIPs) {
|
||||
if (!maskedIPs.add(ip))
|
||||
sameIP = true;
|
||||
}
|
||||
if (sameIP) {
|
||||
badff.add(entry);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Same /16: " + entry);
|
||||
_log.debug("Same /16, family, or port: " + entry);
|
||||
} else if (info != null && now - info.getPublished() > 3*60*60*1000) {
|
||||
badff.add(entry);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@@ -324,52 +325,6 @@ class FloodfillPeerSelector extends PeerSelector {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Set of IPs for this peer, with a given mask.
|
||||
* Includes the comm system's record of the IP, and all netDb addresses.
|
||||
*
|
||||
* @param pinfo may be null
|
||||
* @return an opaque set of masked IPs for this peer
|
||||
* @since 0.9.5 modified from ProfileOrganizer
|
||||
*/
|
||||
private Set<Integer> maskedIPSet(Hash peer, RouterInfo pinfo, int mask) {
|
||||
Set<Integer> rv = new HashSet<Integer>(4);
|
||||
byte[] commIP = _context.commSystem().getIP(peer);
|
||||
if (commIP != null)
|
||||
rv.add(maskedIP(commIP, mask));
|
||||
if (pinfo == null)
|
||||
return rv;
|
||||
Collection<RouterAddress> paddr = pinfo.getAddresses();
|
||||
for (RouterAddress pa : paddr) {
|
||||
byte[] pib = pa.getIP();
|
||||
if (pib == null) continue;
|
||||
rv.add(maskedIP(pib, mask));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate an arbitrary unique value for this ip/mask (mask = 1-4)
|
||||
* If IPv6, force mask = 8.
|
||||
* @since 0.9.5 copied from ProfileOrganizer
|
||||
*/
|
||||
private static Integer maskedIP(byte[] ip, int mask) {
|
||||
int rv = ip[0];
|
||||
if (ip.length == 16) {
|
||||
for (int i = 1; i < 8; i++) {
|
||||
rv <<= i * 4;
|
||||
rv ^= ip[i];
|
||||
}
|
||||
} else {
|
||||
for (int i = 1; i < mask; i++) {
|
||||
rv <<= 8;
|
||||
rv ^= ip[i];
|
||||
}
|
||||
}
|
||||
return Integer.valueOf(rv);
|
||||
}
|
||||
|
||||
private class FloodfillSelectionCollector implements SelectionCollector<Hash> {
|
||||
private final TreeSet<Hash> _sorted;
|
||||
private final List<Hash> _floodfillMatches;
|
||||
|
@@ -37,7 +37,7 @@ public class MaskedIPSet extends HashSet<String> {
|
||||
* @return an opaque set of masked IPs for this peer
|
||||
*/
|
||||
public MaskedIPSet(RouterContext ctx, Hash peer, int mask) {
|
||||
this(ctx, ctx.netDb().lookupRouterInfoLocally(peer), mask);
|
||||
this(ctx, peer, ctx.netDb().lookupRouterInfoLocally(peer), mask);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +51,24 @@ public class MaskedIPSet extends HashSet<String> {
|
||||
* @return an opaque set of masked IPs for this peer
|
||||
*/
|
||||
public MaskedIPSet(RouterContext ctx, RouterInfo pinfo, int mask) {
|
||||
this(ctx, pinfo != null ? pinfo.getHash() : null, pinfo, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Set of IPs for this peer, with a given mask.
|
||||
* Includes the comm system's record of the IP, and all netDb addresses.
|
||||
*
|
||||
* As of 0.9.24, returned set will include netdb family as well.
|
||||
*
|
||||
* @param pinfo may be null
|
||||
* @param mask is 1-4 (number of bytes to match)
|
||||
* @return an opaque set of masked IPs for this peer
|
||||
*/
|
||||
public MaskedIPSet(RouterContext ctx, Hash peer, RouterInfo pinfo, int mask) {
|
||||
super(4);
|
||||
if (pinfo == null)
|
||||
return;
|
||||
byte[] commIP = ctx.commSystem().getIP(pinfo.getHash());
|
||||
byte[] commIP = ctx.commSystem().getIP(peer);
|
||||
if (commIP != null)
|
||||
add(maskedIP(commIP, mask));
|
||||
Collection<RouterAddress> paddr = pinfo.getAddresses();
|
||||
@@ -62,6 +76,11 @@ public class MaskedIPSet extends HashSet<String> {
|
||||
byte[] pib = pa.getIP();
|
||||
if (pib == null) continue;
|
||||
add(maskedIP(pib, mask));
|
||||
// Routers with a common port may be run
|
||||
// by a single entity with a common configuration
|
||||
int port = pa.getPort();
|
||||
if (port > 0)
|
||||
add("p" + port);
|
||||
}
|
||||
String family = pinfo.getOption("family");
|
||||
if (family != null) {
|
||||
|
Reference in New Issue
Block a user