mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Removed batches from BMP. Messages are now sent and acked individually.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface MessageVerifier {
|
||||
|
||||
Message verifyMessage(UnverifiedMessage m) throws GeneralSecurityException;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface UnverifiedBatch {
|
||||
|
||||
Batch verify() throws GeneralSecurityException;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user