mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Rewrote the bundle reading and writing code to eliminate copying. Signatures and digests are now calculated on the fly as the data is read or written. This is a little bit tricky in the case of reading because ReaderImpl uses a lookahead byte, so the signature and message digest need to lag one byte behind.
This commit is contained in:
@@ -8,12 +8,6 @@ public interface Batch {
|
||||
/** Returns the batch's unique identifier. */
|
||||
BatchId getId();
|
||||
|
||||
/** Returns the size of the serialised batch in bytes. */
|
||||
long getSize();
|
||||
|
||||
/** Returns the messages contained in the batch. */
|
||||
Iterable<Message> getMessages();
|
||||
|
||||
/** Returns the sender's signature over the contents of the batch. */
|
||||
byte[] getSignature();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface BatchBuilder {
|
||||
|
||||
/** Adds a message to the batch. */
|
||||
void addMessage(Message m);
|
||||
|
||||
/** Sets the sender's signature over the contents of the batch. */
|
||||
void setSignature(byte[] sig);
|
||||
|
||||
/** Builds and returns the batch. */
|
||||
Batch build() throws IOException, GeneralSecurityException;
|
||||
}
|
||||
@@ -9,9 +9,6 @@ import java.security.GeneralSecurityException;
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -21,5 +18,5 @@ public interface BundleReader {
|
||||
Batch getNextBatch() throws IOException, GeneralSecurityException;
|
||||
|
||||
/** Finishes reading the bundle. */
|
||||
void close() throws IOException;
|
||||
void finish() throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An interface for writing a bundle of acknowledgements, subscriptions,
|
||||
@@ -8,15 +10,18 @@ import java.io.IOException;
|
||||
*/
|
||||
public interface BundleWriter {
|
||||
|
||||
/** Returns the bundle's capacity in bytes. */
|
||||
long getCapacity() throws IOException;
|
||||
/** Returns the bundle's remaining capacity in bytes. */
|
||||
long getRemainingCapacity() throws IOException;
|
||||
|
||||
/** Adds a header to the bundle. */
|
||||
void addHeader(Header h) throws IOException;
|
||||
/** Adds a header to the bundle and returns its identifier. */
|
||||
BundleId addHeader(Iterable<BatchId> acks, Iterable<GroupId> subs,
|
||||
Map<String, String> transports) throws IOException,
|
||||
GeneralSecurityException;
|
||||
|
||||
/** Adds a batch of messages to the bundle. */
|
||||
void addBatch(Batch b) throws IOException;
|
||||
/** Adds a batch to the bundle and returns its identifier. */
|
||||
BatchId addBatch(Iterable<Message> messages) throws IOException,
|
||||
GeneralSecurityException;
|
||||
|
||||
/** Finishes writing the bundle. */
|
||||
void close() throws IOException;
|
||||
void finish() throws IOException;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ public interface Header {
|
||||
// FIXME: Remove BundleId when refactoring is complete
|
||||
BundleId getId();
|
||||
|
||||
/** Returns the size of the serialised header in bytes. */
|
||||
long getSize();
|
||||
|
||||
/** Returns the acknowledgements contained in the header. */
|
||||
Set<BatchId> getAcks();
|
||||
|
||||
@@ -22,7 +19,4 @@ public interface Header {
|
||||
|
||||
/** Returns the transport details contained in the header. */
|
||||
Map<String, String> getTransports();
|
||||
|
||||
/** Returns the sender's signature over the contents of the header. */
|
||||
byte[] getSignature();
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface HeaderBuilder {
|
||||
|
||||
/** Adds acknowledgements to the header. */
|
||||
void addAcks(Iterable<BatchId> acks);
|
||||
|
||||
/** Adds subscriptions to the header. */
|
||||
void addSubscriptions(Iterable<GroupId> subs);
|
||||
|
||||
/** Adds transport details to the header. */
|
||||
void addTransports(Map<String, String> transports);
|
||||
|
||||
/** Sets the sender's signature over the contents of the header. */
|
||||
void setSignature(byte[] sig);
|
||||
|
||||
/** Builds and returns the header. */
|
||||
Header build() throws IOException, GeneralSecurityException;
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package net.sf.briar.api.protocol;
|
||||
public interface MessageFactory {
|
||||
|
||||
Message createMessage(MessageId id, MessageId parent, GroupId group,
|
||||
AuthorId author, long timestamp, byte[] body);
|
||||
AuthorId author, long timestamp, byte[] raw);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
/**
|
||||
* Generic interface for any object that knows how to serialise itself as a
|
||||
* raw byte array.
|
||||
*/
|
||||
public interface Raw {
|
||||
|
||||
byte[] getBytes();
|
||||
|
||||
Reference in New Issue
Block a user