Skip to content
Snippets Groups Projects
Commit 3b2cb654 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

fix: Do not exclude hostname when scanning network peers

parent d02da35a
Branches
Tags
No related merge requests found
Pipeline #32905 failed
......@@ -42,6 +42,7 @@ import org.duniter.core.service.CryptoService;
import org.duniter.core.util.*;
import org.duniter.core.util.CollectionUtils;
import org.duniter.core.util.concurrent.CompletableFutures;
import org.duniter.core.util.http.DnsUtils;
import org.duniter.core.util.http.InetAddressUtils;
import org.duniter.core.util.websocket.WebsocketClientEndpoint;
import org.slf4j.Logger;
......@@ -180,7 +181,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
return peer;
})
// Exclude peer on intranet (not routable) addresses
.filter(peer -> InetAddressUtils.isInternetAddress(peer.getHost()))
.filter(peer -> DnsUtils.isInternetHostName(peer.getHost()) || InetAddressUtils.isInternetAddress(peer.getHost()))
.collect(Collectors.toList())
)
.thenCompose(peers -> this.refreshPeersAsync(mainPeer, peers, pool));
......
......@@ -130,4 +130,24 @@ public class InetAddressUtilsTest {
checkFalse = InetAddressUtils.isInternetAddress("g1.duniter.org");
Assert.assertFalse(checkFalse);
}
@Test
public void isNotLocalAddress() {
boolean checkTrue = InetAddressUtils.isNotLocalAddress("10.0.0.1");
Assert.assertTrue(checkTrue);
checkTrue = InetAddressUtils.isNotLocalAddress("192.168.0.254");
Assert.assertTrue(checkTrue);
boolean checkFalse = InetAddressUtils.isNotLocalAddress("127.0.0.1");
Assert.assertFalse(checkFalse);
checkFalse = InetAddressUtils.isNotLocalAddress("localhost");
Assert.assertFalse(checkFalse);
// Try a host name
checkFalse = InetAddressUtils.isNotLocalAddress("g1.duniter.org");
Assert.assertFalse(checkFalse);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment