proxy progress - getting REALLY close?!
This commit is contained in:
parent
ea19cd47ae
commit
4b71e07b3f
|
@ -27,21 +27,22 @@ public class LocalApplicationProxy {
|
||||||
/**
|
/**
|
||||||
* @param serverPortForRemoteUsers port on which rusEFI proxy accepts authenticator connections
|
* @param serverPortForRemoteUsers port on which rusEFI proxy accepts authenticator connections
|
||||||
* @param applicationRequest remote session we want to connect to
|
* @param applicationRequest remote session we want to connect to
|
||||||
* @param authenticatorPort local port we would bind for TunerStudio to connect to
|
* @param localApplicationPort local port we would bind for TunerStudio to connect to
|
||||||
* @param httpPort
|
* @param jsonHttpPort
|
||||||
*/
|
*/
|
||||||
public static ServerHolder startAndRun(Logger logger, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int authenticatorPort, int httpPort) throws IOException {
|
public static ServerHolder startAndRun(Logger logger, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int localApplicationPort, int jsonHttpPort) throws IOException {
|
||||||
HttpResponse httpResponse = HttpUtil.executeGet(ProxyClient.getHttpAddress(httpPort) + ProxyClient.VERSION_PATH);
|
HttpResponse httpResponse = HttpUtil.executeGet(logger,ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
|
||||||
String version = HttpUtil.getResponse(httpResponse);
|
String version = HttpUtil.getResponse(httpResponse);
|
||||||
logger.info("Version=" + version);
|
logger.info("Server says version=" + version);
|
||||||
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
||||||
throw new IOException("Unexpected backend version " + version + " while we want " + 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));
|
||||||
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest);
|
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest);
|
||||||
|
logger.info("Pushing " + applicationRequest);
|
||||||
localApplicationProxy.run(authenticatorToProxyStream);
|
localApplicationProxy.run(authenticatorToProxyStream);
|
||||||
|
|
||||||
return BinaryProtocolProxy.createProxy(logger, authenticatorToProxyStream, authenticatorPort);
|
return BinaryProtocolProxy.createProxy(logger, authenticatorToProxyStream, localApplicationPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(IoStream authenticatorToProxyStream) throws IOException {
|
public void run(IoStream authenticatorToProxyStream) throws IOException {
|
||||||
|
|
|
@ -33,7 +33,7 @@ public interface ByteReader {
|
||||||
throw new IOException("TcpIoStream: End of input?");
|
throw new IOException("TcpIoStream: End of input?");
|
||||||
listener.onDataArrived(Arrays.copyOf(inputBuffer, result));
|
listener.onDataArrived(Arrays.copyOf(inputBuffer, result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("TcpIoStream: End of connection");
|
logger.error("TcpIoStream: End of connection " + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.tools.online;
|
package com.rusefi.tools.online;
|
||||||
|
|
||||||
|
import com.opensr5.Logger;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
@ -33,13 +34,13 @@ public class HttpUtil {
|
||||||
public static String getResponse(HttpResponse response) throws IOException {
|
public static String getResponse(HttpResponse response) throws IOException {
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String responseString = EntityUtils.toString(entity, "UTF-8");
|
String responseString = EntityUtils.toString(entity, "UTF-8");
|
||||||
System.out.println("responseString=" + responseString);
|
Logger.CONSOLE.info("responseString=" + responseString);
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpResponse executeGet(String url) throws IOException {
|
public static HttpResponse executeGet(Logger logger, String url) throws IOException {
|
||||||
HttpClient httpclient = new DefaultHttpClient();
|
HttpClient httpclient = new DefaultHttpClient();
|
||||||
System.out.println("Connecting to " + url);
|
logger.info("GET " + url);
|
||||||
HttpGet httpget = new HttpGet(url);
|
HttpGet httpget = new HttpGet(url);
|
||||||
return httpclient.execute(httpget);
|
return httpclient.execute(httpget);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.tools.online;
|
package com.rusefi.tools.online;
|
||||||
|
|
||||||
|
import com.opensr5.Logger;
|
||||||
import com.rusefi.server.ControllerInfo;
|
import com.rusefi.server.ControllerInfo;
|
||||||
import com.rusefi.server.UserDetails;
|
import com.rusefi.server.UserDetails;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
|
@ -31,7 +32,7 @@ public class ProxyClient {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<PublicSession> getOnlineApplications(String url) throws IOException {
|
public static List<PublicSession> getOnlineApplications(String url) throws IOException {
|
||||||
HttpResponse httpResponse = HttpUtil.executeGet(url);
|
HttpResponse httpResponse = HttpUtil.executeGet(Logger.CONSOLE, url);
|
||||||
|
|
||||||
List<PublicSession> userLists = new ArrayList<>();
|
List<PublicSession> userLists = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -146,6 +146,7 @@ public class Backend implements Closeable {
|
||||||
// authenticator pushed hello packet on connect
|
// authenticator pushed hello packet on connect
|
||||||
System.out.println("Starting application connector at " + serverPortForApplications);
|
System.out.println("Starting application connector at " + serverPortForApplications);
|
||||||
BinaryProtocolServer.tcpServerSocket(logger, applicationSocket -> () -> {
|
BinaryProtocolServer.tcpServerSocket(logger, applicationSocket -> () -> {
|
||||||
|
logger.info("new application connection!");
|
||||||
totalSessions.incrementAndGet();
|
totalSessions.incrementAndGet();
|
||||||
// connection from authenticator app which proxies for Tuner Studio
|
// connection from authenticator app which proxies for Tuner Studio
|
||||||
IoStream applicationClientStream = null;
|
IoStream applicationClientStream = null;
|
||||||
|
@ -155,8 +156,10 @@ public class Backend implements Closeable {
|
||||||
|
|
||||||
// authenticator pushed hello packet on connect
|
// authenticator pushed hello packet on connect
|
||||||
String jsonString = HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer(), logger);
|
String jsonString = HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer(), logger);
|
||||||
if (jsonString == null)
|
if (jsonString == null) {
|
||||||
|
logger.info("ERROR: null HELLO");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ApplicationRequest applicationRequest = ApplicationRequest.valueOf(jsonString);
|
ApplicationRequest applicationRequest = ApplicationRequest.valueOf(jsonString);
|
||||||
logger.info("Application Connected: " + applicationRequest);
|
logger.info("Application Connected: " + applicationRequest);
|
||||||
String authToken = applicationRequest.getSessionDetails().getAuthToken();
|
String authToken = applicationRequest.getSessionDetails().getAuthToken();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.server;
|
package com.rusefi.server;
|
||||||
|
|
||||||
|
import com.opensr5.Logger;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -14,7 +15,7 @@ public class JsonUserDetailsResolver implements UserDetailsResolver {
|
||||||
public UserDetails apply(String authToken) {
|
public UserDetails apply(String authToken) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpResponse response = HttpUtil.executeGet(HttpUtil.RUSEFI_ONLINE_JSON_API_PREFIX + "getUserByToken&rusefi_token=" + authToken);
|
HttpResponse response = HttpUtil.executeGet(Logger.CONSOLE,HttpUtil.RUSEFI_ONLINE_JSON_API_PREFIX + "getUserByToken&rusefi_token=" + authToken);
|
||||||
JSONObject json = HttpUtil.getJsonResponse(response);
|
JSONObject json = HttpUtil.getJsonResponse(response);
|
||||||
System.out.println("String " + json);
|
System.out.println("String " + json);
|
||||||
Object getUserByToken = json.get("getUserByToken");
|
Object getUserByToken = json.get("getUserByToken");
|
||||||
|
|
|
@ -17,8 +17,6 @@ import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
@ -34,7 +32,14 @@ public class RemoteTab {
|
||||||
private final JComponent content = new JPanel(new BorderLayout());
|
private final JComponent content = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
private final JPanel list = new JPanel(new VerticalFlowLayout());
|
private final JPanel list = new JPanel(new VerticalFlowLayout());
|
||||||
private final JTextField oneTimePasswordControl = new JTextField();
|
private final JTextField oneTimePasswordControl = new JTextField("0") {
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
Dimension size = super.getPreferredSize();
|
||||||
|
// todo: dynamic calculation of desired with based on String width?
|
||||||
|
return new Dimension(100, size.height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
||||||
|
|
||||||
|
@ -42,7 +47,14 @@ public class RemoteTab {
|
||||||
JButton refresh = new JButton("Refresh List");
|
JButton refresh = new JButton("Refresh List");
|
||||||
refresh.addActionListener(e -> requestListDownload());
|
refresh.addActionListener(e -> requestListDownload());
|
||||||
|
|
||||||
JTextField applicationPort = new JTextField();
|
JTextField applicationPort = new JTextField() {
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
Dimension size = super.getPreferredSize();
|
||||||
|
// todo: dynamic calculation of desired with based on String width?
|
||||||
|
return new Dimension(100, size.height);
|
||||||
|
}
|
||||||
|
};
|
||||||
String portProperty = getLocalPort();
|
String portProperty = getLocalPort();
|
||||||
applicationPort.setText(portProperty);
|
applicationPort.setText(portProperty);
|
||||||
|
|
||||||
|
@ -59,14 +71,14 @@ public class RemoteTab {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalPort() {
|
private String getLocalPort() {
|
||||||
return getConfig().getRoot().getProperty(APPLICATION_PORT, Integer.toString(LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS));
|
return getConfig().getRoot().getProperty(APPLICATION_PORT, "8100");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestListDownload() {
|
private void requestListDownload() {
|
||||||
listDownloadExecutor.execute(() -> {
|
listDownloadExecutor.execute(() -> {
|
||||||
List<PublicSession> userDetails;
|
List<PublicSession> userDetails;
|
||||||
try {
|
try {
|
||||||
userDetails = ProxyClient.getOnlineApplications(HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL);
|
userDetails = ProxyClient.getOnlineApplications(HttpUtil.PROXY_JSON_API_HTTP_PORT);
|
||||||
SwingUtilities.invokeLater(() -> showList(userDetails));
|
SwingUtilities.invokeLater(() -> showList(userDetails));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -104,8 +116,8 @@ public class RemoteTab {
|
||||||
LocalApplicationProxy.startAndRun(Logger.CONSOLE,
|
LocalApplicationProxy.startAndRun(Logger.CONSOLE,
|
||||||
LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS,
|
LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS,
|
||||||
applicationRequest,
|
applicationRequest,
|
||||||
HttpUtil.PROXY_JSON_API_HTTP_PORT,
|
Integer.parseInt(getLocalPort()),
|
||||||
Integer.parseInt(getLocalPort()));
|
HttpUtil.PROXY_JSON_API_HTTP_PORT);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// todo: proper handling
|
// todo: proper handling
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue