Added interfaces for reading and writing packets and recognising which

contact originated an incoming connection, and an implementation of
the PacketWriter interface.
This commit is contained in:
akwizgran
2011-08-09 16:15:25 +01:00
parent 18654f1514
commit e9d0021f56
8 changed files with 351 additions and 1 deletions

View File

@@ -4,13 +4,19 @@ import java.security.KeyPair;
import java.security.MessageDigest;
import java.security.Signature;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
public interface CryptoComponent {
KeyPair generateKeyPair();
SecretKey generateSecretKey();
KeyParser getKeyParser();
Mac getMac();
MessageDigest getMessageDigest();
Signature getSignature();

View File

@@ -0,0 +1,16 @@
package net.sf.briar.api.transport;
import net.sf.briar.api.ContactId;
/**
* Maintains a transport plugin's connection reordering window and decides
* whether incoming connections should be accepted or rejected.
*/
public interface ConnectionRecogniser {
/**
* Returns the ID of the contact who created the tag if the connection
* should be accepted, or null if the connection should be rejected.
*/
ContactId acceptConnection(byte[] tag);
}

View File

@@ -0,0 +1,37 @@
package net.sf.briar.api.transport;
import java.io.IOException;
import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.Batch;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.TransportUpdate;
/**
* Reads unencrypted packets from an underlying input stream and authenticates
* them.
*/
public interface PacketReader {
boolean eof() throws IOException;
boolean hasAck() throws IOException;
Ack readAck() throws IOException;
boolean hasBatch() throws IOException;
Batch readBatch() throws IOException;
boolean hasOffer() throws IOException;
Offer readOffer() throws IOException;
boolean hasRequest() throws IOException;
Request readRequest() throws IOException;
boolean hasSubscriptionUpdate() throws IOException;
SubscriptionUpdate readSubscriptionUpdate() throws IOException;
boolean hasTransportUpdate() throws IOException;
TransportUpdate readTransportUpdate() throws IOException;
}

View File

@@ -0,0 +1,24 @@
package net.sf.briar.api.transport;
import java.io.IOException;
import java.io.OutputStream;
/**
* A filter that adds tags and MACs to outgoing packets. Encryption is handled
* by the underlying output stream.
*/
public interface PacketWriter {
/**
* Returns the output stream to which packets should be written. (Note that
* this is not the underlying output stream.)
*/
OutputStream getOutputStream();
/**
* Finishes writing the current packet (if any) and prepares to write the
* next packet. If this method is called twice in succession without any
* intervening writes, the underlying output stream will be unaffected.
*/
void nextPacket() throws IOException;
}