Changeset 026ddb3


Ignore:
Timestamp:
Dec 1, 2018 1:13:51 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
700d4d3
Parents:
79440f84
Message:

Router: Add preliminary support for more LS2 types (proposal 123)
I2CP: Don't require privkeys for meta in CLS2 message

Files:
10 edited

Legend:

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

    r79440f84 r026ddb3  
    104104     * This should be faster than instanceof.
    105105     *
    106      * @return KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET
     106     * @return KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET or LS2 types
    107107     * @since 0.8.2
    108108     */
    109109    public abstract int getType();
     110
     111    /**
     112     * Convenience method, is the type any variant of leaseset?
     113     *
     114     * @return true for any type of LeaseSet, false for RouterInfo, false for others
     115     * @since 0.9.38
     116     */
     117    public boolean isLeaseSet() {
     118        return isLeaseSet(getType());
     119    }
     120
     121    /**
     122     * Convenience method, is the type any variant of leaseset?
     123     *
     124     * @return true for any type of LeaseSet, false for RouterInfo, false for others
     125     * @since 0.9.38
     126     */
     127    public static boolean isLeaseSet(int type) {
     128        return type == KEY_TYPE_LEASESET ||
     129               type == KEY_TYPE_LS2 ||
     130               type == KEY_TYPE_ENCRYPTED_LS2 ||
     131               type == KEY_TYPE_META_LS2;
     132    }
    110133
    111134    /**
  • core/java/src/net/i2p/data/i2cp/CreateLeaseSet2Message.java

    r79440f84 r026ddb3  
    1010import net.i2p.data.DatabaseEntry;
    1111import net.i2p.data.DataFormatException;
     12import net.i2p.data.EncryptedLeaseSet;
    1213import net.i2p.data.LeaseSet;
    1314import net.i2p.data.LeaseSet2;
     15import net.i2p.data.MetaLeaseSet;
    1416import net.i2p.data.PrivateKey;
    1517import net.i2p.data.SigningPrivateKey;
     
    2426 * serialized after the LeaseSet, not before, so we can
    2527 * infer the types from the LeaseSet.
     28 *
     29 * For Meta LS:
     30 * SigningPrivateKey and PrivateKey are not present.
    2631 *
    2732 * @since 0.9.38
     
    4449            } else if (type == DatabaseEntry.KEY_TYPE_LS2) {
    4550                _leaseSet = new LeaseSet2();
     51            } else if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     52                _leaseSet = new EncryptedLeaseSet();
     53            } else if (type == DatabaseEntry.KEY_TYPE_META_LS2) {
     54                _leaseSet = new MetaLeaseSet();
    4655            } else if (type == -1) {
    4756                throw new EOFException("EOF reading LS type");
     
    5059            }
    5160            _leaseSet.readBytes(in);
    52             // In CLSM this is the type of the dest, but revocation is unimplemented.
    53             // In CLS2M this is the type of the signature (which may be different than the
    54             // type of the dest if it's an offline signature)
    55             // and is needed by the session tag manager.
    56             SigType stype = _leaseSet.getSignature().getType();
    57             if (stype == null)
    58                 throw new I2CPMessageException("Unsupported sig type");
    59             _signingPrivateKey = new SigningPrivateKey(stype);
    60             _signingPrivateKey.readBytes(in);
    61             EncType etype = _leaseSet.getEncryptionKey().getType();
    62             if (etype == null)
    63                 throw new I2CPMessageException("Unsupported encryption type");
    64             _privateKey = new PrivateKey(etype);
    65             _privateKey.readBytes(in);
     61            if (type != DatabaseEntry.KEY_TYPE_META_LS2) {
     62                // In CLSM this is the type of the dest, but revocation is unimplemented.
     63                // In CLS2M this is the type of the signature (which may be different than the
     64                // type of the dest if it's an offline signature)
     65                // and is needed by the session tag manager.
     66                SigType stype = _leaseSet.getSignature().getType();
     67                if (stype == null)
     68                    throw new I2CPMessageException("Unsupported sig type");
     69                _signingPrivateKey = new SigningPrivateKey(stype);
     70                _signingPrivateKey.readBytes(in);
     71                EncType etype = _leaseSet.getEncryptionKey().getType();
     72                if (etype == null)
     73                    throw new I2CPMessageException("Unsupported encryption type");
     74                _privateKey = new PrivateKey(etype);
     75                _privateKey.readBytes(in);
     76            }
    6677        } catch (DataFormatException dfe) {
    6778            throw new I2CPMessageException("Error reading the CreateLeaseSetMessage", dfe);
     
    7182    @Override
    7283    protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
    73         if (_sessionId == null || _signingPrivateKey == null || _privateKey == null || _leaseSet == null)
     84        if (_sessionId == null || _leaseSet == null ||
     85            (_leaseSet.getType() != DatabaseEntry.KEY_TYPE_META_LS2 && (_signingPrivateKey == null || _privateKey == null)))
    7486            throw new I2CPMessageException("Unable to write out the message as there is not enough data");
    7587        int size = 4 // sessionId
     
    8395            os.write(_leaseSet.getType());
    8496            _leaseSet.writeBytes(os);
    85             _signingPrivateKey.writeBytes(os);
    86             _privateKey.writeBytes(os);
     97            if (_leaseSet.getType() != DatabaseEntry.KEY_TYPE_META_LS2) {
     98                _signingPrivateKey.writeBytes(os);
     99                _privateKey.writeBytes(os);
     100            }
    87101        } catch (DataFormatException dfe) {
    88102            throw new I2CPMessageException("Error writing out the message data", dfe);
  • router/java/src/net/i2p/data/i2np/DatabaseStoreMessage.java

    r79440f84 r026ddb3  
    1717import net.i2p.data.DataFormatException;
    1818import net.i2p.data.DataHelper;
     19import net.i2p.data.EncryptedLeaseSet;
    1920import net.i2p.data.Hash;
    2021import net.i2p.data.LeaseSet;
    2122import net.i2p.data.LeaseSet2;
     23import net.i2p.data.MetaLeaseSet;
    2224import net.i2p.data.router.RouterInfo;
    2325import net.i2p.data.TunnelId;
     
    135137        }
    136138       
    137         if (dbType == DatabaseEntry.KEY_TYPE_LEASESET) {
    138             _dbEntry = new LeaseSet();
    139             try {
    140                 _dbEntry.readBytes(new ByteArrayInputStream(data, curIndex, data.length-curIndex));
    141             } catch (DataFormatException dfe) {
    142                 throw new I2NPMessageException("Error reading the leaseSet", dfe);
    143             } catch (IOException ioe) {
    144                 throw new I2NPMessageException("Error reading the leaseSet", ioe);
    145             }
    146         } else if (dbType == DatabaseEntry.KEY_TYPE_LS2) {
    147             _dbEntry = new LeaseSet2();
     139        if (DatabaseEntry.isLeaseSet(dbType)) {
     140            if (dbType == DatabaseEntry.KEY_TYPE_LEASESET)
     141                _dbEntry = new LeaseSet();
     142            else if (dbType == DatabaseEntry.KEY_TYPE_LS2)
     143                _dbEntry = new LeaseSet2();
     144            else if (dbType == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2)
     145                _dbEntry = new EncryptedLeaseSet();
     146            else
     147                _dbEntry = new MetaLeaseSet();
    148148            try {
    149149                _dbEntry.readBytes(new ByteArrayInputStream(data, curIndex, data.length-curIndex));
     
    197197            len += 4 + Hash.HASH_LENGTH; // replyTunnel+replyGateway
    198198        int type = _dbEntry.getType();
    199         if (type == DatabaseEntry.KEY_TYPE_LEASESET) {
     199        if (_dbEntry.isLeaseSet()) {
    200200            if (_byteCache == null) {
    201201                _byteCache = _dbEntry.toByteArray();
     
    219219        if (_dbEntry == null) throw new I2NPMessageException("Missing entry");
    220220        int type = _dbEntry.getType();
    221         if (type != DatabaseEntry.KEY_TYPE_LEASESET && type != DatabaseEntry.KEY_TYPE_ROUTERINFO)
     221        if (type != DatabaseEntry.KEY_TYPE_ROUTERINFO && !_dbEntry.isLeaseSet())
    222222            throw new I2NPMessageException("Invalid key type " + type);
    223223       
  • router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java

    r79440f84 r026ddb3  
    9696        DatabaseEntry dbe = getContext().netDb().lookupLocally(_message.getSearchKey());
    9797        int type = dbe != null ? dbe.getType() : -1;
    98         if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
     98        if (DatabaseEntry.isLeaseSet(type) &&
    9999            (lookupType == DatabaseLookupMessage.Type.ANY || lookupType == DatabaseLookupMessage.Type.LS)) {
    100100            LeaseSet ls = (LeaseSet) dbe;
     
    261261                       + " tunnel " + replyTunnel);
    262262        DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
    263         int type = data.getType();
    264         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     263        if (data.isLeaseSet()) {
    265264            getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1);
    266265        }
  • router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java

    r79440f84 r026ddb3  
    6262        for (Map.Entry<Hash, DatabaseEntry> entry : _facade.getDataStore().getMapEntries()) {
    6363            DatabaseEntry obj = entry.getValue();
    64             int type = obj.getType();
    65             if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    66                 type == DatabaseEntry.KEY_TYPE_LS2) {
     64            if (obj.isLeaseSet()) {
    6765                LeaseSet ls = (LeaseSet)obj;
    6866                if (!ls.isCurrent(Router.CLOCK_FUDGE_FACTOR))
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlyLookupMatchJob.java

    r79440f84 r026ddb3  
    5555            DatabaseEntry entry = dsm.getEntry();
    5656            int type = entry.getType();
    57             if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    58                 type == DatabaseEntry.KEY_TYPE_LS2) {
     57            if (DatabaseEntry.isLeaseSet(type)) {
    5958                // Since HFDSMJ wants to setReceivedAsPublished(), we have to
    6059                // set a flag saying this was really the result of a query,
  • router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

    r79440f84 r026ddb3  
    7171        DatabaseEntry entry = _message.getEntry();
    7272        int type = entry.getType();
    73         if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    74             type == DatabaseEntry.KEY_TYPE_LS2) {
     73        if (DatabaseEntry.isLeaseSet(type)) {
    7574            getContext().statManager().addRateData("netDb.storeLeaseSetHandled", 1);
    7675            if (_log.shouldLog(Log.INFO))
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    r79440f84 r026ddb3  
    439439        int rv = 0;
    440440        for (DatabaseEntry ds : _ds.getEntries()) {
    441             int type = ds.getType();
    442             if ((type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) &&
     441            if (ds.isLeaseSet() &&
    443442                ((LeaseSet)ds).getReceivedAsPublished())
    444443                rv++;
     
    469468            return null;
    470469        int type = rv.getType();
    471         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     470        if (DatabaseEntry.isLeaseSet(type)) {
    472471            LeaseSet ls = (LeaseSet)rv;
    473472            if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR))
     
    554553        DatabaseEntry ds = _ds.get(key);
    555554        if (ds != null) {
    556             int type = ds.getType();
    557             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     555            if (ds.isLeaseSet()) {
    558556                LeaseSet ls = (LeaseSet)ds;
    559557                if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR)) {
     
    608606        DatabaseEntry ds = _ds.get(key);
    609607        if (ds != null) {
    610             int type = ds.getType();
    611             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     608            if (ds.isLeaseSet()) {
    612609                LeaseSet ls = (LeaseSet)ds;
    613610                return ls.getDestination();
     
    10831080        if (entry.getHash().equals(h)) {
    10841081            int etype = entry.getType();
    1085             if (etype == DatabaseEntry.KEY_TYPE_LEASESET || etype == DatabaseEntry.KEY_TYPE_LS2) {
     1082            if (DatabaseEntry.isLeaseSet(etype)) {
    10861083                LeaseSet ls = (LeaseSet) entry;
    10871084                Destination d = ls.getDestination();
     
    12431240        Set<LeaseSet> leases = new HashSet<LeaseSet>();
    12441241        for (DatabaseEntry o : getDataStore().getEntries()) {
    1245             int type = o.getType();
    1246             if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2)
     1242            if (o.isLeaseSet())
    12471243                leases.add((LeaseSet)o);
    12481244        }
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    r79440f84 r026ddb3  
    7979        _expiration = context.clock().now() + timeoutMs;
    8080        _peerSelector = facade.getPeerSelector();
    81         int type = data.getType();
    82         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     81        if (data.isLeaseSet()) {
    8382            _connectChecker = null;
    8483            _connectMask = 0;
     
    314313            if (responseTime > MAX_DIRECT_EXPIRATION)
    315314                responseTime = MAX_DIRECT_EXPIRATION;
    316         } else if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
    317         } else {
     315        } else if (!DatabaseEntry.isLeaseSet(type)) {
    318316            throw new IllegalArgumentException("Storing an unknown data type! " + _state.getData());
    319317        }
     
    341339     */
    342340    private void sendStore(DatabaseStoreMessage msg, RouterInfo peer, long expiration) {
    343         int type = msg.getEntry().getType();
    344         if (type == DatabaseEntry.KEY_TYPE_LEASESET || type == DatabaseEntry.KEY_TYPE_LS2) {
     341        if (msg.getEntry().isLeaseSet()) {
    345342            getContext().statManager().addRateData("netDb.storeLeaseSetSent", 1);
    346343            // if it is an encrypted leaseset...
  • router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java

    r79440f84 r026ddb3  
    100100        int count = 0;
    101101        for (DatabaseEntry d : _data.values()) {
    102             int type = d.getType();
    103             if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    104                 type == DatabaseEntry.KEY_TYPE_LS2)
     102            if (d.isLeaseSet())
    105103                count++;
    106104        }
     
    152150                rv = true;
    153151            }
    154         } else if (type == DatabaseEntry.KEY_TYPE_LEASESET ||
    155                    type == DatabaseEntry.KEY_TYPE_LS2) {
     152        } else if (DatabaseEntry.isLeaseSet(type)) {
    156153            LeaseSet ls = (LeaseSet)data;
    157154            if (old != null) {
Note: See TracChangeset for help on using the changeset viewer.