diff --git a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnector.java b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnector.java index 52dcbabed3..10c8b4d675 100644 --- a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnector.java +++ b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnector.java @@ -40,7 +40,12 @@ public class NetworkConnector implements Closeable { private boolean isClosed; public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context) { - return start(implementation, authToken, controllerPort, context, ReconnectListener.VOID); + return start(implementation, authToken, controllerPort, context, new ReconnectListener() { + @Override + public void onReconnect() { + log.info("onReconnect"); + } + }); } public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) { diff --git a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java index fd35cb90b6..9ff8c7ef34 100644 --- a/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java +++ b/java_console/io/src/main/java/com/rusefi/proxy/NetworkConnectorContext.java @@ -10,7 +10,7 @@ import static com.devexperts.logging.Logging.getLogging; public class NetworkConnectorContext { private static final Logging log = getLogging(NetworkConnectorContext.class); private static final int UPDATE_SBC_EXIT_CODE = 15; - private static final int UPDATE_FIRMWARE_EXIT_CODE = 16; + public static final int UPDATE_FIRMWARE_EXIT_CODE = 16; public int reconnectDelay() { return 15; // this one is seconds diff --git a/java_console/io/src/main/java/com/rusefi/proxy/client/IncompatibleBackendException.java b/java_console/io/src/main/java/com/rusefi/proxy/client/IncompatibleBackendException.java new file mode 100644 index 0000000000..02cbc16c88 --- /dev/null +++ b/java_console/io/src/main/java/com/rusefi/proxy/client/IncompatibleBackendException.java @@ -0,0 +1,9 @@ +package com.rusefi.proxy.client; + +import java.io.IOException; + +public class IncompatibleBackendException extends IOException { + public IncompatibleBackendException(String message) { + super(message); + } +} diff --git a/java_console/io/src/main/java/com/rusefi/proxy/client/LocalApplicationProxy.java b/java_console/io/src/main/java/com/rusefi/proxy/client/LocalApplicationProxy.java index 6016b9c969..f42cf46e04 100644 --- a/java_console/io/src/main/java/com/rusefi/proxy/client/LocalApplicationProxy.java +++ b/java_console/io/src/main/java/com/rusefi/proxy/client/LocalApplicationProxy.java @@ -12,6 +12,7 @@ import com.rusefi.io.tcp.BinaryProtocolProxy; import com.rusefi.io.tcp.ServerSocketReference; import com.rusefi.io.tcp.TcpIoStream; import com.rusefi.proxy.NetworkConnector; +import com.rusefi.proxy.NetworkConnectorContext; import com.rusefi.server.ApplicationRequest; import com.rusefi.server.rusEFISSLContext; import com.rusefi.tools.online.HttpUtil; @@ -77,8 +78,15 @@ public class LocalApplicationProxy implements Closeable { public static ServerSocketReference startAndRun(LocalApplicationProxyContext context, ApplicationRequest applicationRequest, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener, ConnectionListener connectionListener) throws IOException { String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH); log.info("Server says version=" + version); - if (!version.contains(ProxyClient.BACKEND_VERSION)) - throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION); + if (!version.contains(ProxyClient.BACKEND_VERSION)) { + String message = "Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION; + log.error(message); + System.out.println(message); + /** + * let's give wrapper script a chance to update us + */ + throw new IncompatibleBackendException(message); + } AbstractIoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener); LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest); diff --git a/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java b/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java index 3a96dc5b64..f330135ec0 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java @@ -5,10 +5,15 @@ import com.rusefi.auth.AuthTokenUtil; import com.rusefi.autodetect.PortDetector; import com.rusefi.proxy.NetworkConnector; import com.rusefi.proxy.NetworkConnectorContext; +import com.rusefi.tools.online.HttpUtil; +import com.rusefi.tools.online.ProxyClient; import com.rusefi.ui.AuthTokenPanel; +import java.io.IOException; + public class NetworkConnectorStartup { private final static Logging log = Logging.getLogging(NetworkConnectorStartup.class); + public static void start() { String authToken = AuthTokenPanel.getAuthToken(); if (!AuthTokenUtil.isToken(authToken)) { @@ -24,8 +29,23 @@ public class NetworkConnectorStartup { NetworkConnectorContext connectorContext = new NetworkConnectorContext(); - NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC, - authToken, autoDetectedPort, connectorContext); + NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC, authToken, autoDetectedPort, connectorContext, new NetworkConnector.ReconnectListener() { + @Override + public void onReconnect() { + try { + String version = HttpUtil.executeGet(ProxyClient.getHttpAddress(HttpUtil.PROXY_JSON_API_HTTP_PORT) + ProxyClient.VERSION_PATH); + if (!version.contains(ProxyClient.BACKEND_VERSION)) { + String message = "Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION; + log.error(message); + System.out.println(message); + // let's give wrapper bash script a chance to update software + System.exit(NetworkConnectorContext.UPDATE_FIRMWARE_EXIT_CODE); + } + } catch (IOException e) { + log.error("Ignoring", e); + } + } + }); log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken()); } }