#2710: Store queue of pending keepalives
This allows the server to send them at a rate greater than the client reply time.
This commit is contained in:
parent
3f6aa0336c
commit
eeb374798b
@ -3,6 +3,9 @@ package net.md_5.bungee;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -26,8 +29,7 @@ public class ServerConnection implements Server
|
||||
@Getter
|
||||
private final boolean forgeServer = false;
|
||||
@Getter
|
||||
@Setter
|
||||
private long sentPingId = -1;
|
||||
private final Queue<KeepAliveData> keepAlives = new LinkedList<>();
|
||||
|
||||
private final Unsafe unsafe = new Unsafe()
|
||||
{
|
||||
@ -87,4 +89,12 @@ public class ServerConnection implements Server
|
||||
{
|
||||
return unsafe;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class KeepAliveData
|
||||
{
|
||||
|
||||
private final long id;
|
||||
private final long time;
|
||||
}
|
||||
}
|
||||
|
@ -93,9 +93,6 @@ public final class UserConnection implements ProxiedPlayer
|
||||
/*========================================================================*/
|
||||
@Getter
|
||||
@Setter
|
||||
private long sentPingTime;
|
||||
@Getter
|
||||
@Setter
|
||||
private int ping = 100;
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -23,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.ServerConnection;
|
||||
import net.md_5.bungee.ServerConnection.KeepAliveData;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.Util;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -124,8 +125,10 @@ public class DownstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(KeepAlive alive) throws Exception
|
||||
{
|
||||
server.setSentPingId( alive.getRandomId() );
|
||||
con.setSentPingTime( System.currentTimeMillis() );
|
||||
if ( server.getKeepAlives().size() < bungee.getConfig().getTimeout() / 50 ) // Allow a theoretical maximum of 1 keepalive per tick
|
||||
{
|
||||
server.getKeepAlives().add( new KeepAliveData( alive.getRandomId(), System.currentTimeMillis() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.ServerConnection.KeepAliveData;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.Util;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -121,9 +122,11 @@ public class UpstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(KeepAlive alive) throws Exception
|
||||
{
|
||||
if ( alive.getRandomId() == con.getServer().getSentPingId() )
|
||||
KeepAliveData keepAliveData = con.getServer().getKeepAlives().poll();
|
||||
|
||||
if ( keepAliveData != null && alive.getRandomId() == keepAliveData.getId() )
|
||||
{
|
||||
int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() );
|
||||
int newPing = (int) ( System.currentTimeMillis() - keepAliveData.getTime() );
|
||||
con.getTabListHandler().onPingChange( newPing );
|
||||
con.setPing( newPing );
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user