diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java index c3c413930ad068245f516647d11af620b4311828..90a51740c8801d76df8c70c622dd135edd0b7bf6 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java @@ -44,8 +44,10 @@ import net.i2p.util.SecureFileOutputStream; * Write out keys to disk when we get them and periodically read ones we don't know * about into memory, with newly read routers are also added to the routing table. * + * Public only for access to static methods by startup classes + * */ -class PersistentDataStore extends TransientDataStore { +public class PersistentDataStore extends TransientDataStore { private final File _dbDir; private final KademliaNetworkDatabaseFacade _facade; private final Writer _writer; @@ -630,8 +632,23 @@ class PersistentDataStore extends TransientDataStore { return ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX; return DIR_PREFIX + b64.charAt(0) + File.separatorChar + ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX; } + + /** + * The persistent RI file for a hash. + * This is available before the netdb subsystem is running, so we can delete our old RI. + * + * @return non-null, should be absolute, does not necessarily exist + * @since 0.9.23 + */ + public static File getRouterInfoFile(RouterContext ctx, Hash hash) { + String b64 = hash.toBase64(); + File dir = new File(ctx.getRouterDir(), ctx.getProperty(KademliaNetworkDatabaseFacade.PROP_DB_DIR, KademliaNetworkDatabaseFacade.DEFAULT_DB_DIR)); + if (ctx.getBooleanProperty(PROP_FLAT)) + return new File(dir, ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX); + return new File(dir, DIR_PREFIX + b64.charAt(0) + File.separatorChar + ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX); + } - static Hash getRouterInfoHash(String filename) { + private static Hash getRouterInfoHash(String filename) { return getHash(filename, ROUTERINFO_PREFIX, ROUTERINFO_SUFFIX); } diff --git a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java index f58a1002c18559d8673a6ab1e5a115c4faf2e49d..1ddce12b9874e8c92322453ad3058caa7fd3216a 100644 --- a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java +++ b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java @@ -20,6 +20,7 @@ import net.i2p.crypto.SigType; import net.i2p.data.Certificate; import net.i2p.data.DataFormatException; import net.i2p.data.DataHelper; +import net.i2p.data.Hash; import net.i2p.data.PrivateKey; import net.i2p.data.PublicKey; import net.i2p.data.SigningPrivateKey; @@ -30,6 +31,7 @@ import net.i2p.data.router.RouterPrivateKeyFile; import net.i2p.router.JobImpl; import net.i2p.router.Router; import net.i2p.router.RouterContext; +import net.i2p.router.networkdb.kademlia.PersistentDataStore; import net.i2p.util.Log; /** @@ -122,9 +124,18 @@ class LoadRouterInfoJob extends JobImpl { } if (sigTypeChanged || shouldRebuild(privkey)) { + if (_us != null) { + Hash h = _us.getIdentity().getHash(); + _log.logAlways(Log.WARN, "Deleting old router identity " + h.toBase64()); + // the netdb hasn't started yet, but we want to delete the RI + File f = PersistentDataStore.getRouterInfoFile(getContext(), h); + f.delete(); + // the banlist can be called at any time + getContext().banlist().banlistRouterForever(h, "Our previous identity"); + _us = null; + } if (sigTypeChanged) _log.logAlways(Log.WARN, "Rebuilding RouterInfo with new signature type " + cstype); - _us = null; // windows... close before deleting if (fis1 != null) { try { fis1.close(); } catch (IOException ioe) {}