Skip to content

Commit deb7123

Browse files
committed
Implement support for DNS over TCP fallback in Netty.
1 parent 9da417a commit deb7123

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/main/generated/io/vertx/core/dns/AddressResolverOptionsConverter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
55
import io.vertx.core.json.impl.JsonUtil;
6-
import java.time.Instant;
7-
import java.time.format.DateTimeFormatter;
86
import java.util.Base64;
97

108
/**
@@ -105,6 +103,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, Address
105103
obj.setServers(list);
106104
}
107105
break;
106+
case "retryWithTcpOnTimeout":
107+
if (member.getValue() instanceof Boolean) {
108+
obj.setRetryWithTcpOnTimeout((Boolean)member.getValue());
109+
}
110+
break;
108111
}
109112
}
110113
}
@@ -141,5 +144,6 @@ static void toJson(AddressResolverOptions obj, java.util.Map<String, Object> jso
141144
obj.getServers().forEach(item -> array.add(item));
142145
json.put("servers", array);
143146
}
147+
json.put("retryWithTcpOnTimeout", obj.isRetryWithTcpOnTimeout());
144148
}
145149
}

src/main/java/io/vertx/core/dns/AddressResolverOptions.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public class AddressResolverOptions {
103103
*/
104104
public static final boolean DEFAULT_ROUND_ROBIN_INET_ADDRESS = false;
105105

106+
/**
107+
* The default retry with TCP on timeout = false
108+
*/
109+
public static final boolean DEFAULT_RETRY_WITH_TCP_ON_TIMEOUT = false;
110+
106111
private String hostsPath;
107112
private Buffer hostsValue;
108113
private int hostsRefreshPeriod;
@@ -118,6 +123,7 @@ public class AddressResolverOptions {
118123
private int ndots;
119124
private boolean rotateServers;
120125
private boolean roundRobinInetAddress;
126+
private boolean retryWithTcpOnTimeout;
121127

122128
public AddressResolverOptions() {
123129
servers = DEFAULT_SERVERS;
@@ -133,6 +139,7 @@ public AddressResolverOptions() {
133139
rotateServers = DEFAULT_ROTATE_SERVERS;
134140
roundRobinInetAddress = DEFAULT_ROUND_ROBIN_INET_ADDRESS;
135141
hostsRefreshPeriod = DEFAULT_HOSTS_REFRESH_PERIOD;
142+
retryWithTcpOnTimeout = DEFAULT_RETRY_WITH_TCP_ON_TIMEOUT;
136143
}
137144

138145
public AddressResolverOptions(AddressResolverOptions other) {
@@ -151,6 +158,7 @@ public AddressResolverOptions(AddressResolverOptions other) {
151158
this.ndots = other.ndots;
152159
this.rotateServers = other.rotateServers;
153160
this.roundRobinInetAddress = other.roundRobinInetAddress;
161+
this.retryWithTcpOnTimeout = other.retryWithTcpOnTimeout;
154162
}
155163

156164
public AddressResolverOptions(JsonObject json) {
@@ -496,6 +504,23 @@ public AddressResolverOptions setRoundRobinInetAddress(boolean roundRobinInetAdd
496504
return this;
497505
}
498506

507+
/**
508+
* @return the value of retry with TCP on timeout flag
509+
*/
510+
public boolean isRetryWithTcpOnTimeout() {
511+
return retryWithTcpOnTimeout;
512+
}
513+
514+
/**
515+
* Set retry with TCP on timeout flag.
516+
*
517+
* @return a reference to this, so the API can be used fluently
518+
*/
519+
public AddressResolverOptions setRetryWithTcpOnTimeout(boolean retryWithTcpOnTimeout) {
520+
this.retryWithTcpOnTimeout = retryWithTcpOnTimeout;
521+
return this;
522+
}
523+
499524
public JsonObject toJson() {
500525
JsonObject json = new JsonObject();
501526
AddressResolverOptionsConverter.toJson(this, json);

src/main/java/io/vertx/core/impl/resolver/DnsResolverProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private DnsResolverProvider(VertxInternal vertx, AddressResolverOptions options)
105105
DnsNameResolverBuilder builder = new DnsNameResolverBuilder();
106106
builder.hostsFileEntriesResolver(this);
107107
builder.channelFactory(() -> vertx.transport().datagramChannel());
108-
builder.socketChannelFactory(() -> (SocketChannel) vertx.transport().channelFactory(false).newChannel());
108+
builder.socketChannelFactory(() ->
109+
(SocketChannel) vertx.transport().channelFactory(false).newChannel(), options.isRetryWithTcpOnTimeout());
109110
builder.nameServerProvider(nameServerAddressProvider);
110111
builder.optResourceEnabled(options.isOptResourceEnabled());
111112
builder.resolveCache(resolveCache);

0 commit comments

Comments
 (0)