APIs for segmented transports.

This commit is contained in:
akwizgran
2012-01-13 10:53:23 +00:00
parent f6cad10868
commit ab9b05448d
50 changed files with 298 additions and 78 deletions

View File

@@ -1,8 +1,9 @@
package net.sf.briar.api.plugins;
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 communication. */
/** An interface for transport plugins that support duplex communication. */
public interface DuplexPlugin extends Plugin {
/**

View File

@@ -1,9 +1,10 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.PluginCallback;
/**
* An interface for receiving connections created by a duplex transport plugin.
* An interface for handling connections created by a duplex transport plugin.
*/
public interface DuplexPluginCallback extends PluginCallback {

View File

@@ -1,4 +1,4 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.duplex;
import java.util.concurrent.Executor;

View File

@@ -0,0 +1,29 @@
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.ContactId;
/**
* An interface for transport plugins that support duplex segmented
* communication.
*/
public interface DuplexSegmentedPlugin {
/**
* 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

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

View File

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

View File

@@ -0,0 +1,33 @@
package net.sf.briar.api.plugins.duplex;
import java.io.IOException;
/**
* 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 {
/**
* Reads a frame into the given buffer and returns its length, or -1 if no
* more frames can be read.
*/
int readFrame(byte[] b) throws IOException;
/** Writes the given frame to the transport. */
void writeFrame(byte[] b, int len) throws IOException;
/**
* 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,4 +1,4 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.duplex;
import java.io.IOException;
import java.io.InputStream;

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.plugins;
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 communication. */
public interface SimplexPlugin extends Plugin {

View File

@@ -1,9 +1,11 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.PluginCallback;
/**
* An interface for receiving readers and writers created by a simplex plugin.
* An interface for handling readers and writers created by a simplex transport
* plugin.
*/
public interface SimplexPluginCallback extends PluginCallback {

View File

@@ -1,4 +1,4 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.simplex;
import java.util.concurrent.Executor;

View File

@@ -0,0 +1,50 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.ContactId;
/**
* An interface for transport plugins that support simplex segmented
* communication.
*/
public interface SimplexSegmentedPlugin {
/**
* 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

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

View File

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

View File

@@ -0,0 +1,25 @@
package net.sf.briar.api.plugins.simplex;
import java.io.IOException;
/**
* 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 {
/**
* Reads a frame into the given buffer and returns its length, or -1 if no
* more frames can be read.
*/
int readFrame(byte[] b) throws IOException;
/**
* 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

@@ -0,0 +1,28 @@
package net.sf.briar.api.plugins.simplex;
import java.io.IOException;
/**
* 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 {
/** Returns the capacity of the transport in bytes. */
long getCapacity();
/** Writes the given frame to the transport. */
void writeFrame(byte[] b, int len) throws IOException;
/**
* 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

@@ -1,4 +1,4 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.simplex;
import java.io.InputStream;

View File

@@ -1,4 +1,4 @@
package net.sf.briar.api.plugins;
package net.sf.briar.api.plugins.simplex;
import java.io.OutputStream;

View File

@@ -1,7 +1,7 @@
package net.sf.briar.api.protocol.duplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.DuplexTransportConnection;
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionContext;

View File

@@ -1,8 +1,8 @@
package net.sf.briar.api.protocol.simplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.SimplexTransportReader;
import net.sf.briar.api.plugins.SimplexTransportWriter;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionContext;

View File

@@ -1,9 +1,9 @@
package net.sf.briar.api.transport;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.SimplexTransportReader;
import net.sf.briar.api.plugins.SimplexTransportWriter;
import net.sf.briar.api.plugins.DuplexTransportConnection;
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;