From 9c03dc8aa695ba2e1d301b37714fef06a03e0ecc Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 17 Jul 2020 22:46:07 -0400 Subject: [PATCH] proxy progress --- .../main/java/com/rusefi/tools/ConsoleTools.java | 3 +++ .../test/java/com/rusefi/MockRusEfiDevice.java | 1 + .../ui/src/test/java/com/rusefi/ServerTest.java | 6 ++++-- .../java/com/rusefi/LocalApplicationProxy.java | 9 ++++++++- .../com/rusefi/proxy}/BaseBroadcastingThread.java | 2 +- .../java/com/rusefi/proxy}/NetworkConnector.java | 15 +++++++++------ 6 files changed, 26 insertions(+), 10 deletions(-) rename {java_console/ui/src/main/java/com/rusefi => java_tools/proxy_server/src/main/java/com/rusefi/proxy}/BaseBroadcastingThread.java (98%) rename {java_console/ui/src/main/java/com/rusefi => java_tools/proxy_server/src/main/java/com/rusefi/proxy}/NetworkConnector.java (76%) diff --git a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java index ec6b51dc48..9695ff0368 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java @@ -21,6 +21,7 @@ import com.rusefi.io.LinkManager; import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.maintenance.ExecHelper; +import com.rusefi.proxy.NetworkConnector; import com.rusefi.server.Backend; import com.rusefi.tools.online.Online; import com.rusefi.tune.xml.Msq; @@ -62,6 +63,8 @@ public class ConsoleTools { registerTool("compile_fsio_file", ConsoleTools::runCompileTool, "Convert all lines from a file to RPN form."); registerTool("proxy_server", Backend::start, "NOT A USER TOOL"); + registerTool("network_connector", NetworkConnector::start, "Connect your rusEFI ECU to rusEFI Online"); + registerTool("network_authenticator", 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."); diff --git a/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java b/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java index e10fb77695..76d1eee053 100644 --- a/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java +++ b/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java @@ -1,6 +1,7 @@ package com.rusefi; import com.opensr5.Logger; +import com.rusefi.proxy.BaseBroadcastingThread; import com.rusefi.server.ControllerInfo; import com.rusefi.server.SessionDetails; diff --git a/java_console/ui/src/test/java/com/rusefi/ServerTest.java b/java_console/ui/src/test/java/com/rusefi/ServerTest.java index 5fd6843ada..7c1ad3462d 100644 --- a/java_console/ui/src/test/java/com/rusefi/ServerTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ServerTest.java @@ -9,6 +9,7 @@ import com.rusefi.io.ConnectionStateListener; import com.rusefi.io.IoStream; import com.rusefi.io.LinkManager; import com.rusefi.io.commands.HelloCommand; +import com.rusefi.proxy.NetworkConnector; import com.rusefi.server.*; import com.rusefi.tools.online.ProxyClient; import org.junit.Before; @@ -40,6 +41,8 @@ public class ServerTest { @Before public void setTestCertificate() throws MalformedURLException { + NetworkConnector.RUSEFI_PROXY_HOSTNAME = ProxyClient.LOCALHOST; + File certificate = new File("certificate/test.jks"); Backend.setupCertificates(certificate, "password"); } @@ -200,8 +203,7 @@ public class ServerTest { // start authenticator int authenticatorPort = 7004; // local port on which authenticator accepts connections from Tuner Studio - IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger); - LocalApplicationProxy.startAndRun(logger, applicationRequest, authenticatorPort, authenticatorToProxyStream); + LocalApplicationProxy.startAndRun(logger, controllerPort, applicationRequest, authenticatorPort); CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1); diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java b/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java index c7f370a312..625cf44720 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java @@ -4,8 +4,11 @@ import com.opensr5.Logger; import com.rusefi.io.IoStream; import com.rusefi.io.commands.HelloCommand; import com.rusefi.io.tcp.BinaryProtocolProxy; +import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.proxy.NetworkConnector; import com.rusefi.server.ApplicationRequest; +import javax.net.ssl.SSLSocketFactory; import java.io.IOException; public class LocalApplicationProxy { @@ -22,7 +25,8 @@ public class LocalApplicationProxy { * @param authenticatorPort local port we would bind for TunerStudio to connect to * @param authenticatorToProxyStream */ - static void startAndRun(Logger logger, ApplicationRequest applicationRequest, int authenticatorPort, IoStream authenticatorToProxyStream) throws IOException { + static void startAndRun(Logger logger, int controllerPort, ApplicationRequest applicationRequest, int authenticatorPort) throws IOException { + IoStream authenticatorToProxyStream = new TcpIoStream(logger, SSLSocketFactory.getDefault().createSocket(NetworkConnector.RUSEFI_PROXY_HOSTNAME, controllerPort)); LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest); localApplicationProxy.run(authenticatorToProxyStream); @@ -33,4 +37,7 @@ public class LocalApplicationProxy { // right from connection push session authentication data new HelloCommand(logger, applicationRequest.toJson()).handle(authenticatorToProxyStream); } + + public static void start(String[] strings) { + } } diff --git a/java_console/ui/src/main/java/com/rusefi/BaseBroadcastingThread.java b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java similarity index 98% rename from java_console/ui/src/main/java/com/rusefi/BaseBroadcastingThread.java rename to java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java index fd48c5a095..c558b437dd 100644 --- a/java_console/ui/src/main/java/com/rusefi/BaseBroadcastingThread.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java @@ -1,4 +1,4 @@ -package com.rusefi; +package com.rusefi.proxy; import com.opensr5.Logger; import com.rusefi.binaryprotocol.IncomingDataBuffer; diff --git a/java_console/ui/src/main/java/com/rusefi/NetworkConnector.java b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java similarity index 76% rename from java_console/ui/src/main/java/com/rusefi/NetworkConnector.java rename to java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java index d65bb6060f..79ed9175ca 100644 --- a/java_console/ui/src/main/java/com/rusefi/NetworkConnector.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java @@ -1,26 +1,26 @@ -package com.rusefi; +package com.rusefi.proxy; import com.opensr5.Logger; import com.rusefi.io.IoStream; import com.rusefi.io.commands.HelloCommand; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.proxy.BaseBroadcastingThread; import com.rusefi.server.ControllerInfo; import com.rusefi.server.SessionDetails; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLSocketFactory; import java.io.IOException; -import java.net.Socket; - -import static com.rusefi.tools.online.ProxyClient.LOCALHOST; /** * Connector between rusEFI ECU and rusEFI server */ public class NetworkConnector { + public static String RUSEFI_PROXY_HOSTNAME = "proxy.rusefi.com"; + @NotNull - static SessionDetails runNetworkConnector(int serverPortForControllers, IoStream targetEcuSocket, final Logger logger, String authToken) throws IOException { + public static SessionDetails runNetworkConnector(int serverPortForControllers, IoStream targetEcuSocket, final Logger logger, String authToken) throws IOException { HelloCommand.send(targetEcuSocket, logger); String controllerSignature = HelloCommand.getHelloResponse(targetEcuSocket.getDataBuffer(), logger); @@ -29,7 +29,7 @@ public class NetworkConnector { SessionDetails deviceSessionDetails = new SessionDetails(ci, authToken, SessionDetails.createOneTimeCode()); - BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(SSLSocketFactory.getDefault().createSocket(LOCALHOST, serverPortForControllers), + BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(SSLSocketFactory.getDefault().createSocket(RUSEFI_PROXY_HOSTNAME, serverPortForControllers), deviceSessionDetails, logger) { @Override @@ -44,4 +44,7 @@ public class NetworkConnector { baseBroadcastingThread.start(); return deviceSessionDetails; } + + public static void start(String[] strings) { + } }