From 8c1f721015dc918e0d35273c70dd1e391f74c2e9 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Mon, 28 Jun 2021 15:52:26 +0100 Subject: [PATCH] Add method for checking whether contact supports transport. --- .../plugin/file/RemovableDriveManager.java | 6 ++++++ .../file/RemovableDriveManagerImpl.java | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/plugin/file/RemovableDriveManager.java b/bramble-api/src/main/java/org/briarproject/bramble/api/plugin/file/RemovableDriveManager.java index 8c74497b0..2838f87cf 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/plugin/file/RemovableDriveManager.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/plugin/file/RemovableDriveManager.java @@ -39,6 +39,12 @@ public interface RemovableDriveManager { */ RemovableDriveTask startWriterTask(ContactId c, TransportProperties p); + /** + * Returns true if the given contact has indicated support for the + * removable drive transport. + */ + boolean isTransportSupportedByContact(ContactId c) throws DbException; + /** * Returns true if there is anything to send to the given contact. */ diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/file/RemovableDriveManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/file/RemovableDriveManagerImpl.java index 2c96d5d53..a0d1848cd 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/file/RemovableDriveManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/file/RemovableDriveManagerImpl.java @@ -8,6 +8,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.plugin.file.RemovableDriveManager; import org.briarproject.bramble.api.plugin.file.RemovableDriveTask; import org.briarproject.bramble.api.properties.TransportProperties; +import org.briarproject.bramble.api.properties.TransportPropertyManager; import java.util.concurrent.Executor; @@ -16,6 +17,8 @@ import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; import javax.inject.Inject; +import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.ID; +import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.PROP_SUPPORTED; import static org.briarproject.bramble.plugin.file.RemovableDrivePluginFactory.MAX_LATENCY; @ThreadSafe @@ -25,6 +28,7 @@ class RemovableDriveManagerImpl private final Executor ioExecutor; private final DatabaseComponent db; + private final TransportPropertyManager transportPropertyManager; private final RemovableDriveTaskFactory taskFactory; private final Object lock = new Object(); @@ -34,10 +38,14 @@ class RemovableDriveManagerImpl private RemovableDriveTask writer = null; @Inject - RemovableDriveManagerImpl(@IoExecutor Executor ioExecutor, - DatabaseComponent db, RemovableDriveTaskFactory taskFactory) { + RemovableDriveManagerImpl( + @IoExecutor Executor ioExecutor, + DatabaseComponent db, + TransportPropertyManager transportPropertyManager, + RemovableDriveTaskFactory taskFactory) { this.ioExecutor = ioExecutor; this.db = db; + this.transportPropertyManager = transportPropertyManager; this.taskFactory = taskFactory; } @@ -80,6 +88,14 @@ class RemovableDriveManagerImpl return created; } + @Override + public boolean isTransportSupportedByContact(ContactId c) + throws DbException { + TransportProperties p = + transportPropertyManager.getRemoteProperties(c, ID); + return "true".equals(p.get(PROP_SUPPORTED)); + } + @Override public boolean isWriterTaskNeeded(ContactId c) throws DbException { return db.transactionWithResult(true, txn ->