forked from I2P_Developers/i2p.i2p
Startup: Delete our old RI from netDB when rekeying
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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) {}
|
||||
|
Reference in New Issue
Block a user