A DNS-based NameResolver. Each A or AAAA record emits an EquivalentAddressGroup in the list passed to NameResolver.Listener2#onResult2(ResolutionResult). @see DnsNameResolverProvider
| 63 | * @see DnsNameResolverProvider |
| 64 | */ |
| 65 | public class DnsNameResolver extends NameResolver { |
| 66 | |
| 67 | private static final Logger logger = Logger.getLogger(DnsNameResolver.class.getName()); |
| 68 | |
| 69 | private static final String SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY = "clientLanguage"; |
| 70 | private static final String SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY = "percentage"; |
| 71 | private static final String SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY = "clientHostname"; |
| 72 | private static final String SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY = "serviceConfig"; |
| 73 | |
| 74 | // From https://github.com/grpc/proposal/blob/master/A2-service-configs-in-dns.md |
| 75 | static final String SERVICE_CONFIG_PREFIX = "grpc_config="; |
| 76 | private static final Set<String> SERVICE_CONFIG_CHOICE_KEYS = |
| 77 | Collections.unmodifiableSet( |
| 78 | new HashSet<>( |
| 79 | Arrays.asList( |
| 80 | SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY, |
| 81 | SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY, |
| 82 | SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY, |
| 83 | SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY))); |
| 84 | |
| 85 | // From https://github.com/grpc/proposal/blob/master/A2-service-configs-in-dns.md |
| 86 | private static final String SERVICE_CONFIG_NAME_PREFIX = "_grpc_config."; |
| 87 | |
| 88 | private static final String JNDI_PROPERTY = |
| 89 | System.getProperty("io.grpc.internal.DnsNameResolverProvider.enable_jndi", "true"); |
| 90 | private static final String JNDI_LOCALHOST_PROPERTY = |
| 91 | System.getProperty("io.grpc.internal.DnsNameResolverProvider.enable_jndi_localhost", "false"); |
| 92 | private static final String JNDI_TXT_PROPERTY = |
| 93 | System.getProperty("io.grpc.internal.DnsNameResolverProvider.enable_service_config", "false"); |
| 94 | |
| 95 | /** |
| 96 | * Java networking system properties name for caching DNS result. |
| 97 | * |
| 98 | * <p>Default value is -1 (cache forever) if security manager is installed. If security manager is |
| 99 | * not installed, the ttl value is {@code null} which falls back to {@link |
| 100 | * #DEFAULT_NETWORK_CACHE_TTL_SECONDS gRPC default value}. |
| 101 | * |
| 102 | * <p>For android, gRPC uses a fixed value; this property value will be ignored. |
| 103 | */ |
| 104 | @VisibleForTesting |
| 105 | static final String NETWORKADDRESS_CACHE_TTL_PROPERTY = "networkaddress.cache.ttl"; |
| 106 | /** Default DNS cache duration if network cache ttl value is not specified ({@code null}). */ |
| 107 | @VisibleForTesting |
| 108 | static final long DEFAULT_NETWORK_CACHE_TTL_SECONDS = 30; |
| 109 | |
| 110 | @VisibleForTesting |
| 111 | static boolean enableJndi = Boolean.parseBoolean(JNDI_PROPERTY); |
| 112 | @VisibleForTesting |
| 113 | static boolean enableJndiLocalhost = Boolean.parseBoolean(JNDI_LOCALHOST_PROPERTY); |
| 114 | @VisibleForTesting |
| 115 | protected static boolean enableTxt = Boolean.parseBoolean(JNDI_TXT_PROPERTY); |
| 116 | |
| 117 | private static final ResourceResolverFactory resourceResolverFactory = |
| 118 | getResourceResolverFactory(DnsNameResolver.class.getClassLoader()); |
| 119 | |
| 120 | @VisibleForTesting |
| 121 | final ProxyDetector proxyDetector; |
| 122 |
nothing calls this directly
no test coverage detected