More accurate ping and handling all packet types properly

This commit is contained in:
Manevolent
2018-08-10 19:01:06 -04:00
parent 4072b19f09
commit 844e3e6e75
3 changed files with 15 additions and 17 deletions
@@ -21,9 +21,9 @@ public class PacketStatistics {
receivedBytes += size;
receivedPackets ++;
receivedPacketList.add(new DataPoint(packet.getCreatedNanotime() / 1000L, packet.getSize()));
receivedPacketList.add(new DataPoint(packet.getCreatedNanotime(), packet.getSize()));
long t = System.currentTimeMillis() - 60_000L;
long t = System.nanoTime() - 60_000_000_000L;
receivedPacketList.removeIf(x -> x.getTime() < t);
}
@@ -33,10 +33,10 @@ public class PacketStatistics {
sentBytes += size;
sentPackets ++;
sentPacketList.add(new DataPoint(packet.getCreatedNanotime() / 1000L, packet.getSize()));
sentPacketList.add(new DataPoint(packet.getCreatedNanotime(), packet.getSize()));
// Remove oldest
long t = System.currentTimeMillis() - 60_000L;
long t = System.nanoTime() - 60_000_000_000L;
sentPacketList.removeIf(x -> x.getTime() < t);
}
@@ -49,7 +49,7 @@ public class PacketStatistics {
}
public int getSentPacketsLastSecond() {
long now = System.currentTimeMillis() - 1_000L;
long now = System.currentTimeMillis() - 1_000_000_000L;
return (int) sentPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -57,7 +57,7 @@ public class PacketStatistics {
}
public int getSentPacketsLastMinute() {
long now = System.currentTimeMillis() - 60_000L;
long now = System.currentTimeMillis() - 1_000_000_000L;
return (int) sentPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -69,7 +69,7 @@ public class PacketStatistics {
}
public int getReceivedPacketsLastSecond() {
long now = System.currentTimeMillis() - 1_000L;
long now = System.currentTimeMillis() - 1_000_000_000L;
return (int) receivedPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -77,7 +77,7 @@ public class PacketStatistics {
}
public int getReceivedPacketsLastMinute() {
long now = System.currentTimeMillis() - 60_000L;
long now = System.currentTimeMillis() - 60_000_000_000L;
return (int) receivedPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -90,7 +90,7 @@ public class PacketStatistics {
}
public int getSentBytesLastMinute() {
long now = System.currentTimeMillis() - 60_000L;
long now = System.currentTimeMillis() - 60_000_000_000L;
return sentPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -100,7 +100,7 @@ public class PacketStatistics {
}
public int getSentBytesLastSecond() {
long now = System.currentTimeMillis() - 1_000L;
long now = System.currentTimeMillis() - 1_000_000_000L;
return sentPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -110,7 +110,7 @@ public class PacketStatistics {
}
public int getReceivedBytesLastMinute() {
long now = System.currentTimeMillis() - 60_000L;
long now = System.currentTimeMillis() - 60_000_000_000L;
return receivedPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -120,7 +120,7 @@ public class PacketStatistics {
}
public int getReceivedBytesLastSecond() {
long now = System.currentTimeMillis() - 1_000L;
long now = System.currentTimeMillis() - 1_000_000_000L;
return receivedPacketList.stream()
.filter(x -> x.getTime() >= now)
@@ -112,9 +112,9 @@ public class LocalTeamspeakClientSocket
Pair<Double, Double> ping = getPing();
response.add(new CommandSingleParameter("connection_ping",
Integer.toString((int)(double)ping.getKey())));
Double.toString(Math.round(ping.getKey() * 1000D * 1000D) / 1000D)));
response.add(new CommandSingleParameter("connection_ping_deviation",
Integer.toString((int)(double)ping.getValue())));
Double.toString(Math.round(ping.getValue() * 1000D * 1000D) / 1000D)));
for (PacketKind kind : PacketKind.values()) {
PacketStatistics stats = getStatistics(kind);