Removed batches from BMP. Messages are now sent and acked individually.

This commit is contained in:
akwizgran
2013-01-16 22:56:03 +00:00
parent 13cad40004
commit 50ad1f486e
55 changed files with 574 additions and 1666 deletions

View File

@@ -11,13 +11,11 @@ import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.db.event.DatabaseListener;
import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.Batch;
import net.sf.briar.api.protocol.Group;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.RawBatch;
import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.Transport;
@@ -70,25 +68,28 @@ public interface DatabaseComponent {
/**
* Generates an acknowledgement for the given contact. Returns null if
* there are no batches to acknowledge.
* there are no messages to acknowledge.
*/
Ack generateAck(ContactId c, int maxBatches) throws DbException;
Ack generateAck(ContactId c, int maxMessages) throws DbException;
/**
* Generates a batch of messages for the given contact. Returns null if
* there are no sendable messages that fit in the given capacity.
* Generates a batch of raw messages for the given contact, with a total
* length less than or equal to the given length. Returns null if
* there are no sendable messages that fit in the given length.
*/
RawBatch generateBatch(ContactId c, int capacity) throws DbException;
Collection<byte[]> generateBatch(ContactId c, int maxLength)
throws DbException;
/**
* Generates a batch of messages for the given contact from the given
* collection of requested messages. Any messages that were either added to
* the batch, or were considered but are no longer sendable to the contact,
* are removed from the collection of requested messages before returning.
* Generates a batch of raw messages for the given contact from the given
* collection of requested messages, with a total length less than or equal
* to the given length. Any messages that were either added to the batch,
* or were considered but are no longer sendable to the contact, are
* removed from the collection of requested messages before returning.
* Returns null if there are no sendable messages that fit in the given
* capacity.
* length.
*/
RawBatch generateBatch(ContactId c, int capacity,
Collection<byte[]> generateBatch(ContactId c, int maxLength,
Collection<MessageId> requested) throws DbException;
/**
@@ -170,8 +171,8 @@ public interface DatabaseComponent {
/** Processes an acknowledgement from the given contact. */
void receiveAck(ContactId c, Ack a) throws DbException;
/** Processes a batch of messages from the given contact. */
void receiveBatch(ContactId c, Batch b) throws DbException;
/** Processes a message from the given contact. */
void receiveMessage(ContactId c, Message m) throws DbException;
/**
* Processes an offer from the given contact and generates a request for

View File

@@ -1,6 +0,0 @@
package net.sf.briar.api.db.event;
/** An event that is broadcast when a batch of messages is received. */
public class BatchReceivedEvent extends DatabaseEvent {
}

View File

@@ -4,6 +4,6 @@ package net.sf.briar.api.db.event;
* An event that is broadcast when one or more messages are added to the
* database.
*/
public class MessagesAddedEvent extends DatabaseEvent {
public class MessageAddedEvent extends DatabaseEvent {
}

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.db.event;
/** An event that is broadcast when a message is received. */
public class MessageReceivedEvent extends DatabaseEvent {
}

View File

@@ -2,9 +2,9 @@ package net.sf.briar.api.protocol;
import java.util.Collection;
/** A packet acknowledging receipt of one or more batches. */
/** A packet acknowledging receipt of one or more messages. */
public interface Ack {
/** Returns the IDs of the acknowledged batches. */
Collection<BatchId> getBatchIds();
/** Returns the IDs of the acknowledged messages. */
Collection<MessageId> getMessageIds();
}

View File

@@ -1,13 +0,0 @@
package net.sf.briar.api.protocol;
import java.util.Collection;
/** An incoming packet containing messages. */
public interface Batch {
/** Returns the batch's unique identifier. */
BatchId getId();
/** Returns the messages contained in the batch. */
Collection<Message> getMessages();
}

View File

@@ -1,21 +0,0 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
/**
* Type-safe wrapper for a byte array that uniquely identifies a batch of
* messages.
*/
public class BatchId extends UniqueId {
public BatchId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof BatchId)
return Arrays.equals(id, ((BatchId) o).id);
return false;
}
}

View File

@@ -0,0 +1,8 @@
package net.sf.briar.api.protocol;
import java.security.GeneralSecurityException;
public interface MessageVerifier {
Message verifyMessage(UnverifiedMessage m) throws GeneralSecurityException;
}

View File

@@ -6,9 +6,7 @@ import java.util.Map;
public interface PacketFactory {
Ack createAck(Collection<BatchId> acked);
RawBatch createBatch(Collection<byte[]> messages);
Ack createAck(Collection<MessageId> acked);
Offer createOffer(Collection<MessageId> offered);

View File

@@ -9,8 +9,8 @@ public interface ProtocolReader {
boolean hasAck() throws IOException;
Ack readAck() throws IOException;
boolean hasBatch() throws IOException;
UnverifiedBatch readBatch() throws IOException;
boolean hasMessage() throws IOException;
UnverifiedMessage readMessage() throws IOException;
boolean hasOffer() throws IOException;
Offer readOffer() throws IOException;

View File

@@ -4,15 +4,13 @@ import java.io.IOException;
public interface ProtocolWriter {
int getMaxBatchesForAck(long capacity);
int getMaxMessagesForAck(long capacity);
int getMaxMessagesForOffer(long capacity);
int getMessageCapacityForBatch(long capacity);
void writeAck(Ack a) throws IOException;
void writeBatch(RawBatch b) throws IOException;
void writeMessage(byte[] raw) throws IOException;
void writeOffer(Offer o) throws IOException;

View File

@@ -1,13 +0,0 @@
package net.sf.briar.api.protocol;
import java.util.Collection;
/** An outgoing packet containing messages. */
public interface RawBatch {
/** Returns the batch's unique identifier. */
BatchId getId();
/** Returns the serialised messages contained in the batch. */
Collection<byte[]> getMessages();
}

View File

@@ -5,7 +5,6 @@ public interface Types {
int ACK = 0;
int AUTHOR = 1;
int BATCH = 2;
int GROUP = 3;
int MESSAGE = 4;
int OFFER = 5;

View File

@@ -1,8 +0,0 @@
package net.sf.briar.api.protocol;
import java.security.GeneralSecurityException;
public interface UnverifiedBatch {
Batch verify() throws GeneralSecurityException;
}

View File

@@ -0,0 +1,28 @@
package net.sf.briar.api.protocol;
public interface UnverifiedMessage {
MessageId getParent();
Group getGroup();
Author getAuthor();
String getSubject();
long getTimestamp();
byte[] getSerialised();
byte[] getAuthorSignature();
byte[] getGroupSignature();
int getBodyStart();
int getBodyLength();
int getLengthSignedByAuthor();
int getLengthSignedByGroup();
}