diff --git a/router/java/src/net/i2p/router/peermanager/PeerManager.java b/router/java/src/net/i2p/router/peermanager/PeerManager.java index d3f2986e8587d6fa8b2bd02bf34bb15730fe226a..362c67b5a7a7f8fc5a02fadd0884053099173fca 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerManager.java +++ b/router/java/src/net/i2p/router/peermanager/PeerManager.java @@ -57,6 +57,7 @@ class PeerManager { */ private static final long REORGANIZE_TIME_LONG = 351*1000; private static final long STORE_TIME = 19*60*60*1000; + private static final long EXPIRE_AGE = 3*24*60*60*1000; public static final String TRACKED_CAPS = "" + FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL + @@ -102,7 +103,8 @@ class PeerManager { } /** - * Reorganize the profiles. Also periodically store them. + * Reorganize the profiles. Also periodically store them, + * and delete very old ones. * * This takes too long to run on the SimpleTimer2 queue * @since 0.9.10 @@ -131,6 +133,7 @@ class PeerManager { try { _log.debug("Periodic profile store start"); storeProfiles(); + _persistenceHelper.deleteOldProfiles(EXPIRE_AGE); _log.debug("Periodic profile store end"); } catch (Throwable t) { _log.log(Log.CRIT, "Error storing profiles", t); diff --git a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java index f978194d3867a3fec8eb02b52fc3a9c8f3a8ff32..f22bf0e3f14c5ebd3e69df5c41f595d3d7e5e05f 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java +++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java @@ -229,6 +229,26 @@ class ProfilePersistenceHelper { } } + /** + * Delete profile files with timestamps older than 'age' ago + * @since 0.9.28 + */ + public void deleteOldProfiles(long age) { + long cutoff = System.currentTimeMillis() - age; + List<File> files = selectFiles(); + int i = 0; + for (File f : files) { + if (!f.isFile()) + continue; + if (f.lastModified() < cutoff) { + i++; + f.delete(); + } + } + if (_log.shouldWarn()) + _log.warn("Deleted " + i + " old profiles"); + } + private boolean isExpired(long lastSentToSuccessfully) { long timeSince = _context.clock().now() - lastSentToSuccessfully; return (timeSince > EXPIRE_AGE);