Changeset 026ddb3 for core/java


Ignore:
Timestamp:
Dec 1, 2018 1:13:51 PM (20 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

Location:
core/java/src/net/i2p/data
Files:
2 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);
Note: See TracChangeset for help on using the changeset viewer.