proxy progress - I am getting tired :(
This commit is contained in:
parent
d7f9a2b81f
commit
1701a221a4
|
@ -10,7 +10,6 @@ import com.rusefi.server.ApplicationRequest;
|
|||
import com.rusefi.server.rusEFISSLContext;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -29,14 +28,15 @@ public class LocalApplicationProxy {
|
|||
* @param applicationRequest remote session we want to connect to
|
||||
* @param localApplicationPort local port we would bind for TunerStudio to connect to
|
||||
* @param jsonHttpPort
|
||||
* @param disconnectListener
|
||||
*/
|
||||
public static ServerHolder startAndRun(Logger logger, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int localApplicationPort, int jsonHttpPort) throws IOException {
|
||||
public static ServerHolder startAndRun(Logger logger, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int localApplicationPort, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener) throws IOException {
|
||||
String version = HttpUtil.executeGet(logger,ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
|
||||
logger.info("Server says version=" + version);
|
||||
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
||||
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
|
||||
|
||||
IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", logger, rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForRemoteUsers));
|
||||
IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", logger, rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForRemoteUsers), disconnectListener);
|
||||
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest);
|
||||
logger.info("Pushing " + applicationRequest);
|
||||
localApplicationProxy.run(authenticatorToProxyStream);
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ConsoleTools {
|
|||
registerTool("compile_fsio_file", ConsoleTools::runCompileTool, "Convert all lines from a file to RPN form.");
|
||||
|
||||
registerTool("proxy_server", a -> BackendLauncher.start(), "NOT A USER TOOL");
|
||||
registerTool("network_connector", NetworkConnectorStartup::start, "Connect your rusEFI ECU to rusEFI Online");
|
||||
registerTool("network_connector", strings -> NetworkConnectorStartup.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.");
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.tools;
|
|||
|
||||
import com.rusefi.auth.AutoTokenUtil;
|
||||
import com.rusefi.autodetect.PortDetector;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.Backend;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
|
@ -10,7 +11,7 @@ import com.rusefi.ui.AuthTokenPanel;
|
|||
import java.io.IOException;
|
||||
|
||||
public class NetworkConnectorStartup {
|
||||
public static void start(String[] strings) throws IOException, InterruptedException {
|
||||
public static void start() throws IOException, InterruptedException {
|
||||
String authToken = AuthTokenPanel.getAuthToken();
|
||||
if (!AutoTokenUtil.isToken(authToken)) {
|
||||
System.err.println("Please configure authentication token using 'set_auth_token' command");
|
||||
|
@ -23,7 +24,13 @@ public class NetworkConnectorStartup {
|
|||
return;
|
||||
}
|
||||
|
||||
SessionDetails sessionDetails = NetworkConnector.runNetworkConnector(authToken, autoDetectedPort, Backend.SERVER_PORT_FOR_CONTROLLERS);
|
||||
SessionDetails sessionDetails = NetworkConnector.runNetworkConnector(authToken, autoDetectedPort, Backend.SERVER_PORT_FOR_CONTROLLERS, new TcpIoStream.DisconnectListener() {
|
||||
@Override
|
||||
public void onDisconnect() {
|
||||
System.err.println("Disconnect detected");
|
||||
System.exit(-1);
|
||||
}
|
||||
});
|
||||
System.out.println("Running with " + sessionDetails.getOneTimeToken());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
|
|||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.*;
|
||||
import org.junit.Before;
|
||||
|
@ -74,7 +75,7 @@ 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
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, serverPortForControllers);
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, serverPortForControllers, TcpIoStream.DisconnectListener.VOID);
|
||||
|
||||
assertTrue("controllerRegistered", controllerRegistered.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class MockRusEfiDevice {
|
|||
Socket socket = rusEFISSLContext.getSSLSocket(LOCALHOST, serverPort);
|
||||
BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(socket,
|
||||
sessionDetails,
|
||||
logger) {
|
||||
logger, TcpIoStream.DisconnectListener.VOID) {
|
||||
@Override
|
||||
protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException {
|
||||
super.handleCommand(packet, stream);
|
||||
|
|
|
@ -21,8 +21,8 @@ public class BaseBroadcastingThread {
|
|||
private final Thread thread;
|
||||
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger) throws IOException {
|
||||
TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket);
|
||||
public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger, TcpIoStream.DisconnectListener disconnectListener) throws IOException {
|
||||
TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket, disconnectListener);
|
||||
IncomingDataBuffer in = stream.getDataBuffer();
|
||||
|
||||
thread = BASE_BROADCASTING_THREAD.newThread(() -> {
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* Connector between rusEFI ECU and rusEFI server
|
||||
*/
|
||||
public class NetworkConnector {
|
||||
public static SessionDetails runNetworkConnector(String authToken, String controllerPort, int serverPortForControllers) throws InterruptedException, IOException {
|
||||
public static SessionDetails runNetworkConnector(String authToken, String controllerPort, int serverPortForControllers, TcpIoStream.DisconnectListener disconnectListener) throws InterruptedException, IOException {
|
||||
LinkManager linkManager = new LinkManager(Logger.CONSOLE)
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
@ -49,11 +49,11 @@ public class NetworkConnector {
|
|||
return null;
|
||||
}
|
||||
|
||||
return runNetworkConnector(serverPortForControllers, linkManager, Logger.CONSOLE, authToken);
|
||||
return runNetworkConnector(serverPortForControllers, linkManager, Logger.CONSOLE, authToken, disconnectListener);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SessionDetails runNetworkConnector(int serverPortForControllers, LinkManager linkManager, final Logger logger, String authToken) throws IOException {
|
||||
private static SessionDetails runNetworkConnector(int serverPortForControllers, LinkManager linkManager, final Logger logger, String authToken, final TcpIoStream.DisconnectListener disconnectListener) throws IOException {
|
||||
IoStream targetEcuSocket = linkManager.getConnector().getBinaryProtocol().getStream();
|
||||
HelloCommand.send(targetEcuSocket, logger);
|
||||
String helloResponse = HelloCommand.getHelloResponse(targetEcuSocket.getDataBuffer(), logger);
|
||||
|
@ -71,7 +71,7 @@ public class NetworkConnector {
|
|||
|
||||
BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForControllers),
|
||||
deviceSessionDetails,
|
||||
logger) {
|
||||
logger, disconnectListener) {
|
||||
@Override
|
||||
protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException {
|
||||
super.handleCommand(packet, stream);
|
||||
|
|
|
@ -112,9 +112,7 @@ public class RemoteTab {
|
|||
JButton connect = new JButton("Connect");
|
||||
connect.addActionListener(event -> {
|
||||
|
||||
list.removeAll();
|
||||
list.add(new JLabel("Connecting to " + publicSession.getUserDetails().getUserName()));
|
||||
AutoupdateUtil.trueLayout(list);
|
||||
setStatus("Connecting to " + publicSession.getUserDetails().getUserName());
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
|
@ -131,6 +129,12 @@ public class RemoteTab {
|
|||
return userPanel;
|
||||
}
|
||||
|
||||
private void setStatus(String text) {
|
||||
list.removeAll();
|
||||
list.add(new JLabel(text));
|
||||
AutoupdateUtil.trueLayout(list);
|
||||
}
|
||||
|
||||
private void runAuthenticator(PublicSession publicSession, ControllerInfo controllerInfo) {
|
||||
SessionDetails sessionDetails = new SessionDetails(controllerInfo, AuthTokenPanel.getAuthToken(),
|
||||
Integer.parseInt(oneTimePasswordControl.getText()));
|
||||
|
@ -142,10 +146,9 @@ public class RemoteTab {
|
|||
LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS,
|
||||
applicationRequest,
|
||||
Integer.parseInt(getLocalPort()),
|
||||
HttpUtil.PROXY_JSON_API_HTTP_PORT);
|
||||
HttpUtil.PROXY_JSON_API_HTTP_PORT, () -> SwingUtilities.invokeLater(() -> setStatus("Disconnected")));
|
||||
} catch (IOException e) {
|
||||
// todo: proper handling
|
||||
e.printStackTrace();
|
||||
setStatus("IO error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue