Skip to content

Commit

Permalink
Network: Add network.address.serialization.resolve setting (defaults …
Browse files Browse the repository at this point in the history
…to false) to always resolve publish address based on host name, closes elastic#1899.
  • Loading branch information
kimchy committed May 2, 2012
1 parent 21f363e commit 27baac8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -83,6 +84,7 @@ public static interface CustomNameResolver {
@Inject
public NetworkService(Settings settings) {
super(settings);
InetSocketTransportAddress.setResolveAddress(settings.getAsBoolean("network.address.serialization.resolve", false));
}

/**
Expand Down
Expand Up @@ -33,6 +33,12 @@
*/
public class InetSocketTransportAddress implements TransportAddress {

private static boolean resolveAddress = false;

public static void setResolveAddress(boolean resolveAddress) {
InetSocketTransportAddress.resolveAddress = resolveAddress;
}

private InetSocketAddress address;

InetSocketTransportAddress() {
Expand Down Expand Up @@ -118,7 +124,7 @@ public void readFrom(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
if (address.getAddress() != null) {
if (!resolveAddress && address.getAddress() != null) {
out.writeByte((byte) 0);
byte[] bytes = address().getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6)
out.writeByte((byte) bytes.length); // 1 byte
Expand Down

0 comments on commit 27baac8

Please sign in to comment.