Changeset 150cee9a for core/java


Ignore:
Timestamp:
Jan 2, 2019 2:29:10 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
4786081
Parents:
941a9944
Message:

Data: Add type byte to MetaLease?,
add EmptyProperties? to reduce object churn,
undeprecate getSigningKey(),
reduce loadProps() buffer size

Location:
core/java/src/net/i2p/data
Files:
1 added
6 edited

Legend:

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

    r941a9944 r150cee9a  
    140140     *  As of 0.9.18, throws DataFormatException on duplicate key
    141141     *
    142      *  @param props the Properties to load into
     142     *  @param props The Properties to load into.
     143     *               As of 0.9.38, if null, a new OrderedProperties will be created.
    143144     *  @param rawStream stream to read the mapping from
    144145     *  @throws DataFormatException if the format is invalid
    145146     *  @throws IOException if there is a problem reading the data
    146      *  @return the parameter props
     147     *  @return the parameter props, or (as of 0.9.38) a new OrderedProperties if props is null,
     148     *                               and an immutable EmptyProperties if empty.
    147149     *  @since 0.8.13
    148150     */
     
    150152        throws DataFormatException, IOException {
    151153        int size = (int) readLong(rawStream, 2);
    152         if (size == 0)
    153             return props;
     154        if (size == 0) {
     155            return (props != null) ? props : EmptyProperties.INSTANCE;
     156        }
     157        if (props == null)
     158            props = new OrderedProperties();
    154159        byte data[] = new byte[size];
    155160        // full read guaranteed
     
    455460        BufferedReader in = null;
    456461        try {
    457             in = new BufferedReader(new InputStreamReader(inStr, "UTF-8"), 16*1024);
     462            in = new BufferedReader(new InputStreamReader(inStr, "UTF-8"), 4*1024);
    458463            String line = null;
    459464            while ( (line = in.readLine()) != null) {
  • core/java/src/net/i2p/data/Lease2.java

    r941a9944 r150cee9a  
    77
    88/**
    9  * Like Lease but with 4-byte timestamps
     9 * Like Lease but with 4-byte timestamps.
     10 * Length is 40.
     11 *
    1012 * PRELIMINARY - Subject to change - see proposal 123
    1113 *
     
    1315 */
    1416public class Lease2 extends Lease {
     17
     18    public static final int LENGTH = 40;
    1519   
    1620    @Override
  • core/java/src/net/i2p/data/LeaseSet.java

    r941a9944 r150cee9a  
    143143    /**
    144144     *  The revocation key.
    145      *  @deprecated unused
    146      */
    147     @Deprecated
     145     *  Undeprecated as of 0.9.38, used for the blinded key in EncryptedLeaseSet.
     146     */
    148147    public SigningPublicKey getSigningKey() {
    149148        return _signingKey;
  • core/java/src/net/i2p/data/LeaseSet2.java

    r941a9944 r150cee9a  
    228228        readHeader(in);
    229229        // LS2 part
    230         _options = DataHelper.readProperties(in);
     230        // null arg to get an EmptyProperties back
     231        _options = DataHelper.readProperties(in, null);
    231232        int numKeys = in.read();
    232233        if (numKeys <= 0 || numKeys > MAX_KEYS)
     
    370371        int rv = _destination.size()
    371372             + 10
    372              + (_leases.size() * 40);
     373             + (_leases.size() * Lease2.LENGTH);
    373374        for (PublicKey key : getEncryptionKeys()) {
    374375            rv += 4;
  • core/java/src/net/i2p/data/MetaLease.java

    r941a9944 r150cee9a  
    1919public class MetaLease extends Lease {
    2020
     21    public static final int LENGTH = 40;
     22
    2123    private int _cost;
     24    private int _type;
    2225
    2326    public int getCost() {
     
    2730    public void setCost(int cost) {
    2831        _cost = cost;
     32    }
     33
     34    public int getType() {
     35        return _type;
     36    }
     37
     38    public void setType(int type) {
     39        _type = type;
    2940    }
    3041
     
    4960        _gateway = Hash.create(in);
    5061        // flags
    51         DataHelper.skip(in, 3);
     62        DataHelper.skip(in, 2);
     63        _type = in.read();
    5264        _cost = in.read();
    5365        _end = new Date(DataHelper.readLong(in, 4) * 1000);
     
    6072        _gateway.writeBytes(out);
    6173        // flags
    62         DataHelper.writeLong(out, 3, 0);
     74        DataHelper.writeLong(out, 2, 0);
     75        out.write(_type);
    6376        out.write(_cost);
    6477        DataHelper.writeLong(out, 4, _end.getTime() / 1000);
     
    7184        MetaLease lse = (MetaLease) object;
    7285        return DataHelper.eq(_end, lse.getEndDate())
     86               && _type == lse._type
    7387               && _cost == lse._cost
    7488               && DataHelper.eq(_gateway, lse.getGateway());
     
    88102        buf.append("\n\tTarget: ").append(_gateway);
    89103        buf.append("\n\tCost: ").append(_cost);
     104        buf.append("\n\tType: ").append(_type);
    90105        buf.append("]");
    91106        return buf.toString();
  • core/java/src/net/i2p/data/MetaLeaseSet.java

    r941a9944 r150cee9a  
    5454        readHeader(in);
    5555        // Meta LS2 part
    56         _options = DataHelper.readProperties(in);
     56        // null arg to get an EmptyProperties back
     57        _options = DataHelper.readProperties(in, null);
    5758        int numLeases = in.read();
    5859        //if (numLeases > MAX_META_LEASES)
     
    107108        int rv = _destination.size()
    108109             + 10
    109              + (_leases.size() * 40);
     110             + (_leases.size() * MetaLease.LENGTH);
    110111        if (isOffline())
    111112            rv += 6 + _transientSigningPublicKey.length() + _offlineSignature.length();
     
    210211            l2.setGateway(new Hash(gw));
    211212            l2.setCost(i * 5);
     213            l2.setType(((i & 0x01) == 0) ? KEY_TYPE_LS2 : KEY_TYPE_META_LS2);
    212214            ls2.addLease(l2);
    213215        }
    214216        java.util.Properties opts = new java.util.Properties();
    215         opts.setProperty("foo", "bar");
    216         opts.setProperty("test", "bazzle");
     217        //opts.setProperty("foo", "bar");
     218        //opts.setProperty("test", "bazzle");
    217219        ls2.setOptions(opts);
    218220        ls2.setDestination(pkf.getDestination());
Note: See TracChangeset for help on using the changeset viewer.