diff --git a/core/java/src/net/i2p/data/SessionTag.java b/core/java/src/net/i2p/data/SessionTag.java index a4fb59b4ac..8be4dffc64 100644 --- a/core/java/src/net/i2p/data/SessionTag.java +++ b/core/java/src/net/i2p/data/SessionTag.java @@ -9,57 +9,60 @@ package net.i2p.data; * */ -import java.io.InputStream; -import java.io.IOException; +import java.util.Arrays; +import net.i2p.data.Base64; import net.i2p.util.RandomSource; import net.i2p.util.SimpleByteCache; import net.i2p.util.SipHash; /** * 32 bytes, usually of random data. - * Changed from ByteArray to SimpleDataStructure in 0.8.2. + * + * Not recommended for external use, subject to change. + * + * As of 0.9.44, does NOT extend SimpleDataStructure, to save space */ -public class SessionTag extends SimpleDataStructure { +public class SessionTag { public final static int BYTE_LENGTH = 32; - private int _cachedHashCode; + private final int _cachedHashCode; + private final byte[] _data; + /** + * Instantiate the data array and fill it with random data. + */ public SessionTag() { - super(); + _data = SimpleByteCache.acquire(BYTE_LENGTH); + RandomSource.getInstance().nextBytes(_data); + _cachedHashCode = SipHash.hashCode(_data); } /** - * @param create if true, instantiate the data array and fill it with random data. + * Instantiate the data array and fill it with random data. + * @param create ignored as of 0.9.44, assumed true */ public SessionTag(boolean create) { - super(); - if (create) { - _data = SimpleByteCache.acquire(BYTE_LENGTH); - RandomSource.getInstance().nextBytes(_data); - _cachedHashCode = SipHash.hashCode(_data); - } + this(); } + /** + * @param val as of 0.9.44, non-null + */ public SessionTag(byte val[]) { - super(val); + if (val.length != BYTE_LENGTH) + throw new IllegalArgumentException(); + _data = val; + _cachedHashCode = SipHash.hashCode(val); + } + + public byte[] getData() { + return _data; } public int length() { return BYTE_LENGTH; } - @Override - public void setData(byte[] data) { - super.setData(data); - _cachedHashCode = SipHash.hashCode(data); - } - - @Override - public void readBytes(InputStream in) throws DataFormatException, IOException { - super.readBytes(in); - _cachedHashCode = SipHash.hashCode(_data); - } - /** * SessionTags are generated both locally and by peers, in quantity, * and are used as keys in several datastructures (see TransientSessionKeyManager), @@ -70,4 +73,23 @@ public class SessionTag extends SimpleDataStructure { return _cachedHashCode; } + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if ((obj == null) || !(obj instanceof SessionTag)) return false; + return Arrays.equals(_data, ((SessionTag) obj)._data); + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder(64); + buf.append("[SessionTag: "); + if (_data == null) { + buf.append("null"); + } else { + buf.append(Base64.encode(_data)); + } + buf.append(']'); + return buf.toString(); + } } diff --git a/history.txt b/history.txt index 2ab445b213..d5d648e11c 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ +2019-10-23 zzz + * Build: Recognize gettext 0.20 + * Data: Reduce SessionTag size + * 2019-10-22 0.9.43 released 2019-10-18 zzz diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index a411b00998..87e5bffca0 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 0; + public final static long BUILD = 1; /** for example "-test" */ public final static String EXTRA = "";