Changeset 2c03b43


Ignore:
Timestamp:
Oct 13, 2015 7:24:30 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5e879b85
Parents:
55a6f44
Message:

Startup: Delete our old RI from netDB when rekeying

Location:
router/java/src/net/i2p/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java

    r55a6f44 r2c03b43  
    4545 * about into memory, with newly read routers are also added to the routing table.
    4646 *
     47 * Public only for access to static methods by startup classes
     48 *
    4749 */
    48 class PersistentDataStore extends TransientDataStore {
     50public class PersistentDataStore extends TransientDataStore {
    4951    private final File _dbDir;
    5052    private final KademliaNetworkDatabaseFacade _facade;
     
    631633        return DIR_PREFIX + b64.charAt(0) + File.separatorChar + ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX;
    632634    }
    633    
    634     static Hash getRouterInfoHash(String filename) {
     635
     636    /**
     637     *  The persistent RI file for a hash.
     638     *  This is available before the netdb subsystem is running, so we can delete our old RI.
     639     *
     640     *  @return non-null, should be absolute, does not necessarily exist
     641     *  @since 0.9.23
     642     */
     643    public static File getRouterInfoFile(RouterContext ctx, Hash hash) {
     644        String b64 = hash.toBase64();
     645        File dir = new File(ctx.getRouterDir(), ctx.getProperty(KademliaNetworkDatabaseFacade.PROP_DB_DIR, KademliaNetworkDatabaseFacade.DEFAULT_DB_DIR));
     646        if (ctx.getBooleanProperty(PROP_FLAT))
     647            return new File(dir, ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX);
     648        return new File(dir, DIR_PREFIX + b64.charAt(0) + File.separatorChar + ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX);
     649    }
     650   
     651    private static Hash getRouterInfoHash(String filename) {
    635652        return getHash(filename, ROUTERINFO_PREFIX, ROUTERINFO_SUFFIX);
    636653    }
  • router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java

    r55a6f44 r2c03b43  
    2121import net.i2p.data.DataFormatException;
    2222import net.i2p.data.DataHelper;
     23import net.i2p.data.Hash;
    2324import net.i2p.data.PrivateKey;
    2425import net.i2p.data.PublicKey;
     
    3132import net.i2p.router.Router;
    3233import net.i2p.router.RouterContext;
     34import net.i2p.router.networkdb.kademlia.PersistentDataStore;
    3335import net.i2p.util.Log;
    3436
     
    123125
    124126                if (sigTypeChanged || shouldRebuild(privkey)) {
     127                    if (_us != null) {
     128                        Hash h = _us.getIdentity().getHash();
     129                        _log.logAlways(Log.WARN, "Deleting old router identity " + h.toBase64());
     130                        // the netdb hasn't started yet, but we want to delete the RI
     131                        File f = PersistentDataStore.getRouterInfoFile(getContext(), h);
     132                        f.delete();
     133                        // the banlist can be called at any time
     134                        getContext().banlist().banlistRouterForever(h, "Our previous identity");
     135                        _us = null;
     136                    }
    125137                    if (sigTypeChanged)
    126138                        _log.logAlways(Log.WARN, "Rebuilding RouterInfo with new signature type " + cstype);
    127                     _us = null;
    128139                    // windows... close before deleting
    129140                    if (fis1 != null) {
Note: See TracChangeset for help on using the changeset viewer.