summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-12 01:13:24 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-12 01:14:13 -0600
commit93452c04073bd2e3e2585c7b9e4ebc2d82ba4f31 (patch)
treea7e5255fe52f36f7f2067fc2cef591cbfe2be63b /tunnel/src
parent8b03d75884e70df292cadcccae06c571dd2a717e (diff)
tunnel: replace CompletableFuture with GhettoCompletableFuture
Diffstat (limited to 'tunnel/src')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java35
1 files changed, 33 insertions, 2 deletions
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 6d3d65cb..978b39aa 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -24,18 +24,20 @@ import com.wireguard.util.NonNullForAll;
import java.net.InetAddress;
import java.util.Collections;
import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import androidx.annotation.Nullable;
import androidx.collection.ArraySet;
-import java9.util.concurrent.CompletableFuture;
@NonNullForAll
public final class GoBackend implements Backend {
private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName();
@Nullable private static AlwaysOnCallback alwaysOnCallback;
- private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();
+ private static GhettoCompletableFuture<VpnService> vpnService = new GhettoCompletableFuture<>();
private final Context context;
@Nullable private Config currentConfig;
@Nullable private Tunnel currentTunnel;
@@ -247,6 +249,35 @@ public final class GoBackend implements Backend {
void alwaysOnTriggered();
}
+ // TODO: When we finally drop API 21 and move to API 24, delete this and replace with the ordinary CompletableFuture.
+ private static final class GhettoCompletableFuture<V> {
+ private final LinkedBlockingQueue<V> completion = new LinkedBlockingQueue<>(1);
+ private final FutureTask<V> result = new FutureTask<>(completion::peek);
+
+ public boolean complete(final V value) {
+ final boolean offered = completion.offer(value);
+ if (offered)
+ result.run();
+ return offered;
+ }
+
+ public V get() throws ExecutionException, InterruptedException {
+ return result.get();
+ }
+
+ public V get(final long timeout, final TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException {
+ return result.get(timeout, unit);
+ }
+
+ public boolean isDone() {
+ return !completion.isEmpty();
+ }
+
+ public GhettoCompletableFuture<V> newIncompleteFuture() {
+ return new GhettoCompletableFuture<>();
+ }
+ }
+
public static class VpnService extends android.net.VpnService {
@Nullable private GoBackend owner;