Use eager retransmission if the transport is lossy and cheap.

This commit is contained in:
akwizgran
2021-06-10 17:42:19 +01:00
parent a960bfb2c1
commit a5ce400341
11 changed files with 50 additions and 7 deletions

View File

@@ -22,6 +22,11 @@ public interface TransportConnectionWriter {
*/
int getMaxIdleTime();
/**
* Returns true if the transport is lossy and cheap.
*/
boolean isLossyAndCheap();
/**
* Returns an output stream for writing to the transport connection.
*/

View File

@@ -79,6 +79,11 @@ public abstract class AbstractDuplexTransportConnection
return plugin.getMaxIdleTime();
}
@Override
public boolean isLossyAndCheap() {
return false;
}
@Override
public OutputStream getOutputStream() throws IOException {
return AbstractDuplexTransportConnection.this.getOutputStream();

View File

@@ -15,6 +15,12 @@ import javax.annotation.Nullable;
@NotNullByDefault
public interface SimplexPlugin extends Plugin {
/**
* Returns true if the transport is likely to lose streams and the cost of
* transmitting redundant copies of data is cheap.
*/
boolean isLossyAndCheap();
/**
* Attempts to create and return a reader for the given transport
* properties. Returns null if a reader cannot be created.

View File

@@ -16,7 +16,7 @@ public interface SyncSessionFactory {
PriorityHandler handler);
SyncSession createSimplexOutgoingSession(ContactId c, TransportId t,
int maxLatency, StreamWriter streamWriter);
int maxLatency, boolean eager, StreamWriter streamWriter);
SyncSession createDuplexOutgoingSession(ContactId c, TransportId t,
int maxLatency, int maxIdleTime, StreamWriter streamWriter,

View File

@@ -71,8 +71,10 @@ class OutgoingSimplexSyncConnection extends SyncConnection implements Runnable {
StreamWriter streamWriter = streamWriterFactory.createStreamWriter(
w.getOutputStream(), ctx);
ContactId c = requireNonNull(ctx.getContactId());
// Use eager retransmission if the transport is lossy and cheap
return syncSessionFactory.createSimplexOutgoingSession(c,
ctx.getTransportId(), w.getMaxLatency(), streamWriter);
ctx.getTransportId(), w.getMaxLatency(), w.isLossyAndCheap(),
streamWriter);
}
}

View File

@@ -92,6 +92,11 @@ abstract class AbstractRemovableDrivePlugin implements SimplexPlugin {
throw new UnsupportedOperationException();
}
@Override
public boolean isLossyAndCheap() {
return true;
}
@Override
public TransportConnectionReader createReader(TransportProperties p) {
try {

View File

@@ -36,6 +36,11 @@ class FileTransportWriter implements TransportConnectionWriter {
return plugin.getMaxIdleTime();
}
@Override
public boolean isLossyAndCheap() {
return plugin.isLossyAndCheap();
}
@Override
public OutputStream getOutputStream() {
return out;

View File

@@ -106,6 +106,11 @@ class RemovableDriveWriterTask extends RemovableDriveTaskImpl
return delegate.getMaxIdleTime();
}
@Override
public boolean isLossyAndCheap() {
return delegate.isLossyAndCheap();
}
@Override
public OutputStream getOutputStream() throws IOException {
return delegate.getOutputStream();

View File

@@ -1,8 +1,8 @@
package org.briarproject.bramble.plugin.file;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.Plugin;
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
import java.io.OutputStream;
import java.util.logging.Logger;
@@ -17,10 +17,10 @@ class TransportOutputStreamWriter implements TransportConnectionWriter {
private static final Logger LOG =
getLogger(TransportOutputStreamWriter.class.getName());
private final Plugin plugin;
private final SimplexPlugin plugin;
private final OutputStream out;
TransportOutputStreamWriter(Plugin plugin, OutputStream out) {
TransportOutputStreamWriter(SimplexPlugin plugin, OutputStream out) {
this.plugin = plugin;
this.out = out;
}
@@ -35,6 +35,11 @@ class TransportOutputStreamWriter implements TransportConnectionWriter {
return plugin.getMaxIdleTime();
}
@Override
public boolean isLossyAndCheap() {
return plugin.isLossyAndCheap();
}
@Override
public OutputStream getOutputStream() {
return out;

View File

@@ -60,12 +60,12 @@ class SyncSessionFactoryImpl implements SyncSessionFactory {
@Override
public SyncSession createSimplexOutgoingSession(ContactId c, TransportId t,
int maxLatency, StreamWriter streamWriter) {
int maxLatency, boolean eager, StreamWriter streamWriter) {
OutputStream out = streamWriter.getOutputStream();
SyncRecordWriter recordWriter =
recordWriterFactory.createRecordWriter(out);
return new SimplexOutgoingSession(db, dbExecutor, eventBus, c, t,
maxLatency, false, streamWriter, recordWriter);
maxLatency, eager, streamWriter, recordWriter);
}
@Override

View File

@@ -35,6 +35,11 @@ public class TestTransportConnectionWriter
return 60_000;
}
@Override
public boolean isLossyAndCheap() {
return false;
}
@Override
public OutputStream getOutputStream() {
return out;