NDT: Fix JSON encoding of extended login (ticket #2672)

Disable middlebox and firewall tests
Don't NPE if no middlebox test
Change version to match measurement-kit
Don't prefer IPv6, it is unreliable
Disable SSL by default, unreliable
Add 30s timeout to initial handshake to prevent long hangs on SSL
This commit is contained in:
zzz
2019-12-03 14:57:32 +00:00
parent f2f29d6a6c
commit 9289a6daa9
5 changed files with 56 additions and 9 deletions

View File

@ -53,7 +53,8 @@ public class MLabRunner {
// use ndt_ssl for test over ssl
private static final String NS_URL_SSL_SSL = "https://mlab-ns.appspot.com/ndt_ssl?format=json";
private static final String PROP_SSL = "routerconsole.bwtest.useSSL";
private static final boolean DEFAULT_USE_SSL = true;
// SSL hangs far too often
private static final boolean DEFAULT_USE_SSL = false;
private static final long NS_TIMEOUT = 20*1000;
private final I2PAppContext _context;
private final Log _log;

View File

@ -68,4 +68,18 @@ public class JSONUtils {
return obj.toJSONString().getBytes();
}
/**
* Function that return json object represented by jsontext and included
* single message assigned to "msg" key
* @param msg {byte[]} message which should be assigned to json object
* @return {byte[]} json object represented by jsontext and encodes into a sequence of bytes
* @since 0.9.45
*/
public static byte[] createJsonLoginObj(byte[] msg, byte tests) {
JSONObject obj = new JSONObject();
obj.put("msg", new String(msg));
obj.put("tests", Integer.toString(tests & 0xff));
return obj.toJSONString().getBytes();
}
}

View File

@ -44,10 +44,11 @@ public class NDTConstants {
/*
* TODO for a later release: Version could be moved to some "configurable"
* or "property" area instead of being in code that needs compilation.
* Changed to match https://github.com/measurement-kit/measurement-kit/blob/master/src/libmeasurement_kit/ndt/internal.hpp
*/
public static final String VERSION = "3.7.0";
public static final String VERSION = "v3.7.0";
public static final String NDT_TITLE_STR = "Network Diagnostic Tool Client v";
public static final String NDT_TITLE_STR = "Network Diagnostic Tool Client ";
// Section: Test type
public static final byte TEST_MID = (1 << 0);

View File

@ -82,6 +82,29 @@ public class Protocol {
}
}
/**
* Send protocol messages given their type and data byte array
*
* @param bParamType
* Control Message Type
* @param bParamToSend
* Data value array to send
* @throws IOException
* If data cannot be successfully written to the Output Stream
*
* @since 0.9.45
* */
public void send_json_login_msg(byte bParamType, byte[] bParamToSend)
throws IOException {
if (jsonSupport) {
byte[] ver = new byte[bParamToSend.length - 1];
System.arraycopy(bParamToSend, 1, ver, 0, ver.length);
send_msg(bParamType, JSONUtils.createJsonLoginObj(bParamToSend, bParamToSend[0]));
} else {
send_msg(bParamType, bParamToSend);
}
}
/**
* Send protocol messages given their type and data byte array
*

View File

@ -232,8 +232,8 @@ public class Tcpbw100 extends JApplet implements ActionListener {
String sHostName = null;
InetAddress hostAddress = null;
String _sTestResults, _sMidBoxTestResult;
byte _yTests = NDTConstants.TEST_MID | NDTConstants.TEST_C2S
| NDTConstants.TEST_S2C | NDTConstants.TEST_SFW
byte _yTests = /* NDTConstants.TEST_MID | */ NDTConstants.TEST_C2S
| NDTConstants.TEST_S2C /* | NDTConstants.TEST_SFW */
| NDTConstants.TEST_STATUS | NDTConstants.TEST_META;
int _iC2sSFWResult = NDTConstants.SFW_NOTTESTED;
int _iS2cSFWResult = NDTConstants.SFW_NOTTESTED;
@ -940,7 +940,9 @@ public class Tcpbw100 extends JApplet implements ActionListener {
_chkboxPreferIPv6 = new JCheckBox(
_resBundDisplayMsgs.getString("preferIPv6"));
// I2P
_chkboxPreferIPv6.setSelected(Addresses.isConnectedIPv6());
// IPv6 unreliable, only prefer if we don't have a IPv4 address
//_chkboxPreferIPv6.setSelected(Addresses.isConnectedIPv6());
_chkboxPreferIPv6.setSelected(!Addresses.isConnected());
_chkboxPreferIPv6.addActionListener(this);
// 2. Conduct default tests?
_chkboxDefaultTest = new JCheckBox(
@ -2567,7 +2569,12 @@ public class Tcpbw100 extends JApplet implements ActionListener {
send[0] = _yTests;
System.arraycopy(NDTConstants.VERSION.getBytes(), 0, send, 1, NDTConstants.VERSION.length());
protocolObj.send_json_msg(MessageType.MSG_EXTENDED_LOGIN, send);
// I2P - adds tests as "tests" in json
// https://github.com/measurement-kit/measurement-kit/blob/master/src/libmeasurement_kit/ndt/messages.cpp
//protocolObj.send_json_msg(MessageType.MSG_EXTENDED_LOGIN, send);
protocolObj.send_json_login_msg(MessageType.MSG_EXTENDED_LOGIN, send);
// SSL in particular will hang here for several minutes
ctlSocket.setSoTimeout(30*1000);
// read the specially crafted data that kicks off the old clients
if (protocolObj.readn(msg, 13) != 13) {
@ -2577,6 +2584,7 @@ public class Tcpbw100 extends JApplet implements ActionListener {
try { ctlSocket.close(); } catch (IOException ioe) {}
return;
}
ctlSocket.setSoTimeout(60*1000);
for (;;) {
@ -2988,7 +2996,7 @@ public class Tcpbw100 extends JApplet implements ActionListener {
_resultsTxtPane.append(ex + "\n");
}
// interpret middlebox test results
if ((_yTests & NDTConstants.TEST_MID) == NDTConstants.TEST_MID) {
if (_sMidBoxTestResult != null && (_yTests & NDTConstants.TEST_MID) == NDTConstants.TEST_MID) {
middleboxResults(_sMidBoxTestResult);
}
@ -4478,7 +4486,7 @@ public class Tcpbw100 extends JApplet implements ActionListener {
return Integer.parseInt(msg, radix);
}
} catch (NumberFormatException nfe) {
_log.warn("parse", nfe);
_log.warn("parse input: \"" + msg + '"', nfe);
return 0;
}
}