From f491b8b15cb634eac60378b0504a715c0ad8ccda Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 20 Nov 2017 13:14:17 +0100 Subject: Use InetAddresses.forString instead of InetAddress.getByName Unlike InetAddress.getByName(), Guava's InetAddresses.forString() never cause DNS services to be accessed. JDK equivalents whenever you are expecting to handle only IP address string literals, so there is no blocking DNS penalty for a malformed string. See: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/net/InetAddresses.html#forString-java.lang.String- Change-Id: Id1fc5fa45465b0e0b3aea7d60b9fdb855240d902 Signed-off-by: Marek Gradzki --- .../io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java | 5 +++-- .../main/java/io/fd/honeycomb/infra/bgp/BgpServerProvider.java | 9 ++------- .../honeycomb/northbound/netconf/NetconfSshServerProvider.java | 10 ++-------- .../honeycomb/northbound/netconf/NetconfTcpServerProvider.java | 10 ++-------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java b/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java index 93dddf113..d2dc51af5 100644 --- a/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java +++ b/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue; import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; +import com.google.common.net.InetAddresses; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; @@ -108,8 +109,8 @@ public class BgpDistributionTest { } private void assertBgpOpenIsSent(final String peerAddress) throws IOException, InterruptedException { - final InetAddress bgpHost = InetAddress.getByName(BGP_HOST_ADDRESS); - final InetAddress bgpPeerAddress = InetAddress.getByName(peerAddress); + final InetAddress bgpHost = InetAddresses.forString(BGP_HOST_ADDRESS); + final InetAddress bgpPeerAddress = InetAddresses.forString(peerAddress); try (final Socket localhost = new Socket(bgpHost, BGP_PORT, bgpPeerAddress, 0); final InputStream inputStream = localhost.getInputStream()) { // Wait until bgp message is sent diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpServerProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpServerProvider.java index 876a39f14..5f9104cf1 100644 --- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpServerProvider.java +++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpServerProvider.java @@ -17,6 +17,7 @@ package io.fd.honeycomb.infra.bgp; import com.google.common.base.Preconditions; +import com.google.common.net.InetAddresses; import com.google.inject.Inject; import io.fd.honeycomb.binding.init.ProviderTrait; import io.netty.channel.Channel; @@ -26,7 +27,6 @@ import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollChannelOption; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.UnknownHostException; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences; @@ -49,12 +49,7 @@ public final class BgpServerProvider extends ProviderTrait