SSU2: Post-termination handler part 9

Cancel timers on eviction from cache
This commit is contained in:
zzz
2022-12-07 15:55:21 -05:00
parent 55e2fae135
commit 855bb2af33

View File

@@ -351,7 +351,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (xdh != null) {
// roughly scale based on expected traffic
int sz = Math.max(16, Math.min(128, getMaxConnections() / 16));
_recentlyClosedConnIDs = new LHMCache<Long, PeerStateDestroyed>(sz);
_recentlyClosedConnIDs = new DestroyedCache(sz);
} else {
_recentlyClosedConnIDs = null;
}
@@ -4065,6 +4065,28 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
/**
* For PeerStateDestroyed, to kill the timers on overflow,
* else the memory won't be freed.
*
* @since 0.9.57
*/
private static class DestroyedCache extends LHMCache<Long, PeerStateDestroyed> {
public DestroyedCache(int max) {
super(max);
}
@Override
protected boolean removeEldestEntry(Map.Entry<Long, PeerStateDestroyed> eldest) {
boolean rv = super.removeEldestEntry(eldest);
if (rv) {
eldest.getValue().kill();
}
return rv;
}
}
/*******
private static final String BADIPS[] = new String[] { "192.168.0.1", "127.0.0.1", "10.3.4.5", "172.16.3.4", "224.5.6.7" };
private static final String GOODIPS[] = new String[] { "192.167.0.1", "126.0.0.1", "11.3.4.5", "172.15.3.4", "223.5.6.7" };