Changeset cd97718


Ignore:
Timestamp:
Mar 4, 2019 5:06:01 PM (17 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5d3b7c1
Parents:
54d9a29
Message:

I2CP, NetDB: More encrypted LS2 fixes (WIP)
Marked encrypted LS hash as local
Fix isCurrent() on encrypted LS
Fix unpublish of encrypted LS

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/LeaseSet2.java

    r54d9a29 rcd97718  
    280280        if (log.shouldWarn())
    281281            log.warn("Don't set revocation key in ls2", new Exception("I did it"));
     282    }
     283
     284    /**
     285     * Determine whether the leaseset is currently valid, at least within a given
     286     * fudge factor.
     287     * Overridden to use the expiration time instead of the last expiration.
     288     *
     289     * @param fudge milliseconds fudge factor to allow between the current time
     290     * @return true if there are current leases, false otherwise
     291     * @since 0.9.39
     292     */
     293    @Override
     294    public boolean isCurrent(long fudge) {
     295        long now = Clock.getInstance().now();
     296        return _expires > now - fudge;
    282297    }
    283298
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    r54d9a29 rcd97718  
    2929import net.i2p.data.DatabaseEntry;
    3030import net.i2p.data.Destination;
     31import net.i2p.data.EncryptedLeaseSet;
    3132import net.i2p.data.Hash;
    3233import net.i2p.data.LeaseSet;
     
    100101    private boolean _dontSendMSMOnReceive;
    101102    private final AtomicInteger _messageId; // messageId counter
     103    private Hash _encryptedLSHash;
    102104   
    103105    // Was 32767 since the beginning (04-2004).
     
    126128        LeaseRequestState leaseRequest;
    127129        Rerequest rerequestTimer;
     130        /** possibly decrypted */
    128131        LeaseSet currentLeaseSet;
     132        /** only if encrypted */
     133        LeaseSet currentEncryptedLeaseSet;
    129134
    130135        SessionParams(Destination d, boolean isPrimary) {
     
    200205        if (_sessionKeyManager != null)
    201206            _sessionKeyManager.shutdown();
     207        if (_encryptedLSHash != null)
     208            _manager.unregisterEncryptedDestination(this, _encryptedLSHash);
    202209        _manager.unregisterConnection(this);
    203210        // netdb may be null in unit tests
     
    205212            for (SessionParams sp : _sessions.values()) {
    206213                LeaseSet ls = sp.currentLeaseSet;
     214                if (ls != null)
     215                    _context.netDb().unpublish(ls);
     216                // unpublish encrypted LS also
     217                ls = sp.currentEncryptedLeaseSet;
    207218                if (ls != null)
    208219                    _context.netDb().unpublish(ls);
     
    434445                if (ls != null)
    435446                    _context.netDb().unpublish(ls);
     447                // unpublish encrypted LS also
     448                ls = sp.currentEncryptedLeaseSet;
     449                if (ls != null)
     450                    _context.netDb().unpublish(ls);
    436451                isPrimary = sp.isPrimary;
    437452                if (!isPrimary)
     
    447462                _manager.unregisterSession(sp.sessionId, sp.dest);
    448463                LeaseSet ls = sp.currentLeaseSet;
     464                if (ls != null)
     465                    _context.netDb().unpublish(ls);
     466                // unpublish encrypted LS also
     467                ls = sp.currentEncryptedLeaseSet;
    449468                if (ls != null)
    450469                    _context.netDb().unpublish(ls);
     
    589608     * called after a new leaseSet is granted by the client, the NetworkDb has been
    590609     * updated.  This takes care of all the LeaseRequestState stuff (including firing any jobs)
     610     *
     611     * @param ls, if encrypted, the encrypted LS, not the decrypted one
    591612     */
    592613    void leaseSetCreated(LeaseSet ls) {
     
    597618        LeaseRequestState state;
    598619        synchronized (this) {
     620            if (ls.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     621                EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
     622                sp.currentEncryptedLeaseSet = encls;
     623                ls = encls.getDecryptedLeaseSet();
     624            }
    599625            sp.currentLeaseSet = ls;
    600626            state = sp.leaseRequest;
     
    615641        if ( (state != null) && (state.getOnGranted() != null) )
    616642            _context.jobQueue().addJob(state.getOnGranted());
     643    }
     644
     645    /**
     646     *  Call after destinationEstablished(),
     647     *  when an encrypted leaseset is created, so we know it's local.
     648     *  Add to the clients list. Check for a dup hash.
     649     *  Caller must call runner.disconnectClient() on failure.
     650     *
     651     *  @param hash the location of the encrypted LS, will change every day
     652     *  @return success, false on dup
     653     *  @since 0.9.39
     654     */
     655    public boolean registerEncryptedLS(Hash hash) {
     656        boolean rv = true;
     657        synchronized(this) {
     658            if (!hash.equals(_encryptedLSHash)) {
     659                if (_encryptedLSHash != null)
     660                    _manager.unregisterEncryptedDestination(this, _encryptedLSHash);
     661                rv = _manager.registerEncryptedDestination(this, hash);
     662                if (rv)
     663                    _encryptedLSHash = hash;
     664            }
     665        }
     666        return rv;
    617667    }
    618668   
  • router/java/src/net/i2p/router/client/ClientManager.java

    r54d9a29 rcd97718  
    273273        }
    274274    }
    275    
     275
    276276    /**
    277277     *  Remove only the following session. Does not remove the runner if it has more.
     
    288288        }
    289289    }
    290    
     290
     291    /**
     292     *  Remove the hash for the encrypted LS.
     293     *  Call before unregisterConnection, or when the hash changes.
     294     *
     295     *  @since 0.9.39
     296     */
     297    public void unregisterEncryptedDestination(ClientConnectionRunner runner, Hash hash) {
     298        if (_log.shouldLog(Log.WARN))
     299            _log.warn("Unregistering encrypted LS "  + hash.toBase32());
     300        synchronized (_runners) {
     301            _runnersByHash.remove(hash);
     302        }
     303    }
     304
    291305    /**
    292306     *  Add to the clients list. Check for a dup destination.
     
    328342        return rv;
    329343    }
    330    
     344
     345    /**
     346     *  Call after destinationEstablished(),
     347     *  when an encrypted leaseset is created, so we know it's local.
     348     *  Add to the clients list. Check for a dup hash.
     349     *  Caller must call runner.disconnectClient() on failure.
     350     *
     351     *  @param hash the location of the encrypted LS, will change every day
     352     *  @return success, false on dup
     353     *  @since 0.9.39
     354     */
     355    public boolean registerEncryptedDestination(ClientConnectionRunner runner, Hash hash) {
     356        if (_log.shouldLog(Log.DEBUG))
     357            _log.debug("New encrypted LS " + hash.toBase32());
     358
     359        boolean rv;
     360        synchronized (_runners) {
     361            rv = !_runnersByHash.containsKey(hash);
     362            if (rv)
     363                _runnersByHash.put(hash, runner);
     364        }
     365        if (!rv)
     366            _log.error("Encrypted dest collision " + hash.toBase32());
     367        return rv;
     368    }
     369
    331370    /**
    332371     *  Generate a new random, unused sessionId. Caller must synch on _runners.
  • router/java/src/net/i2p/router/client/ClientMessageEventListener.java

    r54d9a29 rcd97718  
    633633        }
    634634        try {
     635            if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     636                // so the client manager knows it's a local hash
     637                // we could put this in runner.leaseSetCreated(), but
     638                // need to set it before calling publish()
     639                Hash newHash = ls.getHash();
     640                boolean ok = _runner.registerEncryptedLS(newHash);
     641                if (!ok) {
     642                    _runner.disconnectClient("Duplicate hash of encrypted LS2");
     643                    return;
     644                }
     645            }
    635646            if (_log.shouldDebug())
    636647                _log.debug("Publishing: " + ls);
     
    653664
    654665        // leaseSetCreated takes care of all the LeaseRequestState stuff (including firing any jobs)
    655         if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
    656             EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
    657             _runner.leaseSetCreated(encls.getDecryptedLeaseSet());
    658         } else {
    659             _runner.leaseSetCreated(ls);
    660         }
     666        _runner.leaseSetCreated(ls);
    661667    }
    662668
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    r54d9a29 rcd97718  
    12011201    public void unpublish(LeaseSet localLeaseSet) {
    12021202        if (!_initialized) return;
    1203         Hash h = localLeaseSet.getDestination().calculateHash();
     1203        Hash h = localLeaseSet.getHash();
    12041204        DatabaseEntry data = _ds.remove(h);
    12051205       
Note: See TracChangeset for help on using the changeset viewer.