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