diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 3d2d4a40e..6e590b3c4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -265,15 +265,11 @@ public class VelocityServer implements ProxyServer { logger.info("Loaded {} plugins", pluginManager.getPlugins().size()); } - public EventLoopGroup getWorkerGroup() { - return this.cm.getWorkerGroup(); - } - - public Bootstrap initializeGenericBootstrap() { + public Bootstrap createBootstrap() { return this.cm.createWorker(); } - public Bootstrap initializeGenericBootstrap(EventLoopGroup group) { + public Bootstrap createBootstrap(EventLoopGroup group) { return this.cm.createWorker(group); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index bb4142904..39e0bbd0c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -12,7 +12,6 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.server.ServerInfo; @@ -77,7 +76,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, CompletableFuture result = new CompletableFuture<>(); // Note: we use the event loop for the connection the player is on. This reduces context // switches. - server.initializeGenericBootstrap(proxyPlayer.getMinecraftConnection().eventLoop()) + server.createBootstrap(proxyPlayer.getMinecraftConnection().eventLoop()) .handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 97b0341c6..c3b1d195f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.Nullable; public final class ConnectionManager { @@ -113,23 +114,23 @@ public final class ConnectionManager { } public Bootstrap createWorker() { - return this.createWorker(this.workerGroup); + return this.createWorker(null); } /** * Creates a TCP {@link Bootstrap} using Velocity's event loops. * - * @param group the event loop group to use + * @param group the event loop group to use. Use {@code null} for the default worker group. * * @return a new {@link Bootstrap} */ - public Bootstrap createWorker(EventLoopGroup group) { + public Bootstrap createWorker(@Nullable EventLoopGroup group) { return new Bootstrap() .channel(this.transportType.socketChannelClass) - .group(group) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, this.server.getConfiguration().getConnectTimeout()) + .group(group == null ? this.workerGroup : group) .resolver(this.resolverGroup); } @@ -164,10 +165,6 @@ public final class ConnectionManager { return bossGroup; } - public EventLoopGroup getWorkerGroup() { - return workerGroup; - } - public ServerChannelInitializerHolder getServerChannelInitializer() { return this.serverChannelInitializer; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java b/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java index ec2436b72..5d0211a09 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java @@ -9,7 +9,6 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoop; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpContentCompressor; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; @@ -22,6 +21,7 @@ import java.net.URL; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import javax.net.ssl.SSLEngine; +import org.checkerframework.checker.nullness.qual.Nullable; public class NettyHttpClient { @@ -38,7 +38,7 @@ public class NettyHttpClient { this.server = server; } - private ChannelFuture establishConnection(URL url, EventLoop loop) { + private ChannelFuture establishConnection(URL url, @Nullable EventLoop loop) { String host = url.getHost(); int port = url.getPort(); boolean ssl = url.getProtocol().equals("https"); @@ -47,7 +47,7 @@ public class NettyHttpClient { } InetSocketAddress address = InetSocketAddress.createUnresolved(host, port); - return server.initializeGenericBootstrap(loop) + return server.createBootstrap(loop) .handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { @@ -74,7 +74,7 @@ public class NettyHttpClient { * @param loop the event loop to use * @return a future representing the response */ - public CompletableFuture get(URL url, EventLoop loop) { + public CompletableFuture get(URL url, @Nullable EventLoop loop) { CompletableFuture reply = new CompletableFuture<>(); establishConnection(url, loop) .addListener((ChannelFutureListener) future -> { @@ -109,18 +109,18 @@ public class NettyHttpClient { */ public CompletableFuture post(URL url, ByteBuf body, Consumer decorator) { - return post(url, server.getWorkerGroup().next(), body, decorator); + return post(url, null, body, decorator); } /** * Attempts an HTTP POST request to the specified URL. * @param url the URL to fetch * @param loop the event loop to use - * @param body the body to post + * @param body the body to post - the HTTP client takes ownership of the buffer * @param decorator a consumer that can modify the request as required * @return a future representing the response */ - public CompletableFuture post(URL url, EventLoop loop, ByteBuf body, + public CompletableFuture post(URL url, @Nullable EventLoop loop, ByteBuf body, Consumer decorator) { CompletableFuture reply = new CompletableFuture<>(); establishConnection(url, loop) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index c0109467e..6261d5614 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -19,7 +19,6 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; @@ -63,7 +62,7 @@ public class VelocityRegisteredServer implements RegisteredServer { throw new IllegalStateException("No Velocity proxy instance available"); } CompletableFuture pingFuture = new CompletableFuture<>(); - server.initializeGenericBootstrap() + server.createBootstrap() .handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception {