Builders for incoming and outgoing headers and batches. The protocol and serial components can now be used to serialise, sign, deserialise and verify real bundles (except for message parsing).

This commit is contained in:
akwizgran
2011-07-12 16:50:20 +01:00
parent e0509db45d
commit 3d549ea6ac
33 changed files with 703 additions and 294 deletions

View File

@@ -1,15 +1,15 @@
package net.sf.briar.api.db;
import java.io.IOException;
import java.security.SignatureException;
import java.security.GeneralSecurityException;
import java.util.Map;
import java.util.Set;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.Rating;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.Bundle;
import net.sf.briar.api.protocol.BundleBuilder;
import net.sf.briar.api.protocol.BundleReader;
import net.sf.briar.api.protocol.BundleWriter;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
@@ -51,7 +51,7 @@ public interface DatabaseComponent {
* Generates a bundle of acknowledgements, subscriptions, and batches of
* messages for the given contact.
*/
Bundle generateBundle(ContactId c, BundleBuilder bundleBuilder) throws DbException, IOException, SignatureException;
void generateBundle(ContactId c, BundleWriter bundleBuilder) throws DbException, IOException, GeneralSecurityException;
/** Returns the IDs of all contacts. */
Set<ContactId> getContacts() throws DbException;
@@ -73,7 +73,7 @@ public interface DatabaseComponent {
* messages received from the given contact. Some or all of the messages
* in the bundle may be stored.
*/
void receiveBundle(ContactId c, Bundle b) throws DbException, IOException, SignatureException;
void receiveBundle(ContactId c, BundleReader b) throws DbException, IOException, GeneralSecurityException;
/** Removes a contact (and all associated state) from the database. */
void removeContact(ContactId c) throws DbException;

View File

@@ -1,5 +1,7 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.SignatureException;
public interface BatchBuilder {
@@ -11,5 +13,5 @@ public interface BatchBuilder {
void setSignature(byte[] sig);
/** Builds and returns the batch. */
Batch build() throws SignatureException;
Batch build() throws IOException, SignatureException, InvalidKeyException;
}

View File

@@ -1,21 +0,0 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.SignatureException;
/**
* A bundle of acknowledgements, subscriptions, transport details and batches.
*/
public interface Bundle {
/** Returns the size of the serialised bundle in bytes. */
long getSize() throws IOException;
/** Returns the bundle's header. */
Header getHeader() throws IOException, SignatureException;
/**
* Returns the next batch of messages, or null if there are no more batches.
*/
Batch getNextBatch() throws IOException, SignatureException;
}

View File

@@ -0,0 +1,25 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.GeneralSecurityException;
/**
* An interface for reading a bundle of acknowledgements, subscriptions,
* transport details and batches.
*/
public interface BundleReader {
/** Returns the size of the serialised bundle in bytes. */
long getSize() throws IOException;
/** Returns the bundle's header. */
Header getHeader() throws IOException, GeneralSecurityException;
/**
* Returns the next batch of messages, or null if there are no more batches.
*/
Batch getNextBatch() throws IOException, GeneralSecurityException;
/** Finishes reading the bundle. */
void close() throws IOException;
}

View File

@@ -2,7 +2,11 @@ package net.sf.briar.api.protocol;
import java.io.IOException;
public interface BundleBuilder {
/**
* An interface for writing a bundle of acknowledgements, subscriptions,
* transport details and batches.
*/
public interface BundleWriter {
/** Returns the bundle's capacity in bytes. */
long getCapacity() throws IOException;
@@ -13,6 +17,6 @@ public interface BundleBuilder {
/** Adds a batch of messages to the bundle. */
void addBatch(Batch b) throws IOException;
/** Builds and returns the bundle. */
Bundle build() throws IOException;
/** Finishes writing the bundle. */
void close() throws IOException;
}

View File

@@ -1,24 +1,24 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.SignatureException;
import java.util.Map;
import java.util.Set;
public interface HeaderBuilder {
/** Adds acknowledgements to the header. */
void addAcks(Set<BatchId> acks) throws IOException;
void addAcks(Iterable<BatchId> acks);
/** Adds subscriptions to the header. */
void addSubscriptions(Set<GroupId> subs) throws IOException;
void addSubscriptions(Iterable<GroupId> subs);
/** Adds transport details to the header. */
void addTransports(Map<String, String> transports) throws IOException;
void addTransports(Map<String, String> transports);
/** Sets the sender's signature over the contents of the header. */
void setSignature(byte[] sig) throws IOException;
void setSignature(byte[] sig);
/** Builds and returns the header. */
Header build() throws SignatureException;
Header build() throws IOException, SignatureException, InvalidKeyException;
}

View File

@@ -1,6 +1,8 @@
package net.sf.briar.api.protocol;
public interface Message {
import net.sf.briar.api.serial.Raw;
public interface Message extends Raw {
/** Returns the message's unique identifier. */
MessageId getId();
@@ -22,7 +24,4 @@ public interface Message {
/** Returns the size of the message in bytes. */
int getSize();
/** Returns the message in wire format. */
byte[] getBody();
}

View File

@@ -9,6 +9,7 @@ public interface Reader {
boolean eof() throws IOException;
void setReadLimit(long limit);
void resetReadLimit();
void close() throws IOException;
boolean hasBoolean() throws IOException;
boolean readBoolean() throws IOException;

View File

@@ -6,6 +6,8 @@ import java.util.Map;
public interface Writer {
void close() throws IOException;
void writeBoolean(boolean b) throws IOException;
void writeUint7(byte b) throws IOException;
@@ -31,6 +33,4 @@ public interface Writer {
void writeMapEnd() throws IOException;
void writeNull() throws IOException;
void close() throws IOException;
}