Skip to content

Commit

Permalink
Properly handle cached xNAME responses in LookupSession
Browse files Browse the repository at this point in the history
Closes #316, #320
  • Loading branch information
ibauersachs committed Jul 27, 2024
1 parent ba8a959 commit 345e76c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/org/xbill/DNS/lookup/LookupSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
*/
@Slf4j
public class LookupSession {

public static final int DEFAULT_MAX_ITERATIONS = 16;
public static final int DEFAULT_NDOTS = 1;

Expand Down Expand Up @@ -100,6 +101,7 @@ private LookupSession(
*/
@ToString
public static class LookupSessionBuilder {

private Resolver resolver;
private int maxRedirects;
private int ndots;
Expand Down Expand Up @@ -229,8 +231,8 @@ LookupSessionBuilder irrelevantRecordMode(IrrelevantRecordMode irrelevantRecordM
/**
* Enable querying the local hosts database using the system defaults.
*
* @see HostsFileParser
* @return {@code this}.
* @see HostsFileParser
*/
public LookupSessionBuilder defaultHostsFileParser() {
hostsFileParser = new HostsFileParser();
Expand All @@ -241,8 +243,8 @@ public LookupSessionBuilder defaultHostsFileParser() {
* Enable caching using the supplied cache. An existing {@link Cache} for the same class will be
* replaced.
*
* @see Cache
* @return {@code this}.
* @see Cache
*/
public LookupSessionBuilder cache(@NonNull Cache cache) {
if (caches == null) {
Expand All @@ -262,8 +264,8 @@ public LookupSessionBuilder cache(@NonNull Cache cache) {
* Enable caching using the supplied caches. Existing {@link Cache}s for the same class will be
* replaced.
*
* @see Cache
* @return {@code this}.
* @see Cache
*/
public LookupSessionBuilder caches(@NonNull Collection<Cache> caches) {
caches.forEach(this::cache);
Expand All @@ -286,9 +288,9 @@ public LookupSessionBuilder clearCaches() {
* Enable caching using the supplied cache for the given class.
*
* @param dclass unused
* @deprecated use {@link #cache(Cache)}, the {@link Cache} already provides the class.
* @see Cache
* @return {@code this}.
* @see Cache
* @deprecated use {@link #cache(Cache)}, the {@link Cache} already provides the class.
*/
@Deprecated
public LookupSessionBuilder cache(@NonNull Integer dclass, @NonNull Cache cache) {
Expand All @@ -300,10 +302,10 @@ public LookupSessionBuilder cache(@NonNull Integer dclass, @NonNull Cache cache)
* Enable caching using the supplied caches.
*
* @param caches unused
* @return {@code this}.
* @see Cache
* @deprecated use {@link #cache(Cache)} or {@link #caches(Collection)}, the {@link Cache}
* already provides the class.
* @see Cache
* @return {@code this}.
*/
@Deprecated
public LookupSessionBuilder caches(@NonNull Map<Integer, Cache> caches) {
Expand Down Expand Up @@ -581,7 +583,13 @@ private CompletionStage<LookupResult> setResponseToMessageFuture(
new NoSuchRRSetException(queryRecord.getName(), queryRecord.getType()));
}

if (setResponse.isSuccessful()) {
if (setResponse.isCNAME()) {
return CompletableFuture.completedFuture(
new LookupResult(Collections.singletonList(setResponse.getCNAME()), aliases));
} else if (setResponse.isDNAME()) {
return CompletableFuture.completedFuture(
new LookupResult(Collections.singletonList(setResponse.getDNAME()), aliases));
} else if (setResponse.isSuccessful()) {
List<Record> records =
setResponse.answers().stream()
.flatMap(rrset -> rrset.rrs(cycleResults).stream())
Expand Down

0 comments on commit 345e76c

Please sign in to comment.