Changed the message format to store the author and group inline - this

doesn't take a huge amount of space and allows every message to be
self-certifying.
This commit is contained in:
akwizgran
2011-07-25 21:14:16 +01:00
parent 586d1739ae
commit 3f61d0c3df
18 changed files with 317 additions and 127 deletions

View File

@@ -0,0 +1,12 @@
package net.sf.briar.api.protocol;
import net.sf.briar.api.serial.Writable;
public interface Author extends Writable {
AuthorId getId();
String getName();
byte[] getPublicKey();
}

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
public interface AuthorFactory {
Author createAuthor(String name, byte[] publicKey) throws IOException;
Author createAuthor(AuthorId id, String name, byte[] publicKey);
}

View File

@@ -8,6 +8,9 @@ import net.sf.briar.api.serial.Writer;
/** Type-safe wrapper for a byte array that uniquely identifies an author. */
public class AuthorId extends UniqueId {
/** Used to indicate that a message is anonymous. */
public static final AuthorId NONE = new AuthorId(new byte[UniqueId.LENGTH]);
public AuthorId(byte[] id) {
super(id);
}

View File

@@ -1,6 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
public interface GroupFactory {
Group createGroup(String name, byte[] publicKey) throws IOException;
Group createGroup(GroupId id, String name, byte[] publicKey);
}

View File

@@ -2,11 +2,14 @@ package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.PrivateKey;
public interface MessageEncoder {
Message encodeMessage(MessageId parent, GroupId group, String nick,
KeyPair keyPair, byte[] body) throws IOException,
Message encodeMessage(MessageId parent, Group group, byte[] body)
throws IOException;
Message encodeMessage(MessageId parent, Group group, Author author,
PrivateKey privateKey, byte[] body) throws IOException,
GeneralSecurityException;
}

View File

@@ -9,10 +9,8 @@ import net.sf.briar.api.serial.Writer;
public class MessageId extends UniqueId {
/** Used to indicate that the first message in a thread has no parent. */
public static final MessageId NONE = new MessageId(new byte[] {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
});
public static final MessageId NONE =
new MessageId(new byte[UniqueId.LENGTH]);
public MessageId(byte[] id) {
super(id);

View File

@@ -8,13 +8,14 @@ package net.sf.briar.api.protocol;
public interface Tags {
static final int ACK = 0;
static final int AUTHOR_ID = 1;
static final int BATCH = 2;
static final int BATCH_ID = 3;
static final int GROUP = 4;
static final int GROUP_ID = 5;
static final int MESSAGE = 6;
static final int MESSAGE_ID = 7;
static final int SUBSCRIPTIONS = 8;
static final int TRANSPORTS = 9;
static final int AUTHOR = 1;
static final int AUTHOR_ID = 2;
static final int BATCH = 3;
static final int BATCH_ID = 4;
static final int GROUP = 5;
static final int GROUP_ID = 6;
static final int MESSAGE = 7;
static final int MESSAGE_ID = 8;
static final int SUBSCRIPTIONS = 9;
static final int TRANSPORTS = 10;
}