Check whether we have transport keys before trying to send data.

This commit is contained in:
akwizgran
2021-07-06 16:24:43 +01:00
parent 07ef73ab56
commit 04cf8e16a9

View File

@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.plugin.file.RemovableDriveManager;
import org.briarproject.bramble.api.plugin.file.RemovableDriveTask; import org.briarproject.bramble.api.plugin.file.RemovableDriveTask;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.properties.TransportPropertyManager; import org.briarproject.bramble.api.properties.TransportPropertyManager;
import org.briarproject.bramble.api.transport.KeyManager;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -28,23 +29,28 @@ class RemovableDriveManagerImpl
private final Executor ioExecutor; private final Executor ioExecutor;
private final DatabaseComponent db; private final DatabaseComponent db;
private final KeyManager keyManager;
private final TransportPropertyManager transportPropertyManager; private final TransportPropertyManager transportPropertyManager;
private final RemovableDriveTaskFactory taskFactory; private final RemovableDriveTaskFactory taskFactory;
private final Object lock = new Object(); private final Object lock = new Object();
@GuardedBy("lock") @GuardedBy("lock")
@Nullable
private RemovableDriveTask reader = null; private RemovableDriveTask reader = null;
@GuardedBy("lock") @GuardedBy("lock")
@Nullable
private RemovableDriveTask writer = null; private RemovableDriveTask writer = null;
@Inject @Inject
RemovableDriveManagerImpl( RemovableDriveManagerImpl(
@IoExecutor Executor ioExecutor, @IoExecutor Executor ioExecutor,
DatabaseComponent db, DatabaseComponent db,
KeyManager keyManager,
TransportPropertyManager transportPropertyManager, TransportPropertyManager transportPropertyManager,
RemovableDriveTaskFactory taskFactory) { RemovableDriveTaskFactory taskFactory) {
this.ioExecutor = ioExecutor; this.ioExecutor = ioExecutor;
this.db = db; this.db = db;
this.keyManager = keyManager;
this.transportPropertyManager = transportPropertyManager; this.transportPropertyManager = transportPropertyManager;
this.taskFactory = taskFactory; this.taskFactory = taskFactory;
} }
@@ -91,6 +97,7 @@ class RemovableDriveManagerImpl
@Override @Override
public boolean isTransportSupportedByContact(ContactId c) public boolean isTransportSupportedByContact(ContactId c)
throws DbException { throws DbException {
if (!keyManager.canSendOutgoingStreams(c, ID)) return false;
TransportProperties p = TransportProperties p =
transportPropertyManager.getRemoteProperties(c, ID); transportPropertyManager.getRemoteProperties(c, ID);
return "true".equals(p.get(PROP_SUPPORTED)); return "true".equals(p.get(PROP_SUPPORTED));