Plan B: Remove error correction and reliability layers and the

consequent distinction between segments and frames.
This commit is contained in:
akwizgran
2012-02-06 16:03:09 +00:00
parent 899ec5e19e
commit 6da30ca486
84 changed files with 296 additions and 2674 deletions

View File

@@ -9,10 +9,10 @@ import javax.crypto.Mac;
public interface CryptoComponent {
ErasableKey deriveSegmentKey(byte[] secret, boolean initiator);
ErasableKey deriveTagKey(byte[] secret, boolean initiator);
ErasableKey deriveFrameKey(byte[] secret, boolean initiator);
ErasableKey deriveMacKey(byte[] secret, boolean initiator);
byte[] deriveNextSecret(byte[] secret, int index, long connection);
@@ -27,11 +27,11 @@ public interface CryptoComponent {
SecureRandom getSecureRandom();
Cipher getSegmentCipher();
Cipher getTagCipher();
Cipher getFrameCipher();
Signature getSignature();
Cipher getTagCipher();
Mac getMac();
}

View File

@@ -1,16 +0,0 @@
package net.sf.briar.api.plugins;
import java.io.IOException;
import net.sf.briar.api.transport.Segment;
public interface SegmentSink {
/** Writes the given segment. */
void writeSegment(Segment s) throws IOException;
/**
* Returns the maximum length in bytes of the segments this sink accepts.
*/
int getMaxSegmentLength();
}

View File

@@ -1,19 +0,0 @@
package net.sf.briar.api.plugins;
import java.io.IOException;
import net.sf.briar.api.transport.Segment;
public interface SegmentSource {
/**
* Attempts to read a segment into the given buffer and returns true if a
* segment was read, or false if no more segments can be read.
*/
boolean readSegment(Segment s) throws IOException;
/**
* Returns the maximum length in bytes of the segments this source returns.
*/
int getMaxSegmentLength();
}

View File

@@ -1,30 +0,0 @@
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.Plugin;
/**
* An interface for transport plugins that support duplex segmented
* communication.
*/
public interface DuplexSegmentedPlugin extends Plugin {
/**
* Attempts to create and return a connection to the given contact using
* the current transport and configuration properties. Returns null if a
* connection could not be created.
*/
DuplexSegmentedTransportConnection createConnection(ContactId c);
/**
* Starts the invitation process from the inviter's side. Returns null if
* no connection can be established within the given timeout.
*/
DuplexSegmentedTransportConnection sendInvitation(int code, long timeout);
/**
* Starts the invitation process from the invitee's side. Returns null if
* no connection can be established within the given timeout.
*/
DuplexSegmentedTransportConnection acceptInvitation(int code, long timeout);
}

View File

@@ -1,17 +0,0 @@
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.PluginCallback;
/**
* An interface for handling connections created by a duplex segmented
* transport plugin.
*/
public interface DuplexSegmentedPluginCallback extends PluginCallback {
void incomingConnectionCreated(DuplexSegmentedTransportConnection d);
void outgoingConnectionCreated(ContactId c,
DuplexSegmentedTransportConnection d);
}

View File

@@ -1,10 +0,0 @@
package net.sf.briar.api.plugins.duplex;
import java.util.concurrent.Executor;
public interface DuplexSegmentedPluginFactory {
DuplexSegmentedPlugin createPlugin(Executor pluginExecutor,
DuplexSegmentedPluginCallback callback);
}

View File

@@ -1,29 +0,0 @@
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.plugins.SegmentSink;
import net.sf.briar.api.plugins.SegmentSource;
/**
* An interface for reading and writing data over a duplex segmented transport.
* The connection is not responsible for encrypting/decrypting or authenticating
* the data.
*/
public interface DuplexSegmentedTransportConnection extends SegmentSource,
SegmentSink {
/** Returns the maximum length of a segment in bytes. */
int getMaximumSegmentLength();
/**
* Returns true if the output stream should be flushed after each packet.
*/
boolean shouldFlush();
/**
* Closes the connection and disposes of any associated resources. The
* first argument indicates whether the connection is being closed because
* of an exception and the second argument indicates whether the connection
* was recognised, which may affect how resources are disposed of.
*/
void dispose(boolean exception, boolean recognised);
}

View File

@@ -1,51 +0,0 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.Plugin;
/**
* An interface for transport plugins that support simplex segmented
* communication.
*/
public interface SimplexSegmentedPlugin extends Plugin {
/**
* Attempts to create and return a reader for the given contact using the
* current transport and configuration properties. Returns null if a reader
* could not be created.
*/
SimplexSegmentedTransportReader createReader(ContactId c);
/**
* Attempts to create and return a writer for the given contact using the
* current transport and configuration properties. Returns null if a writer
* could not be created.
*/
SimplexSegmentedTransportWriter createWriter(ContactId c);
/**
* Starts the invitation process from the inviter's side. Returns null if
* no connection can be established within the given timeout.
*/
SimplexSegmentedTransportWriter sendInvitation(int code, long timeout);
/**
* Starts the invitation process from the invitee's side. Returns null if
* no connection can be established within the given timeout.
*/
SimplexSegmentedTransportReader acceptInvitation(int code, long timeout);
/**
* Continues the invitation process from the invitee's side. Returns null
* if no connection can be established within the given timeout.
*/
SimplexSegmentedTransportWriter sendInvitationResponse(int code,
long timeout);
/**
* Continues the invitation process from the inviter's side. Returns null
* if no connection can be established within the given timeout.
*/
SimplexSegmentedTransportReader acceptInvitationResponse(int code,
long timeout);
}

View File

@@ -1,16 +0,0 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.PluginCallback;
/**
* An interface for handling readers and writers created by a simplex
* segmented transport plugin.
*/
public interface SimplexSegmentedPluginCallback extends PluginCallback {
void readerCreated(SimplexSegmentedTransportReader r);
void writerCreated(ContactId c, SimplexSegmentedTransportWriter w);
}

View File

@@ -1,9 +0,0 @@
package net.sf.briar.api.plugins.simplex;
import java.util.concurrent.Executor;
public interface SimplexSegmentedPluginFactory {
SimplexSegmentedPlugin createPlugin(Executor pluginExecutor,
SimplexSegmentedPluginCallback callback);
}

View File

@@ -1,19 +0,0 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.plugins.SegmentSource;
/**
* An interface for reading data from a simplex segmented transport. The reader
* is not responsible for decrypting or authenticating the data before
* returning it.
*/
public interface SimplexSegmentedTransportReader extends SegmentSource {
/**
* Closes the reader and disposes of any associated resources. The first
* argument indicates whether the reader is being closed because of an
* exception and the second argument indicates whether the connection was
* recognised, which may affect how resources are disposed of.
*/
void dispose(boolean exception, boolean recognised);
}

View File

@@ -1,28 +0,0 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.plugins.SegmentSink;
/**
* An interface for writing data to a simplex segmented transport. The writer is
* not responsible for authenticating or encrypting the data before writing it.
*/
public interface SimplexSegmentedTransportWriter extends SegmentSink {
/** Returns the capacity of the transport in bytes. */
long getCapacity();
/** Returns the maximum length of a segment in bytes. */
int getMaximumSegmentLength();
/**
* Returns true if the output stream should be flushed after each packet.
*/
boolean shouldFlush();
/**
* Closes the writer and disposes of any associated resources. The
* argument indicates whether the writer is being closed because of an
* exception, which may affect how resources are disposed of.
*/
void dispose(boolean exception);
}

View File

@@ -9,7 +9,7 @@ import net.sf.briar.api.transport.ConnectionContext;
public interface DuplexConnectionFactory {
void createIncomingConnection(ConnectionContext ctx, TransportId t,
DuplexTransportConnection d, byte[] tag);
DuplexTransportConnection d);
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
DuplexTransportConnection d);

View File

@@ -10,7 +10,7 @@ import net.sf.briar.api.transport.ConnectionContext;
public interface SimplexConnectionFactory {
void createIncomingConnection(ConnectionContext ctx, TransportId t,
SimplexTransportReader r, byte[] tag);
SimplexTransportReader r);
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
SimplexTransportWriter w);

View File

@@ -2,35 +2,12 @@ package net.sf.briar.api.transport;
import java.io.InputStream;
import net.sf.briar.api.plugins.SegmentSource;
public interface ConnectionReaderFactory {
/**
* Creates a connection reader for a simplex connection or the initiator's
* side of a duplex connection. The secret is erased before this method
* returns.
* Creates a connection reader for a simplex connection or one side of a
* duplex connection. The secret is erased before this method returns.
*/
ConnectionReader createConnectionReader(InputStream in, byte[] secret,
byte[] bufferedTag);
/**
* Creates a connection reader for a simplex connection or the initiator's
* side of a duplex connection. The secret is erased before this method
* returns.
*/
ConnectionReader createConnectionReader(SegmentSource in, byte[] secret,
Segment bufferedSegment);
/**
* Creates a connection reader for the responder's side of a duplex
* connection. The secret is erased before this method returns.
*/
ConnectionReader createConnectionReader(InputStream in, byte[] secret);
/**
* Creates a connection reader for the responder's side of a duplex
* connection. The secret is erased before this method returns.
*/
ConnectionReader createConnectionReader(SegmentSource in, byte[] secret);
boolean initiator);
}

View File

@@ -2,8 +2,6 @@ package net.sf.briar.api.transport;
import java.io.OutputStream;
import net.sf.briar.api.plugins.SegmentSink;
public interface ConnectionWriterFactory {
/**
@@ -12,11 +10,4 @@ public interface ConnectionWriterFactory {
*/
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
byte[] secret, boolean initiator);
/**
* Creates a connection writer for a simplex connection or one side of a
* duplex connection. The secret is erased before this method returns.
*/
ConnectionWriter createConnectionWriter(SegmentSink out, long capacity,
byte[] secret, boolean initiator);
}

View File

@@ -1,14 +0,0 @@
package net.sf.briar.api.transport;
public interface Segment {
byte[] getBuffer();
int getLength();
long getSegmentNumber();
void setLength(int length);
void setSegmentNumber(long segmentNumber);
}

View File

@@ -2,21 +2,15 @@ package net.sf.briar.api.transport;
public interface TransportConstants {
/** The maximum length of a segment in bytes, including the tag. */
static final int MAX_SEGMENT_LENGTH = 65536; // 2^16, 64 KiB
/** The length of the segment tag in bytes. */
/** The length of the connection tag in bytes. */
static final int TAG_LENGTH = 16;
/** The maximum length of a frame in bytes, including the header and MAC. */
static final int MAX_FRAME_LENGTH = MAX_SEGMENT_LENGTH - TAG_LENGTH;
static final int MAX_FRAME_LENGTH = 65536; // 2^16, 64 KiB
/** The length of the frame header in bytes. */
static final int FRAME_HEADER_LENGTH = 8;
/** The length of the ack header in bytes. */
static final int ACK_HEADER_LENGTH = 5;
/** The length of the MAC in bytes. */
static final int MAC_LENGTH = 32;
@@ -29,7 +23,4 @@ public interface TransportConstants {
/** The size of the connection reordering window. */
static final int CONNECTION_WINDOW_SIZE = 32;
/** The size of the frame reordering window. */
static final int FRAME_WINDOW_SIZE = 32;
}