From 820eee210c10f653449eb39d48389a3adca18a01 Mon Sep 17 00:00:00 2001 From: Tobias G Date: Mon, 4 Mar 2024 22:27:55 +0100 Subject: [PATCH] Switch back to miliseconds & use NetworkStackLatencyPacket again for ping --- pom.xml | 2 +- .../proxytransport/ProxyTransport.java | 7 +++- .../impl/TransportClientConnection.java | 39 ++++++------------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 3ee488d..417c8d7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.nethergames.proxytransport proxy-transport - 2.0.5-SNAPSHOT + 2.0.5 UTF-8 diff --git a/src/main/java/org/nethergames/proxytransport/ProxyTransport.java b/src/main/java/org/nethergames/proxytransport/ProxyTransport.java index 8e7dabf..3e2bb9a 100644 --- a/src/main/java/org/nethergames/proxytransport/ProxyTransport.java +++ b/src/main/java/org/nethergames/proxytransport/ProxyTransport.java @@ -2,6 +2,7 @@ import dev.waterdog.waterdogpe.network.protocol.ProtocolCodecs; import dev.waterdog.waterdogpe.plugin.Plugin; +import io.netty.incubator.codec.quic.Quic; import org.nethergames.proxytransport.integration.QuicTransportServerInfo; import org.nethergames.proxytransport.integration.TcpTransportServerInfo; import org.nethergames.proxytransport.utils.CodecUpdater; @@ -11,12 +12,16 @@ public class ProxyTransport extends Plugin { @Override public void onStartup() { ProtocolCodecs.addUpdater(new CodecUpdater()); + getLogger().info("Registered architecture: {} | {}", System.getProperty("os.name"), System.getProperty("os.arch")); + getLogger().info("System Properties: {}", System.getProperties().toString()); try { Class.forName("io.netty.incubator.codec.quic.QuicheNativeStaticallyReferencedJniMethods"); + Quic.ensureAvailability(); getLogger().info("QUIC is supported"); - } catch (ClassNotFoundException e) { + } catch (Exception e) { getLogger().info("QUIC is not supported / shading failed"); + getLogger().error(e); } getLogger().info("ProxyTransport was started."); diff --git a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java index 28a5d29..7e0c753 100644 --- a/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java +++ b/src/main/java/org/nethergames/proxytransport/impl/TransportClientConnection.java @@ -10,11 +10,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.epoll.EpollSocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.incubator.codec.quic.QuicChannel; -import io.netty.incubator.codec.quic.QuicConnectionStats; -import io.netty.util.concurrent.Future; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; @@ -168,40 +163,30 @@ public void enableEncryption(SecretKey secretKey) { @Override public long getPing() { - return latency; + return this.latency / 1000; + } + + public long getMicroSecondsPing() { + return this.latency; } public void collectStats() { var connection = getPlayer().getDownstreamConnection(); if (connection instanceof TransportClientConnection && connection.getServerInfo().getServerName().equalsIgnoreCase(getServerInfo().getServerName())) { - if (this.channel instanceof NioSocketChannel) { - NetworkStackLatencyPacket packet = new NetworkStackLatencyPacket(); - packet.setTimestamp(0L); - packet.setFromServer(true); + NetworkStackLatencyPacket packet = new NetworkStackLatencyPacket(); + packet.setTimestamp(0L); + packet.setFromServer(true); - sendPacket(packet); + sendPacket(packet); - this.lastPingTimestamp = System.nanoTime(); - } else if (this.channel instanceof EpollSocketChannel epollChannel) { - this.latency = epollChannel.tcpInfo().rtt() / 2; - this.broadcastPing(); - } else if (this.channel instanceof QuicChannel quicChannel) { - quicChannel.collectStats().addListener((Future future) -> { - if (future.isSuccess()) { - QuicConnectionStats stats = future.getNow(); - - this.latency = stats.recv(); - this.broadcastPing(); - } - }); - } + this.lastPingTimestamp = System.nanoTime(); } } private void broadcastPing() { TickSyncPacket latencyPacket = new TickSyncPacket(); - latencyPacket.setRequestTimestamp(getPlayer().getPing() * 1000); - latencyPacket.setResponseTimestamp(this.latency); + latencyPacket.setRequestTimestamp(getPlayer().getPing()); + latencyPacket.setResponseTimestamp(this.getPing()); sendPacket(latencyPacket); }