Skip to content

Commit

Permalink
Allow ice adapter to start when TelemetryDebugger not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Aug 6, 2023
1 parent 2807bf9 commit 465e0a2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion client/src/main/java/client/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void informationThread() {
if(forgedAlliance != null) {
forgedAlliance.getPeers().forEach(p -> {
synchronized (p) {
p.setLatencies(new LinkedList<>());
p.clearLatencyHistory();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine;

import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

import static com.faforever.iceadapter.debug.Debug.debug;
@CommandLine.Command(name = "faf-ice-adapter", mixinStandardHelpOptions = true, usageHelpAutoWidth = true,
Expand Down Expand Up @@ -48,7 +46,6 @@ public static void main(String[] args) {
new CommandLine(new IceAdapter()).execute(args);
}


@Override
public Integer call() {
IceAdapter.start(iceOptions);
Expand Down Expand Up @@ -170,7 +167,7 @@ public static void close() {

/**
* Read command line arguments and set global, constant values
* @param arguments The arguments to be read
* @param iceOptions The arguments to be read
*/
public static void loadOptions(IceOptions iceOptions) {
TELEMETRY_SERVER = iceOptions.getTelemetryServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void sendMessage(OutgoingMessageV1 message) {
public void startupComplete() {
try {
if (!websocketClient.connectBlocking()) {
Debug.remove(this);
return;
}
} catch (InterruptedException e) {
Expand Down
98 changes: 53 additions & 45 deletions shared/src/main/java/data/ForgedAlliancePeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,58 @@
@Data
public class ForgedAlliancePeer {

private boolean connected = false;
public final String remoteAddress;
public final int remotePort;
public final int remoteId;
public final String remoteUsername;
public final Offerer offerer;

public int echoRequestsSent;
public long lastPacketReceived = System.currentTimeMillis();
public Queue<Integer> latencies = new LinkedList<>();

public long lastConnectionRequestSent = 0;

public int addLatency(int lat) {
lastPacketReceived = System.currentTimeMillis();

synchronized (latencies) {
latencies.add(lat);
if(latencies.size() > 25) {
latencies.remove();
}
}
return getLatency();
}

public int getLatency() {
synchronized (latencies) {
return (int)latencies.stream().mapToInt(Integer::intValue).average().orElse(0);
}
}

public int getJitter() {
int lat = getLatency();
synchronized (latencies) {
return Math.max(latencies.stream().mapToInt(Integer::intValue).max().orElse(0) - lat, lat - latencies.stream().mapToInt(Integer::intValue).min().orElse(0));
}
}

public boolean isQuiet() {
return System.currentTimeMillis() - lastPacketReceived > 5000;
}

public static enum Offerer {
REMOTE, LOCAL
}
private boolean connected = false;
public final String remoteAddress;
public final int remotePort;
public final int remoteId;
public final String remoteUsername;
public final Offerer offerer;

public int echoRequestsSent;
public long lastPacketReceived = System.currentTimeMillis();
public final Queue<Integer> latencies = new LinkedList<>();

public long lastConnectionRequestSent = 0;

public void clearLatencyHistory() {
synchronized (latencies) {
latencies.clear();
}
}

public int addLatency(int lat) {
lastPacketReceived = System.currentTimeMillis();

synchronized (latencies) {
latencies.add(lat);
if (latencies.size() > 25) {
latencies.remove();
}
}
return getAverageLatency();
}

public int getAverageLatency() {
synchronized (latencies) {
return (int) latencies.stream().mapToInt(Integer::intValue).average().orElse(0);
}
}

public int getJitter() {
int averageLatency = getAverageLatency();
synchronized (latencies) {
int maxLatency = latencies.stream().mapToInt(Integer::intValue).max().orElse(0);
int minLatency = latencies.stream().mapToInt(Integer::intValue).min().orElse(0);
return Math.max(maxLatency - averageLatency, averageLatency - minLatency);
}
}

public boolean isQuiet() {
return System.currentTimeMillis() - lastPacketReceived > 5000;
}

public enum Offerer {
REMOTE, LOCAL
}

}
10 changes: 5 additions & 5 deletions shared/src/main/java/data/IceStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ public class IceStatus {
private String init_mode;
private IceOptions options;
private IceGPGNetState gpgpnet;
private IceRelay relays[];
private IceRelay[] relays;

@Data
public class IceOptions {
public static class IceOptions {
private int player_id;
private String player_login;
private int rpc_port;
private int gpgnet_port;
}

@Data
public class IceGPGNetState {
public static class IceGPGNetState {
private int local_port;
private boolean connected;
private String game_state;
private String task_string;
}

@Data
public class IceRelay {
public static class IceRelay {

private int remote_player_id;
private String remote_player_login;
private int local_game_udp_port;
private IceRelayICEState ice;

@Data
public class IceRelayICEState {
public static class IceRelayICEState {
private boolean offerer;
private String state;
private String gathering_state;
Expand Down

0 comments on commit 465e0a2

Please sign in to comment.