REO - local ip into session info
This commit is contained in:
parent
6d2a8f3da9
commit
32215bd8d2
|
@ -4,6 +4,8 @@ import com.rusefi.proxy.NetworkConnector;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ public class SessionDetails {
|
||||||
public static final String CONNECTOR_VERSION = "connectorVersion";
|
public static final String CONNECTOR_VERSION = "connectorVersion";
|
||||||
public static final String IMPLEMENTATION = "implementation";
|
public static final String IMPLEMENTATION = "implementation";
|
||||||
public static final String AGE = "age";
|
public static final String AGE = "age";
|
||||||
|
public static final String LOCAL_IP = "local_ip";
|
||||||
|
|
||||||
private static final String CONTROLLER = "controller";
|
private static final String CONTROLLER = "controller";
|
||||||
private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE");
|
private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE");
|
||||||
|
@ -26,10 +29,24 @@ public class SessionDetails {
|
||||||
private final String authToken;
|
private final String authToken;
|
||||||
private final NetworkConnector.Implementation implementation;
|
private final NetworkConnector.Implementation implementation;
|
||||||
private final int consoleVersion;
|
private final int consoleVersion;
|
||||||
|
private final String localIpAddress;
|
||||||
|
|
||||||
public SessionDetails(NetworkConnector.Implementation implementation, ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion) {
|
public SessionDetails(NetworkConnector.Implementation implementation, ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion) {
|
||||||
|
this(implementation, controllerInfo, authToken, oneTimeCode, consoleVersion, findLocalIpAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String findLocalIpAddress() {
|
||||||
|
try {
|
||||||
|
return InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionDetails(NetworkConnector.Implementation implementation, ControllerInfo controllerInfo, String authToken, int oneTimeCode, int consoleVersion, String localIpAddress) {
|
||||||
this.implementation = Objects.requireNonNull(implementation);
|
this.implementation = Objects.requireNonNull(implementation);
|
||||||
this.consoleVersion = consoleVersion;
|
this.consoleVersion = consoleVersion;
|
||||||
|
this.localIpAddress = localIpAddress;
|
||||||
Objects.requireNonNull(controllerInfo);
|
Objects.requireNonNull(controllerInfo);
|
||||||
Objects.requireNonNull(authToken);
|
Objects.requireNonNull(authToken);
|
||||||
this.controllerInfo = controllerInfo;
|
this.controllerInfo = controllerInfo;
|
||||||
|
@ -37,6 +54,10 @@ public class SessionDetails {
|
||||||
this.authToken = authToken;
|
this.authToken = authToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLocalIpAddress() {
|
||||||
|
return localIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
public static int createOneTimeCode() {
|
public static int createOneTimeCode() {
|
||||||
return HARDCODED_ONE_TIME_CODE == null ? new Random().nextInt(100000) : Integer.parseInt(HARDCODED_ONE_TIME_CODE);
|
return HARDCODED_ONE_TIME_CODE == null ? new Random().nextInt(100000) : Integer.parseInt(HARDCODED_ONE_TIME_CODE);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +89,7 @@ public class SessionDetails {
|
||||||
jsonObject.put(AUTH_TOKEN, authToken);
|
jsonObject.put(AUTH_TOKEN, authToken);
|
||||||
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
jsonObject.put(CONNECTOR_VERSION, consoleVersion);
|
||||||
jsonObject.put(IMPLEMENTATION, implementation.name());
|
jsonObject.put(IMPLEMENTATION, implementation.name());
|
||||||
|
jsonObject.put(LOCAL_IP, localIpAddress);
|
||||||
return jsonObject.toJSONString();
|
return jsonObject.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,11 +99,12 @@ public class SessionDetails {
|
||||||
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
String authToken = (String) jsonObject.get(AUTH_TOKEN);
|
||||||
long oneTimeCode = (Long) jsonObject.get(VEHICLE_TOKEN);
|
long oneTimeCode = (Long) jsonObject.get(VEHICLE_TOKEN);
|
||||||
long connectorVersion = (long) jsonObject.get(CONNECTOR_VERSION);
|
long connectorVersion = (long) jsonObject.get(CONNECTOR_VERSION);
|
||||||
|
String localIp = (String) jsonObject.get(LOCAL_IP);
|
||||||
NetworkConnector.Implementation implementation = NetworkConnector.Implementation.find((String) jsonObject.get(IMPLEMENTATION));
|
NetworkConnector.Implementation implementation = NetworkConnector.Implementation.find((String) jsonObject.get(IMPLEMENTATION));
|
||||||
|
|
||||||
ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER));
|
ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER));
|
||||||
|
|
||||||
return new SessionDetails(implementation, controllerInfo, authToken, (int) oneTimeCode, (int) connectorVersion);
|
return new SessionDetails(implementation, controllerInfo, authToken, (int) oneTimeCode, (int) connectorVersion, localIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ProxyClient {
|
||||||
public static final String LIST_APPLICATIONS_PATH = "/list_applications";
|
public static final String LIST_APPLICATIONS_PATH = "/list_applications";
|
||||||
public static final String VERSION_PATH = "/version";
|
public static final String VERSION_PATH = "/version";
|
||||||
public static final String UPDATE_CONNECTOR_SOFTWARE = "/update_connector_software";
|
public static final String UPDATE_CONNECTOR_SOFTWARE = "/update_connector_software";
|
||||||
public static final String BACKEND_VERSION = "0.0003";
|
public static final String BACKEND_VERSION = "0.0004";
|
||||||
public static final String IS_USED = "isUsed";
|
public static final String IS_USED = "isUsed";
|
||||||
public static final String OWNER = "owner";
|
public static final String OWNER = "owner";
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -317,6 +317,7 @@ public class Backend implements Closeable {
|
||||||
.add(ControllerInfo.ENGINE_MAKE, controllerInfo.getEngineMake())
|
.add(ControllerInfo.ENGINE_MAKE, controllerInfo.getEngineMake())
|
||||||
.add(ControllerInfo.ENGINE_CODE, controllerInfo.getEngineCode())
|
.add(ControllerInfo.ENGINE_CODE, controllerInfo.getEngineCode())
|
||||||
.add(SessionDetails.IMPLEMENTATION, sessionDetails.getImplementation().name())
|
.add(SessionDetails.IMPLEMENTATION, sessionDetails.getImplementation().name())
|
||||||
|
.add(SessionDetails.LOCAL_IP, sessionDetails.getLocalIpAddress())
|
||||||
.add(SessionDetails.CONNECTOR_VERSION, sessionDetails.getConsoleVersion());
|
.add(SessionDetails.CONNECTOR_VERSION, sessionDetails.getConsoleVersion());
|
||||||
objectBuilder = addStreamStats(objectBuilder, client.getStream());
|
objectBuilder = addStreamStats(objectBuilder, client.getStream());
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
|
|
Loading…
Reference in New Issue