13
0
geforkt von Mirrors/Velocity

Handle switching bind (MC and GS4).

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-11-20 22:30:52 -05:00
Ursprung 0d94080c74
Commit 01503be4fa
2 geänderte Dateien mit 33 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -242,11 +242,6 @@ public class VelocityServer implements ProxyServer {
return false; return false;
} }
// If we have a new bind address, bind to it
if (!configuration.getBind().equals(newConfiguration.getBind())) {
this.cm.bind(newConfiguration.getBind());
}
// Re-register servers // Re-register servers
for (Map.Entry<String, String> entry : newConfiguration.getServers().entrySet()) { for (Map.Entry<String, String> entry : newConfiguration.getServers().entrySet()) {
ServerInfo newInfo = ServerInfo newInfo =
@ -259,6 +254,23 @@ public class VelocityServer implements ProxyServer {
} }
} }
// If we have a new bind address, bind to it
if (!configuration.getBind().equals(newConfiguration.getBind())) {
this.cm.bind(newConfiguration.getBind());
this.cm.shutdown(configuration.getBind());
}
if (configuration.isQueryEnabled() && (!newConfiguration.isQueryEnabled()
|| newConfiguration.getQueryPort() != configuration.getQueryPort())) {
this.cm.shutdown(new InetSocketAddress(
configuration.getBind().getHostString(), configuration.getQueryPort()));
}
if (newConfiguration.isQueryEnabled()) {
this.cm.queryBind(newConfiguration.getBind().getHostString(),
newConfiguration.getQueryPort());
}
ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit()); ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit());
this.configuration = newConfiguration; this.configuration = newConfiguration;
eventManager.fireAndForget(new ProxyReloadEvent()); eventManager.fireAndForget(new ProxyReloadEvent());

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.network; package com.velocitypowered.proxy.network;
import com.google.common.base.Preconditions;
import com.velocitypowered.natives.util.Natives; import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.netty.GS4QueryHandler; import com.velocitypowered.proxy.protocol.netty.GS4QueryHandler;
@ -11,7 +12,9 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.WriteBufferWaterMark;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -21,7 +24,7 @@ public final class ConnectionManager {
private static final WriteBufferWaterMark SERVER_WRITE_MARK = new WriteBufferWaterMark(1 << 16, private static final WriteBufferWaterMark SERVER_WRITE_MARK = new WriteBufferWaterMark(1 << 16,
1 << 18); 1 << 18);
private static final Logger LOGGER = LogManager.getLogger(ConnectionManager.class); private static final Logger LOGGER = LogManager.getLogger(ConnectionManager.class);
private final Set<Channel> endpoints = new HashSet<>(); private final Map<InetSocketAddress, Channel> endpoints = new HashMap<>();
private final TransportType transportType; private final TransportType transportType;
private final EventLoopGroup bossGroup; private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup; private final EventLoopGroup workerGroup;
@ -55,7 +58,7 @@ public final class ConnectionManager {
.addListener((ChannelFutureListener) future -> { .addListener((ChannelFutureListener) future -> {
final Channel channel = future.channel(); final Channel channel = future.channel();
if (future.isSuccess()) { if (future.isSuccess()) {
this.endpoints.add(channel); this.endpoints.put(address, channel);
LOGGER.info("Listening on {}", channel.localAddress()); LOGGER.info("Listening on {}", channel.localAddress());
} else { } else {
LOGGER.error("Can't bind to {}", address, future.cause()); LOGGER.error("Can't bind to {}", address, future.cause());
@ -64,16 +67,17 @@ public final class ConnectionManager {
} }
public void queryBind(final String hostname, final int port) { public void queryBind(final String hostname, final int port) {
InetSocketAddress address = new InetSocketAddress(hostname, port);
final Bootstrap bootstrap = new Bootstrap() final Bootstrap bootstrap = new Bootstrap()
.channel(this.transportType.datagramChannelClass) .channel(this.transportType.datagramChannelClass)
.group(this.workerGroup) .group(this.workerGroup)
.handler(new GS4QueryHandler(this.server)) .handler(new GS4QueryHandler(this.server))
.localAddress(hostname, port); .localAddress(address);
bootstrap.bind() bootstrap.bind()
.addListener((ChannelFutureListener) future -> { .addListener((ChannelFutureListener) future -> {
final Channel channel = future.channel(); final Channel channel = future.channel();
if (future.isSuccess()) { if (future.isSuccess()) {
this.endpoints.add(channel); this.endpoints.put(address, channel);
LOGGER.info("Listening for GS4 query on {}", channel.localAddress()); LOGGER.info("Listening for GS4 query on {}", channel.localAddress());
} else { } else {
LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause());
@ -90,8 +94,15 @@ public final class ConnectionManager {
this.server.getConfiguration().getConnectTimeout()); this.server.getConfiguration().getConnectTimeout());
} }
public void shutdown(InetSocketAddress oldBind) {
Channel serverChannel = endpoints.remove(oldBind);
Preconditions.checkState(serverChannel != null, "Endpoint %s not registered", oldBind);
LOGGER.info("Closing endpoint {}", serverChannel.localAddress());
serverChannel.close().syncUninterruptibly();
}
public void shutdown() { public void shutdown() {
for (final Channel endpoint : this.endpoints) { for (final Channel endpoint : this.endpoints.values()) {
try { try {
LOGGER.info("Closing endpoint {}", endpoint.localAddress()); LOGGER.info("Closing endpoint {}", endpoint.localAddress());
endpoint.close().sync(); endpoint.close().sync();