NTCP2 code consolidation, minor changes

This commit is contained in:
zzz
2018-08-23 15:25:45 +00:00
parent 6cf84ac5a3
commit cc2056d4cf
7 changed files with 32 additions and 25 deletions

View File

@ -288,6 +288,8 @@ public class RouterAddress extends DataStructureImpl {
_transportStyle = "SSU";
else if (_transportStyle.equals("NTCP"))
_transportStyle = "NTCP";
else if (_transportStyle.equals("NTCP2"))
_transportStyle = "NTCP2";
DataHelper.readProperties(in, _options);
}

View File

@ -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 = "";

View File

@ -66,7 +66,6 @@ public class X25519KeyFactory extends I2PThread {
* Note that this stops the singleton precalc thread.
* You don't want to do this if there are multiple routers in the JVM.
* Fix this if you care. See Router.shutdown().
* @since 0.8.8
*/
public void shutdown() {
_isRunning = false;

View File

@ -1006,21 +1006,13 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
/** @since 0.9.36 */
public void gotOptions(byte[] options, boolean isHandshake) {
if (options.length < 12) {
NTCP2Options hisPadding = NTCP2Options.fromByteArray(options);
if (hisPadding == null) {
if (_log.shouldWarn())
_log.warn("Got options length " + options.length + " on: " + this);
return;
}
float tmin = (options[0] & 0xff) / 16.0f;
float tmax = (options[1] & 0xff) / 16.0f;
float rmin = (options[2] & 0xff) / 16.0f;
float rmax = (options[3] & 0xff) / 16.0f;
int tdummy = (int) DataHelper.fromLong(options, 4, 2);
int rdummy = (int) DataHelper.fromLong(options, 6, 2);
int tdelay = (int) DataHelper.fromLong(options, 8, 2);
int rdelay = (int) DataHelper.fromLong(options, 10, 2);
_hisPadding = new NTCP2Options(tmin, tmax, rmin, rmax,
tdummy, rdummy, tdelay, rdelay);
_hisPadding = hisPadding;
}
/** @since 0.9.36 */

View File

@ -1,5 +1,7 @@
package net.i2p.router.transport.ntcp;
import net.i2p.data.DataHelper;
/**
*
* NTCP2 Padding/Dummy/Delay configuration for data phase.
@ -60,6 +62,25 @@ class NTCP2Options {
xsDummy, xrDummy, xsDelay, xrDelay);
}
/**
* @since 0.9.37 consolidated from two places
* @return null on error
*/
public static NTCP2Options fromByteArray(byte[] options) {
if (options.length < 12)
return null;
float tmin = (options[0] & 0xff) / 16.0f;
float tmax = (options[1] & 0xff) / 16.0f;
float rmin = (options[2] & 0xff) / 16.0f;
float rmax = (options[3] & 0xff) / 16.0f;
int tdummy = (int) DataHelper.fromLong(options, 4, 2);
int rdummy = (int) DataHelper.fromLong(options, 6, 2);
int tdelay = (int) DataHelper.fromLong(options, 8, 2);
int rdelay = (int) DataHelper.fromLong(options, 10, 2);
return new NTCP2Options(tmin, tmax, rmin, rmax,
tdummy, rdummy, tdelay, rdelay);
}
@Override
public String toString() {
return "Padding options: send min/max %: (" + (_sendMin * 100) + ", " + (_sendMax * 100) +

View File

@ -2131,21 +2131,12 @@ public class NTCPConnection implements Closeable {
}
public void gotOptions(byte[] options, boolean isHandshake) {
if (options.length < 12) {
NTCP2Options hisPadding = NTCP2Options.fromByteArray(options);
if (hisPadding == null) {
if (_log.shouldWarn())
_log.warn("Got options length " + options.length + " on: " + this);
return;
}
float tmin = (options[0] & 0xff) / 16.0f;
float tmax = (options[1] & 0xff) / 16.0f;
float rmin = (options[2] & 0xff) / 16.0f;
float rmax = (options[3] & 0xff) / 16.0f;
int tdummy = (int) DataHelper.fromLong(options, 4, 2);
int rdummy = (int) DataHelper.fromLong(options, 6, 2);
int tdelay = (int) DataHelper.fromLong(options, 8, 2);
int rdelay = (int) DataHelper.fromLong(options, 10, 2);
NTCP2Options hisPadding = new NTCP2Options(tmin, tmax, rmin, rmax,
tdummy, rdummy, tdelay, rdelay);
_paddingConfig = OUR_PADDING.merge(hisPadding);
if (_log.shouldDebug())
_log.debug("Got padding options:" +

View File

@ -273,7 +273,9 @@ public class NTCPTransport extends TransportImpl {
}
if (iv == null || iv.length != NTCP2_IV_LEN) {
iv = new byte[NTCP2_IV_LEN];
ctx.random().nextBytes(iv);
do {
ctx.random().nextBytes(iv);
} while (DataHelper.eq(iv, 0, OutboundNTCP2State.ZEROKEY, 0, NTCP2_IV_LEN));
shouldSave = true;
}
if (shouldSave) {