proxy progress - getting REALLY close?!
This commit is contained in:
parent
d7f0f06502
commit
0ff0da1707
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.io.tcp;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.IoStream;
|
||||
|
@ -15,6 +16,12 @@ import static com.rusefi.binaryprotocol.BinaryProtocolCommands.COMMAND_PROTOCOL;
|
|||
import static com.rusefi.config.generated.Fields.TS_PROTOCOL;
|
||||
|
||||
public class BinaryProtocolProxy {
|
||||
/**
|
||||
* we expect server to at least request output channels once in a while
|
||||
* it could be a while between user connecting authenticator and actually connecting application to authenticator
|
||||
*/
|
||||
public static final int USER_IO_TIMEOUT = 600 * Timeouts.SECOND;
|
||||
|
||||
public static ServerHolder createProxy(Logger logger, IoStream targetEcuSocket, int serverProxyPort) {
|
||||
Function<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
||||
try {
|
||||
|
@ -33,7 +40,7 @@ public class BinaryProtocolProxy {
|
|||
*/
|
||||
//noinspection InfiniteLoopStatement
|
||||
while (true) {
|
||||
byte firstByte = clientStream.getDataBuffer().readByte();
|
||||
byte firstByte = clientStream.getDataBuffer().readByte(USER_IO_TIMEOUT);
|
||||
if (firstByte == COMMAND_PROTOCOL) {
|
||||
clientStream.write(TS_PROTOCOL.getBytes());
|
||||
continue;
|
||||
|
|
|
@ -2,10 +2,10 @@ package com.rusefi.proxy;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
|
@ -18,8 +18,6 @@ import static com.rusefi.io.tcp.BinaryProtocolServer.readPromisedBytes;
|
|||
|
||||
public class BaseBroadcastingThread {
|
||||
private static final NamedThreadFactory BASE_BROADCASTING_THREAD = new NamedThreadFactory("BaseBroadcastingThread");
|
||||
// we expect server to at least request output channels once in a while
|
||||
private static final int IO_TIMEOUT = 600 * Timeouts.SECOND;
|
||||
private final Thread thread;
|
||||
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
|
@ -29,18 +27,21 @@ public class BaseBroadcastingThread {
|
|||
|
||||
thread = BASE_BROADCASTING_THREAD.newThread(() -> {
|
||||
try {
|
||||
boolean isFirstHello = true;
|
||||
while (true) {
|
||||
int length = getPacketLength(in, () -> {
|
||||
throw new UnsupportedOperationException();
|
||||
}, IO_TIMEOUT);
|
||||
}, BinaryProtocolProxy.USER_IO_TIMEOUT);
|
||||
BinaryProtocolServer.Packet packet = readPromisedBytes(in, length);
|
||||
byte[] payload = packet.getPacket();
|
||||
|
||||
byte command = payload[0];
|
||||
|
||||
if (command == Fields.TS_HELLO_COMMAND) {
|
||||
if (isFirstHello && command == Fields.TS_HELLO_COMMAND) {
|
||||
// first TS_HELLO_COMMAND is PROXY request, consecutive TS_HELLO_COMMAND would be real deal from user desktop application
|
||||
isFirstHello = false;
|
||||
// respond on hello request with information about session
|
||||
logger.info("Sending to controller connector@proxy: " + sessionDetails);
|
||||
logger.info("Replying to controller connector@proxy: " + sessionDetails);
|
||||
new HelloCommand(logger, sessionDetails.toJson()).handle(stream);
|
||||
} else {
|
||||
handleCommand(packet, stream);
|
||||
|
|
|
@ -67,6 +67,7 @@ public class RemoteTab {
|
|||
topPanel.add(oneTimePasswordControl);
|
||||
content.add(topPanel, BorderLayout.NORTH);
|
||||
content.add(list, BorderLayout.CENTER);
|
||||
list.add(new JLabel("Requesting list of ECUs"));
|
||||
requestListDownload();
|
||||
}
|
||||
|
||||
|
@ -89,9 +90,13 @@ public class RemoteTab {
|
|||
|
||||
private void showList(List<PublicSession> userDetails) {
|
||||
list.removeAll();
|
||||
if (userDetails.isEmpty()) {
|
||||
list.add(new JLabel("No ECUs are broadcasting at the moment :("));
|
||||
} else {
|
||||
for (PublicSession user : userDetails) {
|
||||
list.add(createPanel(user));
|
||||
}
|
||||
}
|
||||
AutoupdateUtil.trueLayout(list);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue