mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Javadocs and unit tests, God help me.
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
/**
|
||||
* Encapsulates a password. Implementations may keep the password encrypted in
|
||||
* memory to reduce the chances of writing it to the swapfile in plaintext.
|
||||
*/
|
||||
public interface Password {
|
||||
|
||||
/**
|
||||
* Returns the password as a character array, which should be filled with
|
||||
* zeroes as soon as it has been used.
|
||||
*/
|
||||
char[] getPassword();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,16 @@ import net.sf.briar.api.protocol.Bundle;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
|
||||
/**
|
||||
* Encapsulates the database implementation and exposes high-level operations
|
||||
* to other components.
|
||||
*/
|
||||
public interface DatabaseComponent {
|
||||
|
||||
static final long MEGABYTES = 1024L * 1024L;
|
||||
static final long GIGABYTES = 1024L * MEGABYTES;
|
||||
|
||||
// FIXME: Some of these should be configurable
|
||||
static final long MAX_DB_SIZE = 2L * GIGABYTES;
|
||||
static final long MIN_FREE_SPACE = 300L * MEGABYTES;
|
||||
static final long CRITICAL_FREE_SPACE = 100L * MEGABYTES;
|
||||
@@ -21,23 +26,42 @@ public interface DatabaseComponent {
|
||||
static final int CLEANER_SLEEP_MS = 1000; // 1 sec
|
||||
static final int RETRANSMIT_THRESHOLD = 3;
|
||||
|
||||
/** Waits for any open transactions to finish and closes the database. */
|
||||
void close() throws DbException;
|
||||
|
||||
/** Adds a locally generated message to the database. */
|
||||
void addLocallyGeneratedMessage(Message m) throws DbException;
|
||||
|
||||
/** Adds a new neighbour to the database. */
|
||||
void addNeighbour(NeighbourId n) throws DbException;
|
||||
|
||||
/** Generates a bundle of messages for the given neighbour. */
|
||||
void generateBundle(NeighbourId n, Bundle b) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the rating assigned to the given author, which may be
|
||||
* Rating.UNRATED if no rating has been assigned.
|
||||
*/
|
||||
Rating getRating(AuthorId a) throws DbException;
|
||||
|
||||
/** Returns the set of groups to which we subscribe. */
|
||||
Set<GroupId> getSubscriptions() throws DbException;
|
||||
|
||||
/**
|
||||
* Processes a bundle of messages received from the given neighbour. Some
|
||||
* or all of the messages in the bundle may be stored.
|
||||
*/
|
||||
void receiveBundle(NeighbourId n, Bundle b) throws DbException;
|
||||
|
||||
/** Stores a rating for the given author. */
|
||||
void setRating(AuthorId a, Rating r) throws DbException;
|
||||
|
||||
/** Subscribes to the given group. */
|
||||
void subscribe(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Unsubscribes from the given group. Any messages belonging to the group
|
||||
* will be deleted from the database.
|
||||
*/
|
||||
void unsubscribe(GroupId g) throws DbException;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import java.lang.annotation.Target;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
/**
|
||||
* Annotation for injecting the password from which the database encryption
|
||||
* key is derived.
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target({ PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
/** Uniquely identifies a neighbour. */
|
||||
public class NeighbourId {
|
||||
|
||||
private final int id;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
/** The ratings that may be applied to an author in peer moderation. */
|
||||
public enum Rating {
|
||||
BAD, UNRATED, GOOD
|
||||
}
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
/** The status of a message with respect to a neighbour. */
|
||||
public enum Status {
|
||||
NEW, SENT, SEEN
|
||||
/**
|
||||
* The message has not been sent to, received from, or acked by the
|
||||
* neighbour.
|
||||
*/
|
||||
NEW,
|
||||
/**
|
||||
* The message has been sent to, but not received from or acked by, the
|
||||
* neighbour.
|
||||
*/
|
||||
SENT,
|
||||
/** The message has been received from or acked by the neighbour. */
|
||||
SEEN
|
||||
}
|
||||
|
||||
@@ -6,13 +6,15 @@ import java.util.Locale;
|
||||
|
||||
public interface FontManager {
|
||||
|
||||
/** Initializes the FontManager for the given locale. */
|
||||
void initialize(Locale locale) throws IOException;
|
||||
|
||||
String[] getBundledFontFilenames();
|
||||
|
||||
/** Returns the appropriate font for the given language. */
|
||||
Font getFontForLanguage(String language);
|
||||
|
||||
/** Returns the current user interface font. */
|
||||
Font getUiFont();
|
||||
|
||||
/** Sets the user interface font appropriately for the given language. */
|
||||
void setUiFontForLanguage(String language);
|
||||
}
|
||||
@@ -8,26 +8,43 @@ import java.util.Locale;
|
||||
|
||||
public interface I18n {
|
||||
|
||||
/** Returns the named string, translated for the current i18n locale. */
|
||||
String tr(String name);
|
||||
|
||||
/** Returns the i18n locale. This may not match the system locale. */
|
||||
Locale getLocale();
|
||||
|
||||
/** Sets the i18n locale. */
|
||||
void setLocale(Locale locale);
|
||||
|
||||
/** Loads the i18n locale from Briar/Data/locale.cfg. */
|
||||
void loadLocale() throws IOException;
|
||||
|
||||
/** Saves the i18n locale to Briar/Data/locale.cfg. */
|
||||
void saveLocale() throws IOException;
|
||||
|
||||
/** Saves the i18n locale to the given file. */
|
||||
void saveLocale(File dir) throws IOException;
|
||||
|
||||
/** Returns the ComponentOrientation of the current i18n locale. */
|
||||
ComponentOrientation getComponentOrientation();
|
||||
|
||||
/** Registers a listener for changes to the i18n locale. */
|
||||
void addListener(Listener l);
|
||||
|
||||
/** Unregisters a listener for changes to the i18n locale. */
|
||||
void removeListener(Listener l);
|
||||
|
||||
/**
|
||||
* Implemented by classes that wish to be informed of changes to the i18n
|
||||
* locale.
|
||||
*/
|
||||
public interface Listener {
|
||||
|
||||
/**
|
||||
* Called whenever the i18n locale changes.
|
||||
* @param uiFont The user interface font for the new locale.
|
||||
*/
|
||||
void localeChanged(Font uiFont);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.api.i18n;
|
||||
|
||||
/** A named translatable string. */
|
||||
public class Stri18ng {
|
||||
|
||||
private static final String HTML_OPEN_LEFT = "<html><body align='left'>";
|
||||
@@ -15,16 +16,23 @@ public class Stri18ng {
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
/** Returns the string translated for the current i18n locale. */
|
||||
public String tr() {
|
||||
return i18n.tr(name);
|
||||
}
|
||||
|
||||
/** Returns the string, translated for the current i18n locale, as HTML. */
|
||||
public String html() {
|
||||
if(i18n.getComponentOrientation().isLeftToRight())
|
||||
return HTML_OPEN_LEFT + i18n.tr(name) + HTML_CLOSE;
|
||||
else return HTML_OPEN_RIGHT + i18n.tr(name) + HTML_CLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string, translated for the current locale, as HTML.
|
||||
* @param paras Additional (pre-translated) paragraphs that should be
|
||||
* appended to the HTML.
|
||||
*/
|
||||
public String html(String... paras) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
if(i18n.getComponentOrientation().isLeftToRight())
|
||||
|
||||
@@ -3,8 +3,10 @@ package net.sf.briar.api.invitation;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/** A progress callback for creating an invitation. */
|
||||
public interface InvitationCallback {
|
||||
|
||||
/** Returns true if the process has been cancelled by the user. */
|
||||
boolean isCancelled();
|
||||
|
||||
void copyingFile(File f);
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.sf.briar.api.invitation;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/** Provides the parameters for creating an invitation. */
|
||||
public interface InvitationParameters {
|
||||
|
||||
boolean shouldCreateExe();
|
||||
@@ -12,5 +13,5 @@ public interface InvitationParameters {
|
||||
|
||||
File getChosenLocation();
|
||||
|
||||
String[] getBundledFontFilenames();
|
||||
File getSetupDat();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Uniquely identifies a pseudonymous author. */
|
||||
public class AuthorId {
|
||||
|
||||
public static final int LENGTH = 32;
|
||||
|
||||
// FIXME: Replace this with an isSelf() method that compares an AuthorId
|
||||
// to any and all local AuthorIds.
|
||||
public static final AuthorId SELF = new AuthorId(new byte[] {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
|
||||
/** A batch of messages up to CAPACITY bytes in total size. */
|
||||
public interface Batch {
|
||||
|
||||
public static final long CAPACITY = 1024L * 1024L;
|
||||
|
||||
/** Prepares the batch for transmission and generates its identifier. */
|
||||
public void seal();
|
||||
|
||||
/**
|
||||
* Returns the batch's unique identifier. Cannot be called before seal().
|
||||
*/
|
||||
BatchId getId();
|
||||
|
||||
/** Returns the size of the batch in bytes. */
|
||||
long getSize();
|
||||
|
||||
/** Returns the messages contained in the batch. */
|
||||
Iterable<Message> getMessages();
|
||||
|
||||
/** Adds a message to the batch. Cannot be called after seal(). */
|
||||
void addMessage(Message m);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Uniquely identifies a batch of messages. */
|
||||
public class BatchId {
|
||||
|
||||
public static final int LENGTH = 32;
|
||||
|
||||
@@ -1,16 +1,39 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
|
||||
/** A bundle of acknowledgements, subscriptions, and batches of messages. */
|
||||
public interface Bundle {
|
||||
|
||||
/** Prepares the bundle for transmission and generates its identifier. */
|
||||
public void seal();
|
||||
|
||||
/**
|
||||
* Returns the bundle's unique identifier. Cannot be called before seal().
|
||||
*/
|
||||
BundleId getId();
|
||||
|
||||
/** Returns the bundle's capacity in bytes. */
|
||||
long getCapacity();
|
||||
|
||||
/** Returns the bundle's size in bytes. */
|
||||
long getSize();
|
||||
|
||||
/** Returns the acknowledgements contained in the bundle. */
|
||||
Iterable<BatchId> getAcks();
|
||||
|
||||
/** Adds an acknowledgement to the bundle. Cannot be called after seal(). */
|
||||
void addAck(BatchId b);
|
||||
|
||||
/** Returns the subscriptions contained in the bundle. */
|
||||
Iterable<GroupId> getSubscriptions();
|
||||
|
||||
/** Adds a subscription to the bundle. Cannot be called after seal(). */
|
||||
void addSubscription(GroupId g);
|
||||
|
||||
/** Returns the batches of messages contained in the bundle. */
|
||||
Iterable<Batch> getBatches();
|
||||
|
||||
/**
|
||||
* Adds a batch of messages to the bundle. Cannot be called after seal().
|
||||
*/
|
||||
void addBatch(Batch b);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Uniquely identifies a group to which a user may subscribe. */
|
||||
public class GroupId {
|
||||
|
||||
public static final int LENGTH = 32;
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
|
||||
public interface Message {
|
||||
|
||||
/** Returns the message's unique identifier. */
|
||||
MessageId getId();
|
||||
|
||||
/**
|
||||
* Returns the message's parent, or MessageId.NONE if this is the first
|
||||
* message in a thread.
|
||||
*/
|
||||
MessageId getParent();
|
||||
|
||||
/** Returns the group to which the message belongs. */
|
||||
GroupId getGroup();
|
||||
|
||||
/** Returns the message's author. */
|
||||
AuthorId getAuthor();
|
||||
|
||||
/** Returns the timestamp created by the message's author. */
|
||||
long getTimestamp();
|
||||
|
||||
/** Returns the size of the message in bytes. */
|
||||
int getSize();
|
||||
|
||||
/** Returns the message in wire format. */
|
||||
byte[] getBody();
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Uniquely identifies a message. */
|
||||
public class MessageId {
|
||||
|
||||
/** 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
|
||||
|
||||
@@ -2,8 +2,10 @@ package net.sf.briar.api.setup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/** A progress callback for the installation process. */
|
||||
public interface SetupCallback {
|
||||
|
||||
/** Returns true if the process has been cancelled by the user. */
|
||||
boolean isCancelled();
|
||||
|
||||
void extractingFile(File f);
|
||||
|
||||
@@ -2,11 +2,10 @@ package net.sf.briar.api.setup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/** Provides the parameters for the installation process. */
|
||||
public interface SetupParameters {
|
||||
|
||||
File getChosenLocation();
|
||||
|
||||
String[] getBundledFontFilenames();
|
||||
|
||||
long getExeHeaderSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user