mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
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:
@@ -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();
|
||||
|
||||
16
api/net/sf/briar/api/transport/ConnectionRecogniser.java
Normal file
16
api/net/sf/briar/api/transport/ConnectionRecogniser.java
Normal 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);
|
||||
}
|
||||
37
api/net/sf/briar/api/transport/PacketReader.java
Normal file
37
api/net/sf/briar/api/transport/PacketReader.java
Normal 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;
|
||||
}
|
||||
24
api/net/sf/briar/api/transport/PacketWriter.java
Normal file
24
api/net/sf/briar/api/transport/PacketWriter.java
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user