proxy progress
This commit is contained in:
parent
1509498cd9
commit
addfc9f502
|
@ -1,12 +1,12 @@
|
|||
// This file was generated by Version2Header
|
||||
// Mon Jul 06 02:08:25 EDT 2020
|
||||
// Fri Jul 10 23:51:33 EDT 2020
|
||||
|
||||
|
||||
#ifndef GIT_HASH
|
||||
#define GIT_HASH "15731e29f945c418461fe197fa38d87a5f43b361"
|
||||
#define GIT_HASH "38d3641c007cbeae97cc196d0d7a5d8ac6abbd18"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef VCS_VERSION
|
||||
#define VCS_VERSION "24100"
|
||||
#define VCS_VERSION "24207"
|
||||
#endif
|
||||
|
|
|
@ -12,7 +12,6 @@ public interface BinaryProtocolCommands {
|
|||
byte RESPONSE_OK = Fields.TS_RESPONSE_OK;
|
||||
byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK;
|
||||
byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK;
|
||||
char COMMAND_HELLO = Fields.TS_HELLO_COMMAND;
|
||||
char COMMAND_PROTOCOL = 'F';
|
||||
// todo: make crc32CheckCommand shorted one day later - no need in 6 empty bytes
|
||||
char COMMAND_CRC_CHECK_COMMAND = Fields.TS_CRC_CHECK_COMMAND;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.rusefi.io.commands;
|
||||
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Command {
|
||||
byte getCommand();
|
||||
|
||||
void handle(BinaryProtocolServer.Packet packet, IoStream stream) throws IOException;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rusefi.io.commands;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HelloCommand implements Command {
|
||||
private final Logger logger;
|
||||
private final String tsSignature;
|
||||
|
||||
public HelloCommand(Logger logger, String tsSignature) {
|
||||
this.logger = logger;
|
||||
this.tsSignature = tsSignature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getCommand() {
|
||||
return Fields.TS_HELLO_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(BinaryProtocolServer.Packet packet, IoStream stream) throws IOException {
|
||||
stream.sendPacket((BinaryProtocolServer.TS_OK + tsSignature).getBytes(), logger);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
|||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
|
@ -31,7 +32,7 @@ import static com.rusefi.config.generated.Fields.*;
|
|||
|
||||
public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||
private static final int DEFAULT_PROXY_PORT = 2390;
|
||||
private static final String TS_OK = "\0";
|
||||
public static final String TS_OK = "\0";
|
||||
private final Logger logger;
|
||||
|
||||
public AtomicInteger unknownCommands = new AtomicInteger();
|
||||
|
@ -117,17 +118,18 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
System.out.println("Got [" + length + "] length promise");
|
||||
|
||||
byte[] packet = readPromisedBytes(in, length).getPacket();
|
||||
Packet packet = readPromisedBytes(in, length);
|
||||
byte[] payload = packet.getPacket();
|
||||
|
||||
if (packet.length == 0)
|
||||
if (payload.length == 0)
|
||||
throw new IOException("Empty packet");
|
||||
|
||||
byte command = packet[0];
|
||||
byte command = payload[0];
|
||||
|
||||
System.out.println("Got [" + (char) command + "/" + command + "] command");
|
||||
|
||||
if (command == COMMAND_HELLO) {
|
||||
stream.sendPacket((TS_OK + Fields.TS_SIGNATURE).getBytes(), logger);
|
||||
if (command == Fields.TS_HELLO_COMMAND) {
|
||||
new HelloCommand(logger, Fields.TS_SIGNATURE).handle(packet, stream);
|
||||
} else if (command == COMMAND_PROTOCOL) {
|
||||
// System.out.println("Ignoring crc F command");
|
||||
stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), logger);
|
||||
|
@ -138,11 +140,11 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
} else if (command == COMMAND_PAGE) {
|
||||
stream.sendPacket(TS_OK.getBytes(), logger);
|
||||
} else if (command == COMMAND_READ) {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet, 1, packet.length - 1));
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
|
||||
handleRead(linkManager, dis, stream);
|
||||
} else if (command == Fields.TS_CHUNK_WRITE_COMMAND) {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet, 1, packet.length - 1));
|
||||
handleWrite(linkManager, packet, dis, stream);
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
|
||||
handleWrite(linkManager, payload, dis, stream);
|
||||
} else if (command == Fields.TS_BURN_COMMAND) {
|
||||
stream.sendPacket(new byte[]{TS_RESPONSE_BURN_OK}, logger);
|
||||
} else if (command == Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY) {
|
||||
|
@ -150,7 +152,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
// todo: relay command
|
||||
stream.sendPacket(TS_OK.getBytes(), logger);
|
||||
} else if (command == Fields.TS_OUTPUT_COMMAND) {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet, 1, packet.length - 1));
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
|
||||
int offset = swap16(dis.readShort());
|
||||
int count = swap16(dis.readShort());
|
||||
System.out.println("TS_OUTPUT_COMMAND offset=" + offset + "/count=" + count);
|
||||
|
|
|
@ -2,25 +2,32 @@ package com.rusefi.server;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolCommands;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
|
||||
|
||||
public class ClientConnectionState {
|
||||
private final Socket clientSocket;
|
||||
private final Logger logger;
|
||||
|
||||
private long lastActivityTimestamp;
|
||||
private boolean isClosed;
|
||||
private TcpIoStream stream;
|
||||
private IoStream stream;
|
||||
private IncomingDataBuffer incomingData;
|
||||
|
||||
public ClientConnectionState(Socket clientSocket, Logger logger) {
|
||||
this.clientSocket = clientSocket;
|
||||
this.logger = logger;
|
||||
try {
|
||||
stream = new TcpIoStream(logger, clientSocket);
|
||||
incomingData = stream.getDataBuffer();
|
||||
} catch (IOException e) {
|
||||
close();
|
||||
}
|
||||
|
@ -37,7 +44,13 @@ public class ClientConnectionState {
|
|||
|
||||
public void sayHello() {
|
||||
try {
|
||||
stream.sendPacket(new byte[]{BinaryProtocolCommands.COMMAND_HELLO}, logger);
|
||||
stream.sendPacket(new byte[]{Fields.TS_HELLO_COMMAND}, logger);
|
||||
byte[] response = incomingData.getPacket(logger, "", false);
|
||||
if (!checkResponseCode(response, BinaryProtocolCommands.RESPONSE_OK))
|
||||
return;
|
||||
String signature = new String(response, 1, response.length - 1);
|
||||
logger.info("New client: " + signature);
|
||||
|
||||
} catch (IOException e) {
|
||||
close();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class SerialAutoChecker implements Runnable {
|
|||
Logger logger = FileLog.LOGGER;
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
try {
|
||||
stream.sendPacket(new byte[]{BinaryProtocolCommands.COMMAND_HELLO}, logger);
|
||||
stream.sendPacket(new byte[]{Fields.TS_HELLO_COMMAND}, logger);
|
||||
byte[] response = incomingData.getPacket(logger, "", false);
|
||||
if (!checkResponseCode(response, BinaryProtocolCommands.RESPONSE_OK))
|
||||
return;
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.rusefi;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
|
||||
|
@ -33,7 +35,15 @@ public class MockRusEfiDevice {
|
|||
int length = getPacketLength(in, () -> {
|
||||
throw new UnsupportedOperationException();
|
||||
});
|
||||
byte[] packet = readPromisedBytes(in, length).getPacket();
|
||||
BinaryProtocolServer.Packet packet = readPromisedBytes(in, length);
|
||||
byte[] payload = packet.getPacket();
|
||||
|
||||
byte command = payload[0];
|
||||
|
||||
|
||||
if (command == Fields.TS_HELLO_COMMAND) {
|
||||
new HelloCommand(logger, signature).handle(packet, stream);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.rusefi.binaryprotocol.BinaryProtocol.sleep;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -25,7 +26,6 @@ public class ServerTest {
|
|||
public void testSessionTimeout() throws InterruptedException, IOException {
|
||||
int serverPort = 7000;
|
||||
|
||||
|
||||
CountDownLatch serverCreated = new CountDownLatch(1);
|
||||
|
||||
|
||||
|
@ -53,5 +53,9 @@ public class ServerTest {
|
|||
|
||||
new MockRusEfiDevice("rusEFI 2020.07.06.frankenso_na6.2468827536", logger).connect(serverPort);
|
||||
new MockRusEfiDevice("rusEFI 2020.07.11.proteus_f4.1986715563", logger).connect(serverPort);
|
||||
|
||||
|
||||
sleep(Timeouts.SECOND);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue