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"));
|
||||
|
||||
NetworkConnectorContext context = new NetworkConnectorContext();
|
||||
new NetworkConnector().start(getAuthToken(), context, new NetworkConnector.ReconnectListener() {
|
||||
new NetworkConnector().start(NetworkConnector.Implementation.Android,
|
||||
getAuthToken(), context, new NetworkConnector.ReconnectListener() {
|
||||
@Override
|
||||
public void onReconnect() {
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ public class NetworkConnector implements Closeable {
|
|||
private final static Logging log = Logging.getLogging(NetworkConnector.class);
|
||||
private boolean isClosed;
|
||||
|
||||
public NetworkConnectorResult start(String authToken, String controllerPort, NetworkConnectorContext context) {
|
||||
return start(authToken, controllerPort, context, ReconnectListener.VOID);
|
||||
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context) {
|
||||
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()
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
@ -67,10 +67,10 @@ public class NetworkConnector implements Closeable {
|
|||
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;
|
||||
try {
|
||||
controllerInfo = getControllerInfo(linkManager, linkManager.getConnector().getBinaryProtocol().getStream());
|
||||
|
@ -87,13 +87,14 @@ public class NetworkConnector implements Closeable {
|
|||
proxyReconnectSemaphore.acquire();
|
||||
|
||||
try {
|
||||
start(context.serverPortForControllers(), linkManager, authToken, (String message) -> {
|
||||
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
||||
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
||||
log.debug("Releasing semaphore");
|
||||
proxyReconnectSemaphore.release();
|
||||
reconnectListener.onReconnect();
|
||||
}, vehicleToken, controllerInfo, context);
|
||||
start(implementation,
|
||||
context.serverPortForControllers(), linkManager, authToken, (String message) -> {
|
||||
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
||||
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
||||
log.debug("Releasing semaphore");
|
||||
proxyReconnectSemaphore.release();
|
||||
reconnectListener.onReconnect();
|
||||
}, vehicleToken, controllerInfo, context);
|
||||
} catch (IOException e) {
|
||||
log.error("IO error", e);
|
||||
}
|
||||
|
@ -107,10 +108,10 @@ public class NetworkConnector implements Closeable {
|
|||
}
|
||||
|
||||
@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();
|
||||
|
||||
SessionDetails deviceSessionDetails = new SessionDetails(controllerInfo, authToken, oneTimeToken, rusEFIVersion.CONSOLE_VERSION);
|
||||
SessionDetails deviceSessionDetails = new SessionDetails(implementation, controllerInfo, authToken, oneTimeToken, rusEFIVersion.CONSOLE_VERSION);
|
||||
|
||||
Socket socket;
|
||||
try {
|
||||
|
@ -201,4 +202,18 @@ public class NetworkConnector implements Closeable {
|
|||
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;
|
||||
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
|
@ -13,6 +14,8 @@ public class SessionDetails {
|
|||
public static final String VEHICLE_TOKEN = "vehicleToken";
|
||||
public static final String AUTH_TOKEN = "authToken";
|
||||
public static final String CONNECTOR_VERSION = "connectorVersion";
|
||||
public static final String IMPLEMENTATION = "implementation";
|
||||
|
||||
private static final String CONTROLLER = "controller";
|
||||
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 String authToken;
|
||||
private final NetworkConnector.Implementation implementation;
|
||||
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;
|
||||
Objects.requireNonNull(controllerInfo);
|
||||
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);
|
||||
}
|
||||
|
||||
public NetworkConnector.Implementation getImplementation() {
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public int getOneTimeToken() {
|
||||
return vehicleToken;
|
||||
}
|
||||
|
@ -57,6 +66,7 @@ public class SessionDetails {
|
|||
jsonObject.put(VEHICLE_TOKEN, vehicleToken);
|
||||
jsonObject.put(AUTH_TOKEN, authToken);
|
||||
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
||||
jsonObject.put(IMPLEMENTATION, implementation.name());
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
@ -66,10 +76,11 @@ public class SessionDetails {
|
|||
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
||||
long oneTimeCode = (Long)jsonObject.get(VEHICLE_TOKEN);
|
||||
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
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.rusefi.io.LinkConnector;
|
|||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
import com.rusefi.server.rusEFISSLContext;
|
||||
|
@ -99,7 +100,7 @@ public class TestHelper {
|
|||
public static SessionDetails createTestSession(String authToken, String 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 {
|
||||
|
|
|
@ -24,7 +24,8 @@ public class NetworkConnectorStartup {
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
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();
|
||||
|
||||
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));
|
||||
|
||||
// start authenticator
|
||||
|
|
|
@ -76,7 +76,7 @@ public class NetworkConnectorTest {
|
|||
}
|
||||
};
|
||||
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);
|
||||
|
||||
|
|
|
@ -317,6 +317,7 @@ public class Backend implements Closeable {
|
|||
.add(ControllerInfo.VEHICLE_NAME, controllerInfo.getVehicleName())
|
||||
.add(ControllerInfo.ENGINE_MAKE, controllerInfo.getEngineMake())
|
||||
.add(ControllerInfo.ENGINE_CODE, controllerInfo.getEngineCode())
|
||||
.add(SessionDetails.IMPLEMENTATION, sessionDetails.getImplementation().name())
|
||||
.add(SessionDetails.CONNECTOR_VERSION, sessionDetails.getConsoleVersion());
|
||||
objectBuilder = addStreamStats(objectBuilder, client.getStream());
|
||||
if (owner != null) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.rusefi.TestHelper;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -10,7 +11,7 @@ public class SessionDetailsTest {
|
|||
|
||||
@Test
|
||||
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();
|
||||
SessionDetails fromJson = SessionDetails.valueOf(json);
|
||||
|
@ -19,7 +20,7 @@ public class SessionDetailsTest {
|
|||
|
||||
@Test
|
||||
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));
|
||||
|
||||
String json = ar.toJson();
|
||||
|
|
|
@ -113,7 +113,7 @@ public class BroadcastTab {
|
|||
new Thread(() -> {
|
||||
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()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue