diff --git a/proxy/src/main/java/google/registry/proxy/ProxyModule.java b/proxy/src/main/java/google/registry/proxy/ProxyModule.java index 8bc02a7c7..361ea866d 100644 --- a/proxy/src/main/java/google/registry/proxy/ProxyModule.java +++ b/proxy/src/main/java/google/registry/proxy/ProxyModule.java @@ -25,8 +25,6 @@ import com.google.api.services.cloudkms.v1.model.DecryptRequest; import com.google.api.services.storage.Storage; import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.GoogleCredentials; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import com.google.common.flogger.LoggerConfig; import com.google.monitoring.metrics.MetricReporter; import dagger.Component; @@ -185,12 +183,6 @@ public class ProxyModule { return Optional.ofNullable(httpsWhoisPort).orElse(config.webWhois.httpsPort); } - @Provides - ImmutableMap providePortToProtocolMap( - Set protocolSet) { - return Maps.uniqueIndex(protocolSet, Protocol::port); - } - @Provides Environment provideEnvironment() { return env; @@ -359,7 +351,7 @@ public class ProxyModule { }) interface ProxyComponent { - ImmutableMap portToProtocolMap(); + Set protocols(); MetricReporter metricReporter(); } diff --git a/proxy/src/main/java/google/registry/proxy/ProxyServer.java b/proxy/src/main/java/google/registry/proxy/ProxyServer.java index 03613992a..0df563443 100644 --- a/proxy/src/main/java/google/registry/proxy/ProxyServer.java +++ b/proxy/src/main/java/google/registry/proxy/ProxyServer.java @@ -20,7 +20,7 @@ import static google.registry.proxy.handler.RelayHandler.RELAY_CHANNEL_KEY; import static google.registry.proxy.handler.RelayHandler.writeToRelayChannel; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.flogger.FluentLogger; import com.google.monitoring.metrics.MetricReporter; import google.registry.proxy.Protocol.BackendProtocol; @@ -51,28 +51,27 @@ import java.util.concurrent.TimeoutException; import javax.inject.Provider; /** - * A multi-protocol proxy server that listens on port(s) specified in {@link - * ProxyModule.ProxyComponent#portToProtocolMap()} }. + * A multi-protocol proxy server that listens for protocols in {@link + * ProxyModule.ProxyComponent#protocols()} }. */ public class ProxyServer implements Runnable { - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); /** Maximum length of the queue of incoming connections. */ private static final int MAX_SOCKET_BACKLOG = 128; - private final ImmutableMap portToProtocolMap; + private final ImmutableSet protocols; private final HashMap portToChannelMap = new HashMap<>(); private final EventLoopGroup eventGroup = new NioEventLoopGroup(); ProxyServer(ProxyComponent proxyComponent) { - this.portToProtocolMap = proxyComponent.portToProtocolMap(); + this.protocols = ImmutableSet.copyOf(proxyComponent.protocols()); } /** * A {@link ChannelInitializer} for connections from a client of a certain protocol. * - *

The {@link #initChannel} method does the following: + *

The {@link #initChannel(NioSocketChannel)} method does the following: * *

    *
  1. Determine the {@link FrontendProtocol} of the inbound {@link Channel} from its parent @@ -263,8 +262,9 @@ public class ProxyServer implements Runnable { .childOption(ChannelOption.AUTO_READ, false); // Bind to each port specified in portToHandlersMap. - portToProtocolMap.forEach( - (port, protocol) -> { + protocols.forEach( + protocol -> { + int port = protocol.port(); try { // Wait for binding to be established for each listening port. ChannelFuture serverChannelFuture = serverBootstrap.bind(port).sync();