Add method for checking whether contact supports transport.

This commit is contained in:
akwizgran
2021-06-28 15:52:26 +01:00
committed by Torsten Grote
parent 0cc118c849
commit 2dcecb2a46
2 changed files with 24 additions and 2 deletions

View File

@@ -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.
*/

View File

@@ -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 ->