3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 14:40:21 +02:00

Minor Netty cleanup

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-20 00:30:44 -04:00
Ursprung 85e5fb4827
Commit 6d5bacb262
5 geänderte Dateien mit 16 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -265,15 +265,11 @@ public class VelocityServer implements ProxyServer {
logger.info("Loaded {} plugins", pluginManager.getPlugins().size()); logger.info("Loaded {} plugins", pluginManager.getPlugins().size());
} }
public EventLoopGroup getWorkerGroup() { public Bootstrap createBootstrap() {
return this.cm.getWorkerGroup();
}
public Bootstrap initializeGenericBootstrap() {
return this.cm.createWorker(); return this.cm.createWorker();
} }
public Bootstrap initializeGenericBootstrap(EventLoopGroup group) { public Bootstrap createBootstrap(EventLoopGroup group) {
return this.cm.createWorker(group); return this.cm.createWorker(group);
} }

Datei anzeigen

@ -12,7 +12,6 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerInfo;
@ -77,7 +76,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
CompletableFuture<Impl> result = new CompletableFuture<>(); CompletableFuture<Impl> result = new CompletableFuture<>();
// Note: we use the event loop for the connection the player is on. This reduces context // Note: we use the event loop for the connection the player is on. This reduces context
// switches. // switches.
server.initializeGenericBootstrap(proxyPlayer.getMinecraftConnection().eventLoop()) server.createBootstrap(proxyPlayer.getMinecraftConnection().eventLoop())
.handler(new ChannelInitializer<Channel>() { .handler(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel ch) throws Exception { protected void initChannel(Channel ch) throws Exception {

Datei anzeigen

@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class ConnectionManager { public final class ConnectionManager {
@ -113,23 +114,23 @@ public final class ConnectionManager {
} }
public Bootstrap createWorker() { public Bootstrap createWorker() {
return this.createWorker(this.workerGroup); return this.createWorker(null);
} }
/** /**
* Creates a TCP {@link Bootstrap} using Velocity's event loops. * 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} * @return a new {@link Bootstrap}
*/ */
public Bootstrap createWorker(EventLoopGroup group) { public Bootstrap createWorker(@Nullable EventLoopGroup group) {
return new Bootstrap() return new Bootstrap()
.channel(this.transportType.socketChannelClass) .channel(this.transportType.socketChannelClass)
.group(group)
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, .option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
this.server.getConfiguration().getConnectTimeout()) this.server.getConfiguration().getConnectTimeout())
.group(group == null ? this.workerGroup : group)
.resolver(this.resolverGroup); .resolver(this.resolverGroup);
} }
@ -164,10 +165,6 @@ public final class ConnectionManager {
return bossGroup; return bossGroup;
} }
public EventLoopGroup getWorkerGroup() {
return workerGroup;
}
public ServerChannelInitializerHolder getServerChannelInitializer() { public ServerChannelInitializerHolder getServerChannelInitializer() {
return this.serverChannelInitializer; return this.serverChannelInitializer;
} }

Datei anzeigen

@ -9,7 +9,6 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpClientCodec; 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.HttpHeaderNames;
import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpRequest;
@ -22,6 +21,7 @@ import java.net.URL;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import org.checkerframework.checker.nullness.qual.Nullable;
public class NettyHttpClient { public class NettyHttpClient {
@ -38,7 +38,7 @@ public class NettyHttpClient {
this.server = server; this.server = server;
} }
private ChannelFuture establishConnection(URL url, EventLoop loop) { private ChannelFuture establishConnection(URL url, @Nullable EventLoop loop) {
String host = url.getHost(); String host = url.getHost();
int port = url.getPort(); int port = url.getPort();
boolean ssl = url.getProtocol().equals("https"); boolean ssl = url.getProtocol().equals("https");
@ -47,7 +47,7 @@ public class NettyHttpClient {
} }
InetSocketAddress address = InetSocketAddress.createUnresolved(host, port); InetSocketAddress address = InetSocketAddress.createUnresolved(host, port);
return server.initializeGenericBootstrap(loop) return server.createBootstrap(loop)
.handler(new ChannelInitializer<Channel>() { .handler(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel ch) throws Exception { protected void initChannel(Channel ch) throws Exception {
@ -74,7 +74,7 @@ public class NettyHttpClient {
* @param loop the event loop to use * @param loop the event loop to use
* @return a future representing the response * @return a future representing the response
*/ */
public CompletableFuture<SimpleHttpResponse> get(URL url, EventLoop loop) { public CompletableFuture<SimpleHttpResponse> get(URL url, @Nullable EventLoop loop) {
CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>(); CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>();
establishConnection(url, loop) establishConnection(url, loop)
.addListener((ChannelFutureListener) future -> { .addListener((ChannelFutureListener) future -> {
@ -109,18 +109,18 @@ public class NettyHttpClient {
*/ */
public CompletableFuture<SimpleHttpResponse> post(URL url, ByteBuf body, public CompletableFuture<SimpleHttpResponse> post(URL url, ByteBuf body,
Consumer<HttpRequest> decorator) { Consumer<HttpRequest> decorator) {
return post(url, server.getWorkerGroup().next(), body, decorator); return post(url, null, body, decorator);
} }
/** /**
* Attempts an HTTP POST request to the specified URL. * Attempts an HTTP POST request to the specified URL.
* @param url the URL to fetch * @param url the URL to fetch
* @param loop the event loop to use * @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 * @param decorator a consumer that can modify the request as required
* @return a future representing the response * @return a future representing the response
*/ */
public CompletableFuture<SimpleHttpResponse> post(URL url, EventLoop loop, ByteBuf body, public CompletableFuture<SimpleHttpResponse> post(URL url, @Nullable EventLoop loop, ByteBuf body,
Consumer<HttpRequest> decorator) { Consumer<HttpRequest> decorator) {
CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>(); CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>();
establishConnection(url, loop) establishConnection(url, loop)

Datei anzeigen

@ -19,7 +19,6 @@ import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.ProtocolUtils; 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.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
@ -63,7 +62,7 @@ public class VelocityRegisteredServer implements RegisteredServer {
throw new IllegalStateException("No Velocity proxy instance available"); throw new IllegalStateException("No Velocity proxy instance available");
} }
CompletableFuture<ServerPing> pingFuture = new CompletableFuture<>(); CompletableFuture<ServerPing> pingFuture = new CompletableFuture<>();
server.initializeGenericBootstrap() server.createBootstrap()
.handler(new ChannelInitializer<Channel>() { .handler(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel ch) throws Exception { protected void initChannel(Channel ch) throws Exception {