Class DnsNameResolver

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY

        private static final java.lang.String SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY
        See Also:
        Constant Field Values
      • SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY

        private static final java.lang.String SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY
        See Also:
        Constant Field Values
      • SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY

        private static final java.lang.String SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY
        See Also:
        Constant Field Values
      • SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY

        private static final java.lang.String SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY
        See Also:
        Constant Field Values
      • SERVICE_CONFIG_PREFIX

        static final java.lang.String SERVICE_CONFIG_PREFIX
        See Also:
        Constant Field Values
      • SERVICE_CONFIG_CHOICE_KEYS

        private static final java.util.Set<java.lang.String> SERVICE_CONFIG_CHOICE_KEYS
      • SERVICE_CONFIG_NAME_PREFIX

        private static final java.lang.String SERVICE_CONFIG_NAME_PREFIX
        See Also:
        Constant Field Values
      • JNDI_PROPERTY

        private static final java.lang.String JNDI_PROPERTY
      • JNDI_LOCALHOST_PROPERTY

        private static final java.lang.String JNDI_LOCALHOST_PROPERTY
      • JNDI_TXT_PROPERTY

        private static final java.lang.String JNDI_TXT_PROPERTY
      • NETWORKADDRESS_CACHE_TTL_PROPERTY

        static final java.lang.String NETWORKADDRESS_CACHE_TTL_PROPERTY
        Java networking system properties name for caching DNS result.

        Default value is -1 (cache forever) if security manager is installed. If security manager is not installed, the ttl value is null which falls back to gRPC default value.

        For android, gRPC doesn't attempt to cache; this property value will be ignored.

        See Also:
        Constant Field Values
      • DEFAULT_NETWORK_CACHE_TTL_SECONDS

        static final long DEFAULT_NETWORK_CACHE_TTL_SECONDS
        Default DNS cache duration if network cache ttl value is not specified (null).
        See Also:
        Constant Field Values
      • enableJndi

        static boolean enableJndi
      • enableJndiLocalhost

        static boolean enableJndiLocalhost
      • enableTxt

        protected static boolean enableTxt
      • localHostname

        private static java.lang.String localHostname
        Access through getLocalHostname().
      • random

        private final java.util.Random random
      • authority

        private final java.lang.String authority
      • host

        private final java.lang.String host
      • port

        private final int port
      • cacheTtlNanos

        private final long cacheTtlNanos
      • stopwatch

        private final com.google.common.base.Stopwatch stopwatch
      • resolved

        protected boolean resolved
      • shutdown

        private boolean shutdown
      • executor

        private java.util.concurrent.Executor executor
      • usingExecutorResource

        private final boolean usingExecutorResource
        True if using an executor resource that should be released after use.
      • resolving

        private boolean resolving
    • Constructor Detail

      • DnsNameResolver

        protected DnsNameResolver​(@Nullable
                                  java.lang.String nsAuthority,
                                  java.lang.String name,
                                  NameResolver.Args args,
                                  SharedResourceHolder.Resource<java.util.concurrent.Executor> executorResource,
                                  com.google.common.base.Stopwatch stopwatch,
                                  boolean isAndroid)
    • Method Detail

      • getServiceAuthority

        public java.lang.String getServiceAuthority()
        Description copied from class: NameResolver
        Returns the authority used to authenticate connections to servers. It must be from a trusted source, because if the authority is tampered with, RPCs may be sent to the attackers which may leak sensitive user data.

        An implementation must generate it without blocking, typically in line, and must keep it unchanged. NameResolvers created from the same factory with the same argument must return the same authority.

        Specified by:
        getServiceAuthority in class NameResolver
      • getHost

        protected java.lang.String getHost()
      • detectProxy

        @Nullable
        private EquivalentAddressGroup detectProxy()
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • parseServiceConfig

        @Nullable
        static NameResolver.ConfigOrError parseServiceConfig​(java.util.List<java.lang.String> rawTxtRecords,
                                                             java.util.Random random,
                                                             java.lang.String localHostname)
      • resolve

        private void resolve()
      • cacheRefreshRequired

        private boolean cacheRefreshRequired()
      • shutdown

        public void shutdown()
        Description copied from class: NameResolver
        Stops the resolution. Updates to the Listener will stop.
        Specified by:
        shutdown in class NameResolver
      • getPort

        final int getPort()
      • parseTxtResults

        static java.util.List<java.util.Map<java.lang.String,​?>> parseTxtResults​(java.util.List<java.lang.String> txtRecords)
                                                                                throws java.io.IOException
        Parse TXT service config records as JSON.
        Throws:
        java.io.IOException - if one of the txt records contains improperly formatted JSON.
      • getPercentageFromChoice

        @Nullable
        private static final java.lang.Double getPercentageFromChoice​(java.util.Map<java.lang.String,​?> serviceConfigChoice)
      • getClientLanguagesFromChoice

        @Nullable
        private static final java.util.List<java.lang.String> getClientLanguagesFromChoice​(java.util.Map<java.lang.String,​?> serviceConfigChoice)
      • getHostnamesFromChoice

        @Nullable
        private static final java.util.List<java.lang.String> getHostnamesFromChoice​(java.util.Map<java.lang.String,​?> serviceConfigChoice)
      • getNetworkAddressCacheTtlNanos

        private static long getNetworkAddressCacheTtlNanos​(boolean isAndroid)
        Returns value of network address cache ttl property if not Android environment. For android, DnsNameResolver does not cache the dns lookup result.
      • maybeChooseServiceConfig

        @Nullable
        static java.util.Map<java.lang.String,​?> maybeChooseServiceConfig​(java.util.Map<java.lang.String,​?> choice,
                                                                                java.util.Random random,
                                                                                java.lang.String hostname)
        Determines if a given Service Config choice applies, and if so, returns it.
        Parameters:
        choice - The service config choice.
        Returns:
        The service config object or null if this choice does not apply.
        See Also:
        Service Config in DNS
      • getLocalHostname

        private static java.lang.String getLocalHostname()
      • shouldUseJndi

        protected static boolean shouldUseJndi​(boolean jndiEnabled,
                                               boolean jndiLocalhostEnabled,
                                               java.lang.String target)