forked from I2P_Developers/i2p.i2p
* CapacityCalculator: Small adjustment for XOR distance to
break ties and encourage closeness
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
2011-10-29 zzz
|
2011-10-29 zzz
|
||||||
* BuildHandler: Add router.buildHandlerThreads config setting
|
* BuildHandler: Add router.buildHandlerThreads config setting
|
||||||
|
* CapacityCalculator: Small adjustment for XOR distance to
|
||||||
|
break ties and encourage closeness
|
||||||
* ProfileOrganizer: Reduce min expire time
|
* ProfileOrganizer: Reduce min expire time
|
||||||
* SSU: Limit max peers to use as introducers
|
* SSU: Limit max peers to use as introducers
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class CapacityCalculator {
|
|||||||
private static final double BONUS_NEW = 1.25;
|
private static final double BONUS_NEW = 1.25;
|
||||||
private static final double BONUS_ESTABLISHED = 1;
|
private static final double BONUS_ESTABLISHED = 1;
|
||||||
private static final double BONUS_SAME_COUNTRY = .85;
|
private static final double BONUS_SAME_COUNTRY = .85;
|
||||||
|
private static final double BONUS_XOR = .25;
|
||||||
private static final double PENALTY_UNREACHABLE = 2;
|
private static final double PENALTY_UNREACHABLE = 2;
|
||||||
|
|
||||||
public static double calc(PeerProfile profile) {
|
public static double calc(PeerProfile profile) {
|
||||||
@ -69,6 +70,8 @@ class CapacityCalculator {
|
|||||||
// penalize unreachable peers
|
// penalize unreachable peers
|
||||||
if (profile.wasUnreachable())
|
if (profile.wasUnreachable())
|
||||||
capacity -= PENALTY_UNREACHABLE;
|
capacity -= PENALTY_UNREACHABLE;
|
||||||
|
// a tiny tweak to break ties and encourage closeness, -.25 to +.25
|
||||||
|
capacity -= profile.getXORDistance() * (BONUS_XOR / 128);
|
||||||
|
|
||||||
capacity += profile.getCapacityBonus();
|
capacity += profile.getCapacityBonus();
|
||||||
if (capacity < 0)
|
if (capacity < 0)
|
||||||
|
@ -58,6 +58,7 @@ public class PeerProfile {
|
|||||||
private boolean _expanded;
|
private boolean _expanded;
|
||||||
private boolean _expandedDB;
|
private boolean _expandedDB;
|
||||||
private int _consecutiveShitlists;
|
private int _consecutiveShitlists;
|
||||||
|
private final int _distance;
|
||||||
|
|
||||||
public PeerProfile(RouterContext context, Hash peer) {
|
public PeerProfile(RouterContext context, Hash peer) {
|
||||||
this(context, peer, true);
|
this(context, peer, true);
|
||||||
@ -74,6 +75,11 @@ public class PeerProfile {
|
|||||||
// if it is false, so all need to be fixed before we can have non-expanded profiles
|
// if it is false, so all need to be fixed before we can have non-expanded profiles
|
||||||
if (expand)
|
if (expand)
|
||||||
expandProfile();
|
expandProfile();
|
||||||
|
Hash us = _context.routerHash();
|
||||||
|
if (us != null)
|
||||||
|
_distance = ((_peer.getData()[0] & 0xff) ^ (us.getData()[0] & 0xff)) - 127;
|
||||||
|
else
|
||||||
|
_distance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** what peer is being profiled */
|
/** what peer is being profiled */
|
||||||
@ -115,6 +121,15 @@ public class PeerProfile {
|
|||||||
return us != null && us.equals(_context.commSystem().getCountry(_peer));
|
return us != null && us.equals(_context.commSystem().getCountry(_peer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For now, just a one-byte comparison
|
||||||
|
* @return -127 to +128, lower is closer
|
||||||
|
* @since 0.8.11
|
||||||
|
*/
|
||||||
|
public int getXORDistance() {
|
||||||
|
return _distance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this peer active at the moment (sending/receiving messages within the
|
* Is this peer active at the moment (sending/receiving messages within the
|
||||||
* given period?)
|
* given period?)
|
||||||
|
Reference in New Issue
Block a user