Skip to content
Permalink
Browse files

Merge pull request #82 from dnsjava/resolver-spi

Refactor nameserver lookup to an SPI interface
  • Loading branch information
ibauersachs committed Nov 30, 2019
2 parents 535300f + bc58efc commit 87531546faefbe7b1443ffcbd0378237c0e29e87
Showing with 1,382 additions and 554 deletions.
  1. +38 −0 .github/workflows/build.yml
  2. +24 −2 pom.xml
  3. +3 −2 src/main/java/org/xbill/DNS/Cache.java
  4. +15 −15 src/main/java/org/xbill/DNS/ExtendedResolver.java
  5. +20 −27 src/main/java/org/xbill/DNS/Lookup.java
  6. +1 −1 src/main/java/org/xbill/DNS/Name.java
  7. +76 −421 src/main/java/org/xbill/DNS/ResolverConfig.java
  8. +34 −20 src/main/java/org/xbill/DNS/SimpleResolver.java
  9. +115 −0 src/main/java/org/xbill/DNS/config/AndroidResolverConfigProvider.java
  10. +85 −0 src/main/java/org/xbill/DNS/config/BaseResolverConfigProvider.java
  11. +250 −0 src/main/java/org/xbill/DNS/config/IPHlpAPI.java
  12. +12 −0 src/main/java/org/xbill/DNS/config/InitializationException.java
  13. +98 −0 src/main/java/org/xbill/DNS/config/JndiContextResolverConfigProvider.java
  14. +59 −0 src/main/java/org/xbill/DNS/config/PropertyResolverConfigProvider.java
  15. +128 −0 src/main/java/org/xbill/DNS/config/ResolvConfResolverConfigProvider.java
  16. +31 −0 src/main/java/org/xbill/DNS/config/ResolverConfigProvider.java
  17. +77 −0 src/main/java/org/xbill/DNS/config/SunJvmResolverConfigProvider.java
  18. +125 −0 src/main/java/org/xbill/DNS/config/WindowsResolverConfigProvider.java
  19. +0 −4 src/main/resources/org/xbill/DNS/windows/DNSServer.properties
  20. +0 −4 src/main/resources/org/xbill/DNS/windows/DNSServer_de.properties
  21. +0 −4 src/main/resources/org/xbill/DNS/windows/DNSServer_fr.properties
  22. +0 −4 src/main/resources/org/xbill/DNS/windows/DNSServer_ja.properties
  23. +0 −4 src/main/resources/org/xbill/DNS/windows/DNSServer_pl.properties
  24. +46 −5 src/test/java/org/xbill/DNS/AddressTest.java
  25. +144 −41 src/test/java/org/xbill/DNS/ResolverConfigTest.java
  26. +1 −0 src/test/resources/simplelogger.properties
@@ -0,0 +1,38 @@
name: dnsjava CI

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-16.04, ubuntu-latest, windows-latest ]
java: [ '1.8', '11' ]
arch: [ 'x86', 'x64' ]
exclude:
- os: ubuntu-16.04
arch: x86
- os: ubuntu-latest
arch: x86

name: Java ${{ matrix.java }}/${{ matrix.arch }}/${{ matrix.os }}

steps:
- uses: actions/checkout@v1

- name: Cache Maven dependencies
uses: actions/cache@v1
with:
path: ~/.m2
key: m2

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
architecture: ${{ matrix.arch }}

- name: Build with Maven
run: mvn test jacoco:report -B -"Dgpg.skip"
26 pom.xml
@@ -93,7 +93,11 @@
org.xbill.DNS.*
</Export-Package>
<Import-Package>
!org.xbill.DNS*,!sun.*,android.os;resolution:=optional,*
!org.xbill.DNS*,
!sun.*,
android.*;resolution:=optional,
javax.naming.*;resolution:=optional,
com.sun.jna.*;resolution:=optional,*
</Import-Package>
<Bundle-RequiredExecutionEnvironment>JavaSE-1.8</Bundle-RequiredExecutionEnvironment>
<Bundle-License>
@@ -201,14 +205,26 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
<version>1.7.29</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
@@ -233,6 +249,12 @@
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.29</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
@@ -721,8 +721,9 @@ public SetResponse addMessage(Message in) {
cred = getCred(Section.ADDITIONAL, isAuth);
addRRset(rRset, cred);
}
log.debug("addMessage: {}", response);
return (response);

log.debug("caching {} for {}", response, in.getQuestion().getName());
return response;
}

/**
@@ -4,9 +4,11 @@

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

@@ -264,19 +266,14 @@ private void init() {
*
* @see SimpleResolver
* @see ResolverConfig
* @exception UnknownHostException Failure occured initializing SimpleResolvers
*/
public ExtendedResolver() throws UnknownHostException {
public ExtendedResolver() {
init();
String[] servers = ResolverConfig.getCurrentConfig().servers();
if (servers != null) {
for (String server : servers) {
Resolver r = new SimpleResolver(server);
r.setTimeout(quantum);
resolvers.add(r);
}
} else {
resolvers.add(new SimpleResolver());
List<InetSocketAddress> servers = ResolverConfig.getCurrentConfig().servers();
for (InetSocketAddress server : servers) {
Resolver r = new SimpleResolver(server);
r.setTimeout(quantum);
resolvers.add(r);
}
}

@@ -286,7 +283,7 @@ public ExtendedResolver() throws UnknownHostException {
* @param servers An array of server names for which SimpleResolver contexts should be
* initialized.
* @see SimpleResolver
* @exception UnknownHostException Failure occured initializing SimpleResolvers
* @exception UnknownHostException Failure occurred initializing SimpleResolvers
*/
public ExtendedResolver(String[] servers) throws UnknownHostException {
init();
@@ -305,9 +302,7 @@ public ExtendedResolver(String[] servers) throws UnknownHostException {
*/
public ExtendedResolver(Resolver[] res) {
init();
for (Resolver re : res) {
resolvers.add(re);
}
resolvers.addAll(Arrays.asList(res));
}

@Override
@@ -433,4 +428,9 @@ public void setLoadBalance(boolean flag) {
public void setRetries(int retries) {
this.retries = retries;
}

@Override
public String toString() {
return "ExtendedResolver of " + resolvers;
}
}
@@ -4,7 +4,6 @@

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -30,12 +29,12 @@
public final class Lookup {

private static Resolver defaultResolver;
private static Name[] defaultSearchPath;
private static List<Name> defaultSearchPath;
private static Map<Integer, Cache> defaultCaches;
private static int defaultNdots;

private Resolver resolver;
private Name[] searchPath;
private List<Name> searchPath;
private Cache cache;
private boolean temporary_cache;
private int credibility;
@@ -76,12 +75,7 @@
public static final int TYPE_NOT_FOUND = 4;

public static synchronized void refreshDefault() {

try {
defaultResolver = new ExtendedResolver();
} catch (UnknownHostException e) {
throw new RuntimeException("Failed to initialize resolver");
}
defaultResolver = new ExtendedResolver();
defaultSearchPath = ResolverConfig.getCurrentConfig().searchPath();
defaultCaches = new HashMap<>();
defaultNdots = ResolverConfig.getCurrentConfig().ndots();
@@ -141,7 +135,7 @@ public static synchronized void setDefaultCache(Cache cache, int dclass) {
*
* @return The default search path.
*/
public static synchronized Name[] getDefaultSearchPath() {
public static synchronized List<Name> getDefaultSearchPath() {
return defaultSearchPath;
}

@@ -150,7 +144,7 @@ public static synchronized void setDefaultCache(Cache cache, int dclass) {
*
* @param domains The default search path.
*/
public static synchronized void setDefaultSearchPath(Name[] domains) {
public static synchronized void setDefaultSearchPath(List<Name> domains) {
defaultSearchPath = domains;
}

@@ -165,10 +159,12 @@ public static synchronized void setDefaultSearchPath(String[] domains) throws Te
defaultSearchPath = null;
return;
}
Name[] newdomains = new Name[domains.length];
for (int i = 0; i < domains.length; i++) {
newdomains[i] = Name.fromString(domains[i], Name.root);

List<Name> newdomains = new ArrayList<>(domains.length);
for (String domain : domains) {
newdomains.add(Name.fromString(domain, Name.root));
}

defaultSearchPath = newdomains;
}

@@ -310,7 +306,7 @@ public void setResolver(Resolver resolver) {
*
* @param domains An array of names containing the search path.
*/
public void setSearchPath(Name[] domains) {
public void setSearchPath(List<Name> domains) {
this.searchPath = domains;
}

@@ -325,9 +321,10 @@ public void setSearchPath(String[] domains) throws TextParseException {
this.searchPath = null;
return;
}
Name[] newdomains = new Name[domains.length];
for (int i = 0; i < domains.length; i++) {
newdomains[i] = Name.fromString(domains[i], Name.root);

List<Name> newdomains = new ArrayList<>(domains.length);
for (String domain : domains) {
newdomains.add(Name.fromString(domain, Name.root));
}
this.searchPath = newdomains;
}
@@ -436,10 +433,8 @@ private void processResponse(Name name, SetResponse response) {

private void lookup(Name current) {
SetResponse sr = cache.lookupRecords(current, type, credibility);
if (log.isDebugEnabled()) {
log.debug("lookup {} {}", current, Type.string(type));
log.debug(sr.toString());
}
log.debug("lookup {} {}, cache answer: {}", current, Type.string(type), sr);

processResponse(current, sr);
if (done || doneCurrent) {
return;
@@ -451,7 +446,7 @@ private void lookup(Name current) {
try {
response = resolver.send(query);
} catch (IOException e) {
log.debug("Lookup failed", e);
log.debug("Lookup failed using resolver {}", resolver, e);

// A network error occurred. Press on.
if (e instanceof InterruptedIOException) {
@@ -481,10 +476,8 @@ private void lookup(Name current) {
if (sr == null) {
sr = cache.lookupRecords(current, type, credibility);
}
if (log.isDebugEnabled()) {
log.debug("queried {} {}", current, Type.string(type));
log.debug(sr.toString());
}

log.debug("Queried {} {}: {}", current, Type.string(type), sr);
processResponse(current, sr);
}

@@ -307,7 +307,7 @@ public static Name fromString(String s, Name origin) throws TextParseException {
if (s.equals("@") && origin != null) {
return origin;
} else if (s.equals(".")) {
return (root);
return root;
}

return new Name(s, origin);

0 comments on commit 8753154

Please sign in to comment.
You can’t perform that action at this time.