Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 13:30:17 +01:00
Allow custom connection and read timeouts.
Dieser Commit ist enthalten in:
Ursprung
2b1d55a0fc
Commit
871319d679
@ -273,6 +273,14 @@ public class VelocityConfiguration extends AnnotatedConfig {
|
|||||||
return announceForge;
|
return announceForge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getConnectTimeout() {
|
||||||
|
return advanced.getConnectionTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReadTimeout() {
|
||||||
|
return advanced.getReadTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this)
|
return MoreObjects.toStringHelper(this)
|
||||||
@ -420,21 +428,23 @@ public class VelocityConfiguration extends AnnotatedConfig {
|
|||||||
"Disable by setting to 0"})
|
"Disable by setting to 0"})
|
||||||
@ConfigKey("login-ratelimit")
|
@ConfigKey("login-ratelimit")
|
||||||
private int loginRatelimit = 3000;
|
private int loginRatelimit = 3000;
|
||||||
|
@Comment({"Specify a custom timeout for connection timeouts here. The default is five seconds."})
|
||||||
|
@ConfigKey("connection-timeout")
|
||||||
|
private int connectionTimeout = 5000;
|
||||||
|
@Comment({"Specify a read timeout for connections here. The default is 30 seconds."})
|
||||||
|
@ConfigKey("read-timeout")
|
||||||
|
private int readTimeout = 30000;
|
||||||
|
|
||||||
private Advanced() {
|
private Advanced() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Advanced(int compressionThreshold, int compressionLevel, int loginRatelimit) {
|
|
||||||
this.compressionThreshold = compressionThreshold;
|
|
||||||
this.compressionLevel = compressionLevel;
|
|
||||||
this.loginRatelimit = loginRatelimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Advanced(Toml toml) {
|
private Advanced(Toml toml) {
|
||||||
if (toml != null) {
|
if (toml != null) {
|
||||||
this.compressionThreshold = toml.getLong("compression-threshold", 1024L).intValue();
|
this.compressionThreshold = toml.getLong("compression-threshold", 1024L).intValue();
|
||||||
this.compressionLevel = toml.getLong("compression-level", -1L).intValue();
|
this.compressionLevel = toml.getLong("compression-level", -1L).intValue();
|
||||||
this.loginRatelimit = toml.getLong("login-ratelimit", 3000L).intValue();
|
this.loginRatelimit = toml.getLong("login-ratelimit", 3000L).intValue();
|
||||||
|
this.connectionTimeout = toml.getLong("connection-timeout", 5000L).intValue();
|
||||||
|
this.readTimeout = toml.getLong("read-timeout", 30000L).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,33 +452,31 @@ public class VelocityConfiguration extends AnnotatedConfig {
|
|||||||
return compressionThreshold;
|
return compressionThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCompressionThreshold(int compressionThreshold) {
|
|
||||||
this.compressionThreshold = compressionThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCompressionLevel() {
|
public int getCompressionLevel() {
|
||||||
return compressionLevel;
|
return compressionLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCompressionLevel(int compressionLevel) {
|
|
||||||
this.compressionLevel = compressionLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLoginRatelimit() {
|
public int getLoginRatelimit() {
|
||||||
return loginRatelimit;
|
return loginRatelimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginRatelimit(int loginRatelimit) {
|
public int getConnectionTimeout() {
|
||||||
this.loginRatelimit = loginRatelimit;
|
return connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Advanced{"
|
return "Advanced{" +
|
||||||
+ "compressionThreshold=" + compressionThreshold
|
"compressionThreshold=" + compressionThreshold +
|
||||||
+ ", compressionLevel=" + compressionLevel
|
", compressionLevel=" + compressionLevel +
|
||||||
+ ", loginRatelimit=" + loginRatelimit
|
", loginRatelimit=" + loginRatelimit +
|
||||||
+ '}';
|
", connectionTimeout=" + connectionTimeout +
|
||||||
|
", readTimeout=" + readTimeout +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,18 +508,10 @@ public class VelocityConfiguration extends AnnotatedConfig {
|
|||||||
return queryEnabled;
|
return queryEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryEnabled(boolean queryEnabled) {
|
|
||||||
this.queryEnabled = queryEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getQueryPort() {
|
public int getQueryPort() {
|
||||||
return queryPort;
|
return queryPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryPort(int queryPort) {
|
|
||||||
this.queryPort = queryPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Query{"
|
return "Query{"
|
||||||
|
@ -33,8 +33,6 @@ import static com.velocitypowered.proxy.network.Connections.HANDLER;
|
|||||||
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER;
|
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER;
|
||||||
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER;
|
import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER;
|
||||||
import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
|
import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
|
||||||
import static com.velocitypowered.proxy.network.Connections.CONNECTION_TIMEOUT_SECONDS;
|
|
||||||
import static com.velocitypowered.proxy.network.Connections.SERVER_READ_TIMEOUT_SECONDS;
|
|
||||||
|
|
||||||
public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection {
|
public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection {
|
||||||
static final AttributeKey<CompletableFuture<ConnectionRequestBuilder.Result>> CONNECTION_NOTIFIER =
|
static final AttributeKey<CompletableFuture<ConnectionRequestBuilder.Result>> CONNECTION_NOTIFIER =
|
||||||
@ -56,13 +54,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
public CompletableFuture<ConnectionRequestBuilder.Result> connect() {
|
public CompletableFuture<ConnectionRequestBuilder.Result> connect() {
|
||||||
CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>();
|
CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>();
|
||||||
server.initializeGenericBootstrap()
|
server.initializeGenericBootstrap()
|
||||||
.option(ChannelOption.TCP_NODELAY, true)
|
|
||||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECTION_TIMEOUT_SECONDS * 1000)
|
|
||||||
.handler(new ChannelInitializer<Channel>() {
|
.handler(new ChannelInitializer<Channel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel ch) throws Exception {
|
protected void initChannel(Channel ch) throws Exception {
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(SERVER_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS))
|
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.SECONDS))
|
||||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||||
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND))
|
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND))
|
||||||
|
@ -75,7 +75,7 @@ public final class ConnectionManager {
|
|||||||
@Override
|
@Override
|
||||||
protected void initChannel(final Channel ch) {
|
protected void initChannel(final Channel ch) {
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(CLIENT_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS))
|
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.SECONDS))
|
||||||
.addLast(LEGACY_PING_DECODER, new LegacyPingDecoder())
|
.addLast(LEGACY_PING_DECODER, new LegacyPingDecoder())
|
||||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||||
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
|
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
|
||||||
@ -89,7 +89,6 @@ public final class ConnectionManager {
|
|||||||
ch.pipeline().addLast(Connections.HANDLER, connection);
|
ch.pipeline().addLast(Connections.HANDLER, connection);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECTION_TIMEOUT_SECONDS * 1000)
|
|
||||||
.childOption(ChannelOption.TCP_NODELAY, true)
|
.childOption(ChannelOption.TCP_NODELAY, true)
|
||||||
.childOption(ChannelOption.IP_TOS, 0x18)
|
.childOption(ChannelOption.IP_TOS, 0x18)
|
||||||
.localAddress(address);
|
.localAddress(address);
|
||||||
@ -126,7 +125,9 @@ public final class ConnectionManager {
|
|||||||
public Bootstrap createWorker() {
|
public Bootstrap createWorker() {
|
||||||
return new Bootstrap()
|
return new Bootstrap()
|
||||||
.channel(this.transportType.socketChannelClass)
|
.channel(this.transportType.socketChannelClass)
|
||||||
.group(this.workerGroup);
|
.group(this.workerGroup)
|
||||||
|
.option(ChannelOption.TCP_NODELAY, true)
|
||||||
|
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, server.getConfiguration().getConnectTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
@ -13,8 +13,4 @@ public interface Connections {
|
|||||||
String MINECRAFT_DECODER = "minecraft-decoder";
|
String MINECRAFT_DECODER = "minecraft-decoder";
|
||||||
String MINECRAFT_ENCODER = "minecraft-encoder";
|
String MINECRAFT_ENCODER = "minecraft-encoder";
|
||||||
String READ_TIMEOUT = "read-timeout";
|
String READ_TIMEOUT = "read-timeout";
|
||||||
|
|
||||||
int CLIENT_READ_TIMEOUT_SECONDS = 30; // client -> proxy
|
|
||||||
int SERVER_READ_TIMEOUT_SECONDS = 30; // proxy -> server
|
|
||||||
int CONNECTION_TIMEOUT_SECONDS = 5;
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren