mirror of https://github.com/rusefi/rusefi-1.git
usability
This commit is contained in:
parent
361c33009a
commit
78a244f25e
|
@ -244,7 +244,8 @@ public class rusEFI extends Activity {
|
||||||
mResultView.post(() -> mResultView.append("On connection established\n"));
|
mResultView.post(() -> mResultView.append("On connection established\n"));
|
||||||
|
|
||||||
NetworkConnectorContext context = new NetworkConnectorContext();
|
NetworkConnectorContext context = new NetworkConnectorContext();
|
||||||
new NetworkConnector().start(getAuthToken(), context, new NetworkConnector.ReconnectListener() {
|
new NetworkConnector().start(NetworkConnector.Implementation.Android,
|
||||||
|
getAuthToken(), context, new NetworkConnector.ReconnectListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onReconnect() {
|
public void onReconnect() {
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ public class NetworkConnector implements Closeable {
|
||||||
private final static Logging log = Logging.getLogging(NetworkConnector.class);
|
private final static Logging log = Logging.getLogging(NetworkConnector.class);
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
|
||||||
public NetworkConnectorResult start(String authToken, String controllerPort, NetworkConnectorContext context) {
|
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context) {
|
||||||
return start(authToken, controllerPort, context, ReconnectListener.VOID);
|
return start(implementation, authToken, controllerPort, context, ReconnectListener.VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkConnectorResult start(String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) {
|
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) {
|
||||||
LinkManager controllerConnector = new LinkManager()
|
LinkManager controllerConnector = new LinkManager()
|
||||||
.setCompositeLogicEnabled(false)
|
.setCompositeLogicEnabled(false)
|
||||||
.setNeedPullData(false);
|
.setNeedPullData(false);
|
||||||
|
@ -67,10 +67,10 @@ public class NetworkConnector implements Closeable {
|
||||||
return NetworkConnectorResult.ERROR;
|
return NetworkConnectorResult.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return start(authToken, context, reconnectListener, controllerConnector);
|
return start(implementation, authToken, context, reconnectListener, controllerConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkConnectorResult start(String authToken, NetworkConnectorContext context, ReconnectListener reconnectListener, LinkManager linkManager) {
|
public NetworkConnectorResult start(Implementation implementation, String authToken, NetworkConnectorContext context, ReconnectListener reconnectListener, LinkManager linkManager) {
|
||||||
ControllerInfo controllerInfo;
|
ControllerInfo controllerInfo;
|
||||||
try {
|
try {
|
||||||
controllerInfo = getControllerInfo(linkManager, linkManager.getConnector().getBinaryProtocol().getStream());
|
controllerInfo = getControllerInfo(linkManager, linkManager.getConnector().getBinaryProtocol().getStream());
|
||||||
|
@ -87,7 +87,8 @@ public class NetworkConnector implements Closeable {
|
||||||
proxyReconnectSemaphore.acquire();
|
proxyReconnectSemaphore.acquire();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
start(context.serverPortForControllers(), linkManager, authToken, (String message) -> {
|
start(implementation,
|
||||||
|
context.serverPortForControllers(), linkManager, authToken, (String message) -> {
|
||||||
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
||||||
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
||||||
log.debug("Releasing semaphore");
|
log.debug("Releasing semaphore");
|
||||||
|
@ -107,10 +108,10 @@ public class NetworkConnector implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static SessionDetails start(int serverPortForControllers, LinkManager linkManager, String authToken, final TcpIoStream.DisconnectListener disconnectListener, int oneTimeToken, ControllerInfo controllerInfo, final NetworkConnectorContext context) throws IOException {
|
private static SessionDetails start(Implementation implementation, int serverPortForControllers, LinkManager linkManager, String authToken, final TcpIoStream.DisconnectListener disconnectListener, int oneTimeToken, ControllerInfo controllerInfo, final NetworkConnectorContext context) throws IOException {
|
||||||
IoStream targetEcuSocket = linkManager.getConnector().getBinaryProtocol().getStream();
|
IoStream targetEcuSocket = linkManager.getConnector().getBinaryProtocol().getStream();
|
||||||
|
|
||||||
SessionDetails deviceSessionDetails = new SessionDetails(controllerInfo, authToken, oneTimeToken, rusEFIVersion.CONSOLE_VERSION);
|
SessionDetails deviceSessionDetails = new SessionDetails(implementation, controllerInfo, authToken, oneTimeToken, rusEFIVersion.CONSOLE_VERSION);
|
||||||
|
|
||||||
Socket socket;
|
Socket socket;
|
||||||
try {
|
try {
|
||||||
|
@ -201,4 +202,18 @@ public class NetworkConnector implements Closeable {
|
||||||
void onReconnect();
|
void onReconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Implementation {
|
||||||
|
Android,
|
||||||
|
Plugin,
|
||||||
|
SBC,
|
||||||
|
Unknown;
|
||||||
|
|
||||||
|
public static Implementation find(String name) {
|
||||||
|
for (Implementation implementation : values()) {
|
||||||
|
if (implementation.name().equalsIgnoreCase(name))
|
||||||
|
return implementation;
|
||||||
|
}
|
||||||
|
return Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.server;
|
package com.rusefi.server;
|
||||||
|
|
||||||
|
import com.rusefi.proxy.NetworkConnector;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ public class SessionDetails {
|
||||||
public static final String VEHICLE_TOKEN = "vehicleToken";
|
public static final String VEHICLE_TOKEN = "vehicleToken";
|
||||||
public static final String AUTH_TOKEN = "authToken";
|
public static final String AUTH_TOKEN = "authToken";
|
||||||
public static final String CONNECTOR_VERSION = "connectorVersion";
|
public static final String CONNECTOR_VERSION = "connectorVersion";
|
||||||
|
public static final String IMPLEMENTATION = "implementation";
|
||||||
|
|
||||||
private static final String CONTROLLER = "controller";
|
private static final String CONTROLLER = "controller";
|
||||||
private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE");
|
private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE");
|
||||||
|
|
||||||
|
@ -20,9 +23,11 @@ public class SessionDetails {
|
||||||
|
|
||||||
private final int vehicleToken;
|
private final int vehicleToken;
|
||||||
private final String authToken;
|
private final String authToken;
|
||||||
|
private final NetworkConnector.Implementation implementation;
|
||||||
private final int consoleVersion;
|
private final int consoleVersion;
|
||||||
|
|
||||||
public SessionDetails(ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion) {
|
public SessionDetails(NetworkConnector.Implementation implementation, ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion) {
|
||||||
|
this.implementation = Objects.requireNonNull(implementation);
|
||||||
this.consoleVersion = consoleVersion;
|
this.consoleVersion = consoleVersion;
|
||||||
Objects.requireNonNull(controllerInfo);
|
Objects.requireNonNull(controllerInfo);
|
||||||
Objects.requireNonNull(authToken);
|
Objects.requireNonNull(authToken);
|
||||||
|
@ -35,6 +40,10 @@ public class SessionDetails {
|
||||||
return HARDCODED_ONE_TIME_CODE == null ? new Random().nextInt(100000) : Integer.parseInt(HARDCODED_ONE_TIME_CODE);
|
return HARDCODED_ONE_TIME_CODE == null ? new Random().nextInt(100000) : Integer.parseInt(HARDCODED_ONE_TIME_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NetworkConnector.Implementation getImplementation() {
|
||||||
|
return implementation;
|
||||||
|
}
|
||||||
|
|
||||||
public int getOneTimeToken() {
|
public int getOneTimeToken() {
|
||||||
return vehicleToken;
|
return vehicleToken;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +66,7 @@ public class SessionDetails {
|
||||||
jsonObject.put(VEHICLE_TOKEN, vehicleToken);
|
jsonObject.put(VEHICLE_TOKEN, vehicleToken);
|
||||||
jsonObject.put(AUTH_TOKEN, authToken);
|
jsonObject.put(AUTH_TOKEN, authToken);
|
||||||
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
||||||
|
jsonObject.put(IMPLEMENTATION, implementation.name());
|
||||||
return jsonObject.toJSONString();
|
return jsonObject.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +76,11 @@ public class SessionDetails {
|
||||||
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
||||||
long oneTimeCode = (Long)jsonObject.get(VEHICLE_TOKEN);
|
long oneTimeCode = (Long)jsonObject.get(VEHICLE_TOKEN);
|
||||||
long connectorVersion = (long) jsonObject.get(CONNECTOR_VERSION);
|
long connectorVersion = (long) jsonObject.get(CONNECTOR_VERSION);
|
||||||
|
NetworkConnector.Implementation implementation = NetworkConnector.Implementation.find((String) jsonObject.get(IMPLEMENTATION));
|
||||||
|
|
||||||
ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER));
|
ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER));
|
||||||
|
|
||||||
return new SessionDetails(controllerInfo, authToken, (int) oneTimeCode, (int) connectorVersion);
|
return new SessionDetails(implementation, controllerInfo, authToken, (int) oneTimeCode, (int) connectorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
|
import com.rusefi.proxy.NetworkConnector;
|
||||||
import com.rusefi.server.ControllerInfo;
|
import com.rusefi.server.ControllerInfo;
|
||||||
import com.rusefi.server.SessionDetails;
|
import com.rusefi.server.SessionDetails;
|
||||||
import com.rusefi.server.rusEFISSLContext;
|
import com.rusefi.server.rusEFISSLContext;
|
||||||
|
@ -99,7 +100,7 @@ public class TestHelper {
|
||||||
public static SessionDetails createTestSession(String authToken, String signature) {
|
public static SessionDetails createTestSession(String authToken, String signature) {
|
||||||
ControllerInfo ci = new ControllerInfo("vehicle", "make", "code", signature);
|
ControllerInfo ci = new ControllerInfo("vehicle", "make", "code", signature);
|
||||||
|
|
||||||
return new SessionDetails(ci, authToken, SessionDetails.createOneTimeCode(), rusEFIVersion.CONSOLE_VERSION);
|
return new SessionDetails(NetworkConnector.Implementation.Unknown, ci, authToken, SessionDetails.createOneTimeCode(), rusEFIVersion.CONSOLE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertLatch(String message, CountDownLatch reconnectCounter) throws InterruptedException {
|
public static void assertLatch(String message, CountDownLatch reconnectCounter) throws InterruptedException {
|
||||||
|
|
|
@ -24,7 +24,8 @@ public class NetworkConnectorStartup {
|
||||||
|
|
||||||
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
|
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
|
||||||
|
|
||||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(authToken, autoDetectedPort, connectorContext);
|
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC,
|
||||||
|
authToken, autoDetectedPort, connectorContext);
|
||||||
log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken());
|
log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,12 +110,13 @@ public class FullServerTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
// start "rusEFI network connector" to connect controller with backend since in real life controller has only local serial port it does not have network
|
// start "rusEFI network connector" to connect controller with backend since in real life controller has only local serial port it does not have network
|
||||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = networkConnector.start(TestHelper.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, networkConnectorContext, NetworkConnector.ReconnectListener.VOID);
|
NetworkConnector.NetworkConnectorResult networkConnectorResult = networkConnector.start(NetworkConnector.Implementation.Unknown,
|
||||||
|
TestHelper.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, networkConnectorContext, NetworkConnector.ReconnectListener.VOID);
|
||||||
ControllerInfo controllerInfo = networkConnectorResult.getControllerInfo();
|
ControllerInfo controllerInfo = networkConnectorResult.getControllerInfo();
|
||||||
|
|
||||||
TestHelper.assertLatch("controllerRegistered", controllerRegistered);
|
TestHelper.assertLatch("controllerRegistered", controllerRegistered);
|
||||||
|
|
||||||
SessionDetails authenticatorSessionDetails = new SessionDetails(controllerInfo, TEST_TOKEN_3, networkConnectorResult.getOneTimeToken(), rusEFIVersion.CONSOLE_VERSION);
|
SessionDetails authenticatorSessionDetails = new SessionDetails(NetworkConnector.Implementation.Unknown, controllerInfo, TEST_TOKEN_3, networkConnectorResult.getOneTimeToken(), rusEFIVersion.CONSOLE_VERSION);
|
||||||
ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userDetailsResolver.apply(TestHelper.TEST_TOKEN_1));
|
ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userDetailsResolver.apply(TestHelper.TEST_TOKEN_1));
|
||||||
|
|
||||||
// start authenticator
|
// start authenticator
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class NetworkConnectorTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
NetworkConnector networkConnector = new NetworkConnector();
|
NetworkConnector networkConnector = new NetworkConnector();
|
||||||
networkConnector.start(TestHelper.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, connectorContext, reconnectListener);
|
networkConnector.start(NetworkConnector.Implementation.Unknown, TestHelper.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, connectorContext, reconnectListener);
|
||||||
|
|
||||||
assertLatch(reconnectCounter);
|
assertLatch(reconnectCounter);
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,7 @@ public class Backend implements Closeable {
|
||||||
.add(ControllerInfo.VEHICLE_NAME, controllerInfo.getVehicleName())
|
.add(ControllerInfo.VEHICLE_NAME, controllerInfo.getVehicleName())
|
||||||
.add(ControllerInfo.ENGINE_MAKE, controllerInfo.getEngineMake())
|
.add(ControllerInfo.ENGINE_MAKE, controllerInfo.getEngineMake())
|
||||||
.add(ControllerInfo.ENGINE_CODE, controllerInfo.getEngineCode())
|
.add(ControllerInfo.ENGINE_CODE, controllerInfo.getEngineCode())
|
||||||
|
.add(SessionDetails.IMPLEMENTATION, sessionDetails.getImplementation().name())
|
||||||
.add(SessionDetails.CONNECTOR_VERSION, sessionDetails.getConsoleVersion());
|
.add(SessionDetails.CONNECTOR_VERSION, sessionDetails.getConsoleVersion());
|
||||||
objectBuilder = addStreamStats(objectBuilder, client.getStream());
|
objectBuilder = addStreamStats(objectBuilder, client.getStream());
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi.server;
|
package com.rusefi.server;
|
||||||
|
|
||||||
import com.rusefi.TestHelper;
|
import com.rusefi.TestHelper;
|
||||||
|
import com.rusefi.proxy.NetworkConnector;
|
||||||
import com.rusefi.rusEFIVersion;
|
import com.rusefi.rusEFIVersion;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ public class SessionDetailsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() {
|
public void testSerialization() {
|
||||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
SessionDetails sd = new SessionDetails(NetworkConnector.Implementation.Unknown, TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
||||||
|
|
||||||
String json = sd.toJson();
|
String json = sd.toJson();
|
||||||
SessionDetails fromJson = SessionDetails.valueOf(json);
|
SessionDetails fromJson = SessionDetails.valueOf(json);
|
||||||
|
@ -19,7 +20,7 @@ public class SessionDetailsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplicationRequest() {
|
public void testApplicationRequest() {
|
||||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
SessionDetails sd = new SessionDetails(NetworkConnector.Implementation.Unknown, TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
||||||
ApplicationRequest ar = new ApplicationRequest(sd, new UserDetails("", 321));
|
ApplicationRequest ar = new ApplicationRequest(sd, new UserDetails("", 321));
|
||||||
|
|
||||||
String json = ar.toJson();
|
String json = ar.toJson();
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class BroadcastTab {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
networkConnector = new NetworkConnector();
|
networkConnector = new NetworkConnector();
|
||||||
|
|
||||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = networkConnector.start(authToken, autoDetectedPort, connectorContext);
|
NetworkConnector.NetworkConnectorResult networkConnectorResult = networkConnector.start(NetworkConnector.Implementation.Plugin, authToken, autoDetectedPort, connectorContext);
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> status.setText("One time password to connect to this ECU: " + networkConnectorResult.getOneTimeToken()));
|
SwingUtilities.invokeLater(() -> status.setText("One time password to connect to this ECU: " + networkConnectorResult.getOneTimeToken()));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue