REO progress
This commit is contained in:
parent
5cdfcc41d6
commit
12bb4f9275
|
@ -1 +1,7 @@
|
|||
java -jar console/rusefi_console.jar network_connector
|
||||
#!/bin/bash
|
||||
while true
|
||||
do
|
||||
java -jar console/rusefi_console.jar network_connector
|
||||
exit_status=$?
|
||||
echo Exit code: ${exit_status}
|
||||
done
|
|
@ -11,9 +11,11 @@ import com.rusefi.io.LinkManager;
|
|||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
import com.rusefi.server.rusEFISSLContext;
|
||||
import com.rusefi.tools.VehicleToken;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -69,7 +71,7 @@ public class NetworkConnector implements Closeable {
|
|||
return NetworkConnectorResult.ERROR;
|
||||
}
|
||||
|
||||
int oneTimeToken = SessionDetails.createOneTimeCode();
|
||||
int vehicleToken = VehicleToken.getOrCreate();
|
||||
|
||||
BinaryProtocolServer.getThreadFactory("Proxy Reconnect").newThread(() -> {
|
||||
Semaphore proxyReconnectSemaphore = new Semaphore(1);
|
||||
|
@ -84,7 +86,7 @@ public class NetworkConnector implements Closeable {
|
|||
log.debug("Releasing semaphore");
|
||||
proxyReconnectSemaphore.release();
|
||||
reconnectListener.onReconnect();
|
||||
}, oneTimeToken, controllerInfo, context);
|
||||
}, vehicleToken, controllerInfo, context);
|
||||
} catch (IOException e) {
|
||||
log.error("IO error", e);
|
||||
}
|
||||
|
@ -94,14 +96,14 @@ public class NetworkConnector implements Closeable {
|
|||
}
|
||||
}).start();
|
||||
|
||||
return new NetworkConnectorResult(controllerInfo, oneTimeToken);
|
||||
return new NetworkConnectorResult(controllerInfo, vehicleToken);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SessionDetails start(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);
|
||||
SessionDetails deviceSessionDetails = new SessionDetails(controllerInfo, authToken, oneTimeToken, rusEFIVersion.CONSOLE_VERSION);
|
||||
|
||||
Socket socket;
|
||||
try {
|
||||
|
|
|
@ -13,14 +13,17 @@ public class SessionDetails {
|
|||
private static final String ONE_TIME_TOKEN = "oneTime";
|
||||
private static final String AUTH_TOKEN = "authToken";
|
||||
private static final String CONTROLLER = "controller";
|
||||
private static final String CONNECTOR_VERSION = "connectorVersion";
|
||||
private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE");
|
||||
|
||||
private final ControllerInfo controllerInfo;
|
||||
|
||||
private final int oneTimeToken;
|
||||
private final String authToken;
|
||||
private final int consoleVersion;
|
||||
|
||||
public SessionDetails(ControllerInfo controllerInfo, String authToken, int oneTimeCode) {
|
||||
public SessionDetails(ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion) {
|
||||
this.consoleVersion = consoleVersion;
|
||||
Objects.requireNonNull(controllerInfo);
|
||||
Objects.requireNonNull(authToken);
|
||||
this.controllerInfo = controllerInfo;
|
||||
|
@ -49,6 +52,7 @@ public class SessionDetails {
|
|||
jsonObject.put(CONTROLLER, controllerInfo.toJson());
|
||||
jsonObject.put(ONE_TIME_TOKEN, oneTimeToken);
|
||||
jsonObject.put(AUTH_TOKEN, authToken);
|
||||
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
@ -57,10 +61,11 @@ public class SessionDetails {
|
|||
|
||||
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
||||
long oneTimeCode = (Long)jsonObject.get(ONE_TIME_TOKEN);
|
||||
long connectorVersion = (long) jsonObject.get(CONNECTOR_VERSION);
|
||||
|
||||
ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER));
|
||||
|
||||
return new SessionDetails(controllerInfo, authToken, (int) oneTimeCode);
|
||||
return new SessionDetails(controllerInfo, authToken, (int) oneTimeCode, (int) connectorVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.rusefi.tools;
|
||||
|
||||
import com.rusefi.server.SessionDetails;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
|
||||
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
public class VehicleToken {
|
||||
private static final String VEHICLE_TOKEN = "VEHICLE_TOKEN";
|
||||
|
||||
public static int getOrCreate() {
|
||||
String value = getConfig().getRoot().getProperty(VEHICLE_TOKEN, null);
|
||||
if (value == null || !Node.isNumeric(value)) {
|
||||
value = Integer.toString(SessionDetails.createOneTimeCode());
|
||||
getConfig().getRoot().setProperty(VEHICLE_TOKEN, value);
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
}
|
|
@ -99,7 +99,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());
|
||||
return new SessionDetails(ci, authToken, SessionDetails.createOneTimeCode(), rusEFIVersion.CONSOLE_VERSION);
|
||||
}
|
||||
|
||||
public static void assertLatch(String message, CountDownLatch reconnectCounter) throws InterruptedException {
|
||||
|
|
|
@ -65,7 +65,8 @@ public class ConsoleTools {
|
|||
registerTool("network_authenticator", strings -> LocalApplicationProxy.start(), "rusEFI Online Authenticator");
|
||||
|
||||
registerTool("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token.");
|
||||
registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token.");
|
||||
registerTool("print_vehicle_token", args -> printVehicleToken(), "Prints vehicle access token.");
|
||||
registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI Online authentication token.");
|
||||
registerTool("upload_tune", ConsoleTools::uploadTune, "Upload specified tune file to rusEFI Online using auth token from settings");
|
||||
|
||||
registerTool("read_tune", args -> readTune(), "Read tune from controller");
|
||||
|
@ -173,6 +174,11 @@ public class ConsoleTools {
|
|||
AuthTokenPanel.setAuthToken(newToken);
|
||||
}
|
||||
|
||||
private static void printVehicleToken() {
|
||||
int vehicleToken = VehicleToken.getOrCreate();
|
||||
System.out.println("Vehicle token: " + vehicleToken);
|
||||
}
|
||||
|
||||
private static void printAuthToken() {
|
||||
String authToken = AuthTokenPanel.getAuthToken();
|
||||
if (authToken.trim().isEmpty()) {
|
||||
|
|
|
@ -107,7 +107,7 @@ public class FullServerTest {
|
|||
|
||||
TestHelper.assertLatch("controllerRegistered", controllerRegistered);
|
||||
|
||||
SessionDetails authenticatorSessionDetails = new SessionDetails(controllerInfo, TEST_TOKEN_3, networkConnectorResult.getOneTimeToken());
|
||||
SessionDetails authenticatorSessionDetails = new SessionDetails(controllerInfo, TEST_TOKEN_3, networkConnectorResult.getOneTimeToken(), rusEFIVersion.CONSOLE_VERSION);
|
||||
ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userDetailsResolver.apply(TestHelper.TEST_TOKEN_1));
|
||||
|
||||
// start authenticator
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.rusefi.TestHelper;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -9,7 +10,7 @@ public class SessionDetailsTest {
|
|||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123);
|
||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
||||
|
||||
String json = sd.toJson();
|
||||
SessionDetails fromJson = SessionDetails.valueOf(json);
|
||||
|
@ -18,7 +19,7 @@ public class SessionDetailsTest {
|
|||
|
||||
@Test
|
||||
public void testApplicationRequest() {
|
||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123);
|
||||
SessionDetails sd = new SessionDetails(TestHelper.CONTROLLER_INFO, "auth", 123, rusEFIVersion.CONSOLE_VERSION);
|
||||
ApplicationRequest ar = new ApplicationRequest(sd, new UserDetails("", 321));
|
||||
|
||||
String json = ar.toJson();
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.rusefi.io.tcp.ServerSocketReference;
|
|||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxy;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxyContextImpl;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
import com.rusefi.server.ApplicationRequest;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
|
@ -225,7 +226,7 @@ public class RemoteTab {
|
|||
|
||||
private void runAuthenticator(PublicSession publicSession, ControllerInfo controllerInfo, LocalApplicationProxy.ConnectionListener connectionListener) {
|
||||
SessionDetails sessionDetails = new SessionDetails(controllerInfo, AuthTokenPanel.getAuthToken(),
|
||||
Integer.parseInt(oneTimePasswordControl.getText()));
|
||||
Integer.parseInt(oneTimePasswordControl.getText()), rusEFIVersion.CONSOLE_VERSION);
|
||||
|
||||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, publicSession.getUserDetails());
|
||||
|
||||
|
|
Loading…
Reference in New Issue