3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Fully replaced AsyncHttpClient (#1194)

Dieser Commit ist enthalten in:
Adrian 2024-01-17 10:20:27 -05:00 committet von GitHub
Ursprung b22b2dc458
Commit 6d7335b21f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
5 geänderte Dateien mit 12 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,6 @@ spotless = "com.diffplug.spotless:6.12.0"
adventure-bom = "net.kyori:adventure-bom:4.15.0-SNAPSHOT" adventure-bom = "net.kyori:adventure-bom:4.15.0-SNAPSHOT"
adventure-facet = "net.kyori:adventure-platform-facet:4.3.0" adventure-facet = "net.kyori:adventure-platform-facet:4.3.0"
asm = "org.ow2.asm:asm:9.5" asm = "org.ow2.asm:asm:9.5"
asynchttpclient = "org.asynchttpclient:async-http-client:2.12.3"
brigadier = "com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT" brigadier = "com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT"
bstats = "org.bstats:bstats-base:3.0.1" bstats = "org.bstats:bstats-base:3.0.1"
caffeine = "com.github.ben-manes.caffeine:caffeine:3.1.5" caffeine = "com.github.ben-manes.caffeine:caffeine:3.1.5"

Datei anzeigen

@ -119,7 +119,6 @@ dependencies {
implementation(platform(libs.adventure.bom)) implementation(platform(libs.adventure.bom))
implementation("net.kyori:adventure-nbt") implementation("net.kyori:adventure-nbt")
implementation(libs.adventure.facet) implementation(libs.adventure.facet)
implementation(libs.asynchttpclient)
implementation(libs.completablefutures) implementation(libs.completablefutures)
implementation(libs.nightconfig) implementation(libs.nightconfig)
implementation(libs.bstats) implementation(libs.bstats)

Datei anzeigen

@ -101,7 +101,6 @@ import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.translation.TranslationRegistry; import net.kyori.adventure.translation.TranslationRegistry;
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.asynchttpclient.AsyncHttpClient;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -595,10 +594,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
} }
public HttpClient getHttpClient() { public HttpClient getHttpClient() {
return httpClient;
}
public AsyncHttpClient getAsyncHttpClient() {
return cm.getHttpClient(); return cm.getHttpClient();
} }

Datei anzeigen

@ -209,7 +209,11 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
url += "&ip=" + urlFormParameterEscaper().escape(playerIp); url += "&ip=" + urlFormParameterEscaper().escape(playerIp);
} }
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create(url)).build(); final HttpRequest httpRequest = HttpRequest.newBuilder()
.setHeader("User-Agent",
server.getVersion().getName() + "/" + server.getVersion().getVersion())
.uri(URI.create(url))
.build();
server.getHttpClient().sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()) server.getHttpClient().sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString())
.whenCompleteAsync((response, throwable) -> { .whenCompleteAsync((response, throwable) -> {
if (mcConnection.isClosed()) { if (mcConnection.isClosed()) {

Datei anzeigen

@ -17,9 +17,6 @@
package com.velocitypowered.proxy.network; package com.velocitypowered.proxy.network;
import static org.asynchttpclient.Dsl.asyncHttpClient;
import static org.asynchttpclient.Dsl.config;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.proxy.ListenerBoundEvent; import com.velocitypowered.api.event.proxy.ListenerBoundEvent;
import com.velocitypowered.api.event.proxy.ListenerCloseEvent; import com.velocitypowered.api.event.proxy.ListenerCloseEvent;
@ -37,15 +34,11 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.WriteBufferWaterMark;
import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.GlobalEventExecutor;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.http.HttpClient;
import java.util.HashMap; 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.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.filter.FilterContext;
import org.asynchttpclient.filter.FilterContext.FilterContextBuilder;
import org.asynchttpclient.filter.RequestFilter;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -69,7 +62,7 @@ public final class ConnectionManager {
public final BackendChannelInitializerHolder backendChannelInitializer; public final BackendChannelInitializerHolder backendChannelInitializer;
private final SeparatePoolInetNameResolver resolver; private final SeparatePoolInetNameResolver resolver;
private final AsyncHttpClient httpClient; private final HttpClient httpClient;
/** /**
* Initalizes the {@code ConnectionManager}. * Initalizes the {@code ConnectionManager}.
@ -86,20 +79,9 @@ public final class ConnectionManager {
this.backendChannelInitializer = new BackendChannelInitializerHolder( this.backendChannelInitializer = new BackendChannelInitializerHolder(
new BackendChannelInitializer(this.server)); new BackendChannelInitializer(this.server));
this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE); this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE);
this.httpClient = asyncHttpClient(config() this.httpClient = HttpClient.newBuilder()
.setEventLoopGroup(this.workerGroup) .executor(this.workerGroup)
.setUserAgent(server.getVersion().getName() + "/" + server.getVersion().getVersion()) .build();
.addRequestFilter(new RequestFilter() {
@Override
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
return new FilterContextBuilder<>(ctx)
.request(new RequestBuilder(ctx.getRequest())
.setNameResolver(resolver)
.build())
.build();
}
})
.build());
} }
public void logChannelInformation() { public void logChannelInformation() {
@ -256,8 +238,8 @@ public final class ConnectionManager {
return this.serverChannelInitializer; return this.serverChannelInitializer;
} }
public AsyncHttpClient getHttpClient() { public HttpClient getHttpClient() {
return httpClient; return this.httpClient;
} }
public BackendChannelInitializerHolder getBackendChannelInitializer() { public BackendChannelInitializerHolder getBackendChannelInitializer() {