forked from I2P_Developers/i2p.i2p
Profiles: Remove the long-unused failing peers map, deprecate all related methods
This commit is contained in:
@ -368,8 +368,9 @@ public class PeerProfile {
|
||||
public float getIntegrationValue() { return _integrationValue; }
|
||||
/**
|
||||
* is this peer actively failing (aka not worth touching)?
|
||||
* deprecated - unused - always false
|
||||
* @deprecated - unused - always false
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getIsFailing() { return false; }
|
||||
|
||||
/**
|
||||
@ -670,9 +671,13 @@ public class PeerProfile {
|
||||
private float calculateSpeed() { return (float) SpeedCalculator.calc(this); }
|
||||
private float calculateCapacity() { return (float) CapacityCalculator.calc(this); }
|
||||
private float calculateIntegration() { return (float) IntegrationCalculator.calc(this); }
|
||||
/** deprecated - unused - always false */
|
||||
|
||||
/**
|
||||
* @deprecated - unused - always false
|
||||
*/
|
||||
@Deprecated
|
||||
void setIsFailing(boolean val) {}
|
||||
|
||||
|
||||
/**
|
||||
* Helper for calculators
|
||||
* @since 0.9.2
|
||||
|
@ -53,8 +53,6 @@ public class ProfileOrganizer {
|
||||
private final Map<Hash, PeerProfile> _notFailingPeers;
|
||||
/** H(routerIdnetity), containing elements in _notFailingPeers */
|
||||
private final List<Hash> _notFailingPeersList;
|
||||
/** TO BE REMOVED H(routerIdentity) to PeerProfile for all peers that ARE failing horribly (but that we haven't dropped reference to yet) */
|
||||
private final Map<Hash, PeerProfile> _failingPeers;
|
||||
/** who are we? */
|
||||
private Hash _us;
|
||||
private final ProfilePersistenceHelper _persistenceHelper;
|
||||
@ -94,7 +92,7 @@ public class ProfileOrganizer {
|
||||
|
||||
/** synchronized against this lock when updating the tier that peers are located in (and when fetching them from a peer) */
|
||||
private final ReentrantReadWriteLock _reorganizeLock = new ReentrantReadWriteLock(false);
|
||||
|
||||
|
||||
public ProfileOrganizer(RouterContext context) {
|
||||
_context = context;
|
||||
_log = context.logManager().getLog(ProfileOrganizer.class);
|
||||
@ -104,7 +102,6 @@ public class ProfileOrganizer {
|
||||
_wellIntegratedPeers = new HashMap<Hash, PeerProfile>(128);
|
||||
_notFailingPeers = new HashMap<Hash, PeerProfile>(256);
|
||||
_notFailingPeersList = new ArrayList<Hash>(256);
|
||||
_failingPeers = new HashMap<Hash, PeerProfile>(16);
|
||||
_strictCapacityOrder = new TreeSet<PeerProfile>(_comp);
|
||||
_persistenceHelper = new ProfilePersistenceHelper(_context);
|
||||
|
||||
@ -299,7 +296,8 @@ public class ProfileOrganizer {
|
||||
@Deprecated
|
||||
public int countWellIntegratedPeers() { return count(_wellIntegratedPeers); }
|
||||
public int countNotFailingPeers() { return count(_notFailingPeers); }
|
||||
public int countFailingPeers() { return count(_failingPeers); }
|
||||
@Deprecated
|
||||
public int countFailingPeers() { return 0; }
|
||||
|
||||
public int countActivePeers() {
|
||||
int activePeers = 0;
|
||||
@ -307,12 +305,6 @@ public class ProfileOrganizer {
|
||||
|
||||
getReadLock();
|
||||
try {
|
||||
for (PeerProfile profile : _failingPeers.values()) {
|
||||
if (profile.getLastSendSuccessful() >= hideBefore)
|
||||
activePeers++;
|
||||
else if (profile.getLastHeardFrom() >= hideBefore)
|
||||
activePeers++;
|
||||
}
|
||||
for (PeerProfile profile : _notFailingPeers.values()) {
|
||||
if (profile.getLastSendSuccessful() >= hideBefore)
|
||||
activePeers++;
|
||||
@ -336,7 +328,9 @@ public class ProfileOrganizer {
|
||||
|
||||
/**
|
||||
* Deprecated for now, always false
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isFailing(Hash peer) {
|
||||
// Always false so skip the lock
|
||||
//return isX(_failingPeers, peer);
|
||||
@ -348,7 +342,6 @@ public class ProfileOrganizer {
|
||||
if (!getWriteLock())
|
||||
return;
|
||||
try {
|
||||
_failingPeers.clear();
|
||||
_fastPeers.clear();
|
||||
_highCapacityPeers.clear();
|
||||
_notFailingPeers.clear();
|
||||
@ -733,12 +726,10 @@ public class ProfileOrganizer {
|
||||
/**
|
||||
* I'm not quite sure why you'd want this... (other than for failover from the better results)
|
||||
*
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated
|
||||
private void selectFailingPeers(int howMany, Set<Hash> exclude, Set<Hash> matches) {
|
||||
getReadLock();
|
||||
try {
|
||||
locked_selectPeers(_failingPeers, howMany, exclude, matches);
|
||||
} finally { releaseReadLock(); }
|
||||
return;
|
||||
}
|
||||
|
||||
@ -749,8 +740,7 @@ public class ProfileOrganizer {
|
||||
public Set<Hash> selectAllPeers() {
|
||||
getReadLock();
|
||||
try {
|
||||
Set<Hash> allPeers = new HashSet<Hash>(_failingPeers.size() + _notFailingPeers.size() + _highCapacityPeers.size() + _fastPeers.size());
|
||||
allPeers.addAll(_failingPeers.keySet());
|
||||
Set<Hash> allPeers = new HashSet<Hash>(_notFailingPeers.size() + _highCapacityPeers.size() + _fastPeers.size());
|
||||
allPeers.addAll(_notFailingPeers.keySet());
|
||||
allPeers.addAll(_highCapacityPeers.keySet());
|
||||
allPeers.addAll(_fastPeers.keySet());
|
||||
@ -840,7 +830,6 @@ public class ProfileOrganizer {
|
||||
locked_calculateThresholds(allPeers);
|
||||
thresholdTime = System.currentTimeMillis()-thresholdStart;
|
||||
|
||||
_failingPeers.clear();
|
||||
_fastPeers.clear();
|
||||
_highCapacityPeers.clear();
|
||||
_notFailingPeers.clear();
|
||||
@ -853,7 +842,6 @@ public class ProfileOrganizer {
|
||||
locked_placeProfile(profile);
|
||||
}
|
||||
|
||||
locked_unfailAsNecessary();
|
||||
locked_demoteHighCapAsNecessary();
|
||||
locked_promoteFastAsNecessary();
|
||||
locked_demoteFastAsNecessary();
|
||||
@ -906,7 +894,7 @@ public class ProfileOrganizer {
|
||||
_log.info("Need to explicitly promote " + numToPromote + " peers to the fast group");
|
||||
long now = _context.clock().now();
|
||||
for (PeerProfile cur : _strictCapacityOrder) {
|
||||
if ( (!_fastPeers.containsKey(cur.getPeer())) && (!cur.getIsFailing()) ) {
|
||||
if (!_fastPeers.containsKey(cur.getPeer())) {
|
||||
if (!isSelectable(cur.getPeer())) {
|
||||
// skip peers we dont have in the netDb
|
||||
// if (_log.shouldLog(Log.INFO))
|
||||
@ -982,46 +970,8 @@ public class ProfileOrganizer {
|
||||
_log.info("Demoted " + numToDemote + " peers from high cap, size now " + _highCapacityPeers.size());
|
||||
}
|
||||
}
|
||||
|
||||
/** how many not failing/active peers must we have? */
|
||||
private final static int MIN_NOT_FAILING_ACTIVE = 3;
|
||||
|
||||
/**
|
||||
* I'm not sure how much I dislike the following - if there aren't enough
|
||||
* active and not-failing peers, pick the most reliable active peers and
|
||||
* override their 'failing' flag, resorting them into the not-failing buckets
|
||||
*
|
||||
*/
|
||||
private void locked_unfailAsNecessary() {
|
||||
int notFailingActive = 0;
|
||||
long now = _context.clock().now();
|
||||
for (PeerProfile peer : _notFailingPeers.values()) {
|
||||
if (peer.getIsActive(now))
|
||||
notFailingActive++;
|
||||
if (notFailingActive >= MIN_NOT_FAILING_ACTIVE) {
|
||||
// we've got enough, no need to try further
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// we dont have enough, lets unfail our best ones remaining
|
||||
int needToUnfail = MIN_NOT_FAILING_ACTIVE - notFailingActive;
|
||||
if (needToUnfail > 0) {
|
||||
int unfailed = 0;
|
||||
for (PeerProfile best : _strictCapacityOrder) {
|
||||
if ( (best.getIsActive(now)) && (best.getIsFailing()) ) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("All peers were failing, so we have overridden the failing flag for one of the most reliable active peers (" + best.getPeer().toBase64() + ")");
|
||||
best.setIsFailing(false);
|
||||
locked_placeProfile(best);
|
||||
unfailed++;
|
||||
}
|
||||
if (unfailed >= needToUnfail)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////
|
||||
// no more public stuff below
|
||||
////////
|
||||
@ -1044,7 +994,7 @@ public class ProfileOrganizer {
|
||||
if (_us.equals(profile.getPeer())) continue;
|
||||
|
||||
// only take into account active peers that aren't failing
|
||||
if (profile.getIsFailing() || (!profile.getIsActive(now)))
|
||||
if (!profile.getIsActive(now))
|
||||
continue;
|
||||
|
||||
// dont bother trying to make sense of things below the baseline
|
||||
@ -1211,9 +1161,6 @@ public class ProfileOrganizer {
|
||||
/** called after locking the reorganizeLock */
|
||||
private PeerProfile locked_getProfile(Hash peer) {
|
||||
PeerProfile cur = _notFailingPeers.get(peer);
|
||||
if (cur != null)
|
||||
return cur;
|
||||
cur = _failingPeers.get(peer);
|
||||
return cur;
|
||||
}
|
||||
|
||||
@ -1284,8 +1231,6 @@ public class ProfileOrganizer {
|
||||
continue;
|
||||
if (_us.equals(peer))
|
||||
continue;
|
||||
if (_failingPeers.containsKey(peer))
|
||||
continue;
|
||||
// we assume if connected, it's fine, don't look in _notFailingPeers
|
||||
boolean ok = isSelectable(peer);
|
||||
if (ok) {
|
||||
@ -1427,16 +1372,7 @@ public class ProfileOrganizer {
|
||||
*/
|
||||
private void locked_placeProfile(PeerProfile profile) {
|
||||
Hash peer = profile.getPeer();
|
||||
if (profile.getIsFailing()) {
|
||||
if (!shouldDrop(profile))
|
||||
_failingPeers.put(peer, profile);
|
||||
_fastPeers.remove(peer);
|
||||
_highCapacityPeers.remove(peer);
|
||||
_wellIntegratedPeers.remove(peer);
|
||||
_notFailingPeers.remove(peer);
|
||||
_notFailingPeersList.remove(peer);
|
||||
} else {
|
||||
_failingPeers.remove(peer);
|
||||
|
||||
_fastPeers.remove(peer);
|
||||
_highCapacityPeers.remove(peer);
|
||||
_wellIntegratedPeers.remove(peer);
|
||||
@ -1476,7 +1412,7 @@ public class ProfileOrganizer {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Integrated: \t" + peer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1573,8 +1509,7 @@ public class ProfileOrganizer {
|
||||
+ " Speed:\t" + fmt.format(profile.getSpeedValue())
|
||||
+ " Capacity:\t" + fmt.format(profile.getCapacityValue())
|
||||
+ " Integration:\t" + fmt.format(profile.getIntegrationValue())
|
||||
+ " Active?\t" + profile.getIsActive(now)
|
||||
+ " Failing?\t" + profile.getIsFailing());
|
||||
+ " Active?\t" + profile.getIsActive(now) );
|
||||
} else {
|
||||
System.out.println("Peer " + peer.toBase64().substring(0,4)
|
||||
+ " [" + (organizer.isFast(peer) ? "F+R " :
|
||||
@ -1583,8 +1518,7 @@ public class ProfileOrganizer {
|
||||
+ " Speed:\t" + fmt.format(profile.getSpeedValue())
|
||||
+ " Capacity:\t" + fmt.format(profile.getCapacityValue())
|
||||
+ " Integration:\t" + fmt.format(profile.getIntegrationValue())
|
||||
+ " Active?\t" + profile.getIsActive(now)
|
||||
+ " Failing?\t" + profile.getIsFailing());
|
||||
+ " Active?\t" + profile.getIsActive(now));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user