mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
25
api/net/sf/briar/api/protocol/BundleReader.java
Normal file
25
api/net/sf/briar/api/protocol/BundleReader.java
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user