-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
335 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
package org.xbill.DNS; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.xbill.DNS.io.TcpIoClient; | ||
import org.xbill.DNS.io.UdpIoClient; | ||
|
||
/** | ||
* An implementation of the IO clients that use the internal NIO-based clients. | ||
* | ||
* @see NioUdpClient | ||
* @see NioTcpClient | ||
* @since 3.6 | ||
*/ | ||
public class DefaultIoClient implements TcpIoClient, UdpIoClient { | ||
private final TcpIoClient tcpIoClient; | ||
private final UdpIoClient udpIoClient; | ||
|
||
public DefaultIoClient() { | ||
tcpIoClient = new NioTcpClient(); | ||
udpIoClient = new NioUdpClient(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<byte[]> sendAndReceiveTcp( | ||
InetSocketAddress local, | ||
InetSocketAddress remote, | ||
Message query, | ||
byte[] data, | ||
Duration timeout) { | ||
return tcpIoClient.sendAndReceiveTcp(local, remote, query, data, timeout); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<byte[]> sendAndReceiveUdp( | ||
InetSocketAddress local, | ||
InetSocketAddress remote, | ||
Message query, | ||
byte[] data, | ||
int max, | ||
Duration timeout) { | ||
return udpIoClient.sendAndReceiveUdp(local, remote, query, data, max, timeout); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/xbill/DNS/io/DefaultIoClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
package org.xbill.DNS.io; | ||
|
||
import org.xbill.DNS.DefaultIoClient; | ||
import org.xbill.DNS.SimpleResolver; | ||
|
||
/** | ||
* Serves as a default implementation that is used by the {@link SimpleResolver}, unless otherwise | ||
* configured. This preserves the default behavior (to use the built-in NIO clients) while allowing | ||
* flexibility at the point of use. | ||
* | ||
* @since 3.6 | ||
*/ | ||
public class DefaultIoClientFactory implements IoClientFactory { | ||
/** | ||
* Shared instance because it only serves as a bridge to the static NIO classes and does not need | ||
* to be different per class. | ||
*/ | ||
private static final DefaultIoClient RESOLVER_CLIENT = new DefaultIoClient(); | ||
|
||
@Override | ||
public TcpIoClient createOrGetTcpClient() { | ||
return RESOLVER_CLIENT; | ||
} | ||
|
||
@Override | ||
public UdpIoClient createOrGetUdpClient() { | ||
return RESOLVER_CLIENT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
package org.xbill.DNS.io; | ||
|
||
import org.xbill.DNS.SimpleResolver; | ||
|
||
/** | ||
* Interface for creating the TCP/UDP factories necessary for the {@link SimpleResolver}. | ||
* | ||
* @since 3.6 | ||
*/ | ||
public interface IoClientFactory { | ||
/** | ||
* Create or return a cached/reused instance of the TCP resolver that should be used to send DNS | ||
* data over the wire to the remote target. <br> | ||
* It is the responsibility of this method to manage pooling or connection reuse. This method is | ||
* called right before the connection is made every time the {@link SimpleResolver} is called. The | ||
* implementer of this method should be aware and choose how to pool or reuse connections. | ||
* | ||
* @return an instance of the tcp resolver client | ||
*/ | ||
TcpIoClient createOrGetTcpClient(); | ||
|
||
/** | ||
* Create or return a cached/reused instance of the UDP resolver that should be used to send DNS | ||
* data over the wire to the remote target. | ||
* | ||
* @return an instance of the udp resolver client | ||
*/ | ||
UdpIoClient createOrGetUdpClient(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
package org.xbill.DNS.io; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.xbill.DNS.Message; | ||
import org.xbill.DNS.Resolver; | ||
|
||
/** | ||
* Serves as an interface from a {@link Resolver} to the underlying mechanism for sending bytes over | ||
* the wire as a TCP message. | ||
* | ||
* @since 3.6 | ||
*/ | ||
public interface TcpIoClient { | ||
/** | ||
* Sends a query to a remote server and returns the answer. | ||
* | ||
* @param local Address from which the connection is coming. may be {@code null} and the | ||
* implementation must decide on the local address. | ||
* @param remote Address that the connection should send the data to. | ||
* @param query DNS message representation of the outbound query. | ||
* @param data Raw byte representation of the outbound query. | ||
* @param timeout Duration before the connection will time out and be closed. | ||
* @return A {@link CompletableFuture} that will be completed with the byte value of the response. | ||
* @since 3.6 | ||
*/ | ||
CompletableFuture<byte[]> sendAndReceiveTcp( | ||
InetSocketAddress local, | ||
InetSocketAddress remote, | ||
Message query, | ||
byte[] data, | ||
Duration timeout); | ||
} |
Oops, something went wrong.