From 487be2efb4995388a15d6da396bf3603a60b7176 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 15 Feb 2022 14:59:07 +0200 Subject: [PATCH] fix resolution of mdns (.local) hostnames when connecting to bitcoin core --- .../java/com/sparrowwallet/sparrow/net/Bwt.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/Bwt.java b/src/main/java/com/sparrowwallet/sparrow/net/Bwt.java index cd115367..55ee73ea 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/Bwt.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/Bwt.java @@ -21,6 +21,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.time.Duration; import java.util.*; import java.util.stream.Collectors; @@ -115,6 +117,17 @@ public class Bwt { Config config = Config.get(); bwtConfig.bitcoindUrl = config.getCoreServer(); + if(bwtConfig.bitcoindUrl != null) { + try { + HostAndPort hostAndPort = Protocol.HTTP.getServerHostAndPort(bwtConfig.bitcoindUrl); + if(hostAndPort.getHost().endsWith(".local")) { + InetAddress inetAddress = InetAddress.getByName(hostAndPort.getHost()); + bwtConfig.bitcoindUrl = Protocol.HTTP.toUrlString(inetAddress.getHostAddress(), hostAndPort.getPort()); + } + } catch(Exception e) { + //ignore + } + } HostAndPort torProxy = getTorProxy(); if(Protocol.isOnionAddress(bwtConfig.bitcoindUrl) && torProxy != null) {