diff options
Diffstat (limited to 'tunnel/src/main/java/com/wireguard')
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/BackendException.java | 3 | ||||
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java b/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java index b64ebb47..52d084cd 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java @@ -55,6 +55,7 @@ public final class BackendException extends Exception { VPN_NOT_AUTHORIZED, UNABLE_TO_START_VPN, TUN_CREATION_ERROR, - GO_ACTIVATION_ERROR_CODE + GO_ACTIVATION_ERROR_CODE, + DNS_RESOLUTION_FAILURE, } } diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index 8b9213db..dfe217a3 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -16,6 +16,7 @@ import com.wireguard.android.backend.BackendException.Reason; import com.wireguard.android.backend.Tunnel.State; import com.wireguard.android.util.SharedLibraryLoader; import com.wireguard.config.Config; +import com.wireguard.config.InetEndpoint; import com.wireguard.config.InetNetwork; import com.wireguard.config.Peer; import com.wireguard.crypto.Key; @@ -40,6 +41,7 @@ import androidx.collection.ArraySet; */ @NonNullForAll public final class GoBackend implements Backend { + private static final int DNS_RESOLUTION_RETRIES = 10; private static final String TAG = "WireGuard/GoBackend"; @Nullable private static AlwaysOnCallback alwaysOnCallback; private static GhettoCompletableFuture<VpnService> vpnService = new GhettoCompletableFuture<>(); @@ -234,6 +236,25 @@ public final class GoBackend implements Backend { return; } + + dnsRetry: for (int i = 0; i < DNS_RESOLUTION_RETRIES; ++i) { + // Pre-resolve IPs so they're cached when building the userspace string + for (final Peer peer : config.getPeers()) { + final InetEndpoint ep = peer.getEndpoint().orElse(null); + if (ep == null) + continue; + if (ep.getResolved().orElse(null) == null) { + if (i < DNS_RESOLUTION_RETRIES - 1) { + Log.w(TAG, "DNS host \"" + ep.getHost() + "\" failed to resolve; trying again"); + Thread.sleep(1000); + continue dnsRetry; + } else + throw new BackendException(Reason.DNS_RESOLUTION_FAILURE, ep.getHost()); + } + } + break; + } + // Build config final String goConfig = config.toWgUserspaceString(); |