Initial commit with new directory structure.

This commit is contained in:
akwizgran
2011-06-21 18:01:28 +01:00
commit cd4f99df3d
98 changed files with 5811 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.crypto;
public interface Password {
char[] getPassword();
}

View File

@@ -0,0 +1,43 @@
package net.sf.briar.api.db;
import java.util.Set;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.Bundle;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
public interface DatabaseComponent {
static final long MEGABYTES = 1024L * 1024L;
static final long GIGABYTES = 1024L * MEGABYTES;
static final long MAX_DB_SIZE = 2L * GIGABYTES;
static final long MIN_FREE_SPACE = 300L * MEGABYTES;
static final long CRITICAL_FREE_SPACE = 100L * MEGABYTES;
static final long MAX_BYTES_BETWEEN_SPACE_CHECKS = 5L * MEGABYTES;
static final long MAX_MS_BETWEEN_SPACE_CHECKS = 60L * 1000L; // 1 min
static final long BYTES_PER_SWEEP = 5L * MEGABYTES;
static final int CLEANER_SLEEP_MS = 1000; // 1 sec
static final int RETRANSMIT_THRESHOLD = 3;
void close() throws DbException;
void addLocallyGeneratedMessage(Message m) throws DbException;
void addNeighbour(NeighbourId n) throws DbException;
void generateBundle(NeighbourId n, Bundle b) throws DbException;
Rating getRating(AuthorId a) throws DbException;
Set<GroupId> getSubscriptions() throws DbException;
void receiveBundle(NeighbourId n, Bundle b) throws DbException;
void setRating(AuthorId a, Rating r) throws DbException;
void subscribe(GroupId g) throws DbException;
void unsubscribe(GroupId g) throws DbException;
}

View File

@@ -0,0 +1,14 @@
package net.sf.briar.api.db;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;
@BindingAnnotation
@Target({ PARAMETER })
@Retention(RUNTIME)
public @interface DatabasePassword {}

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.db;
public class DbException extends Exception {
private static final long serialVersionUID = 3706581789209939441L;
public DbException(Throwable t) {
super(t);
}
}

View File

@@ -0,0 +1,30 @@
package net.sf.briar.api.db;
public class NeighbourId {
private final int id;
public NeighbourId(int id) {
this.id = id;
}
public int getInt() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof NeighbourId) return id == ((NeighbourId) o).id;
return false;
}
@Override
public int hashCode() {
return id;
}
@Override
public String toString() {
return String.valueOf(id);
}
}

View File

@@ -0,0 +1,5 @@
package net.sf.briar.api.db;
public enum Rating {
BAD, UNRATED, GOOD
}

View File

@@ -0,0 +1,5 @@
package net.sf.briar.api.db;
public enum Status {
NEW, SENT, SEEN
}

View File

@@ -0,0 +1,18 @@
package net.sf.briar.api.i18n;
import java.awt.Font;
import java.io.IOException;
import java.util.Locale;
public interface FontManager {
void initialize(Locale locale) throws IOException;
String[] getBundledFontFilenames();
Font getFontForLanguage(String language);
Font getUiFont();
void setUiFontForLanguage(String language);
}

View File

@@ -0,0 +1,33 @@
package net.sf.briar.api.i18n;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
public interface I18n {
String tr(String name);
Locale getLocale();
void setLocale(Locale locale);
void loadLocale() throws IOException;
void saveLocale() throws IOException;
void saveLocale(File dir) throws IOException;
ComponentOrientation getComponentOrientation();
void addListener(Listener l);
void removeListener(Listener l);
public interface Listener {
void localeChanged(Font uiFont);
}
}

View File

@@ -0,0 +1,41 @@
package net.sf.briar.api.i18n;
public class Stri18ng {
private static final String HTML_OPEN_LEFT = "<html><body align='left'>";
private static final String HTML_OPEN_RIGHT = "<html><body align='right'>";
private static final String HTML_CLOSE = "</body></html>";
private static final String PARAGRAPH = "<p><p>"; // Yes, two of them
private final String name;
private final I18n i18n;
public Stri18ng(String name, I18n i18n) {
this.name = name;
this.i18n = i18n;
}
public String tr() {
return i18n.tr(name);
}
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;
}
public String html(String... paras) {
StringBuilder s = new StringBuilder();
if(i18n.getComponentOrientation().isLeftToRight())
s.append(HTML_OPEN_LEFT);
else s.append(HTML_OPEN_RIGHT);
s.append(tr());
for(String para : paras) {
s.append(PARAGRAPH);
s.append(para);
}
s.append(HTML_CLOSE);
return s.toString();
}
}

View File

@@ -0,0 +1,23 @@
package net.sf.briar.api.invitation;
import java.io.File;
import java.util.List;
public interface InvitationCallback {
boolean isCancelled();
void copyingFile(File f);
void encryptingFile(File f);
void created(List<File> files);
void error(String message);
void notFound(File f);
void notDirectory(File f);
void notAllowed(File f);
}

View File

@@ -0,0 +1,16 @@
package net.sf.briar.api.invitation;
import java.io.File;
public interface InvitationParameters {
boolean shouldCreateExe();
boolean shouldCreateJar();
char[] getPassword();
File getChosenLocation();
String[] getBundledFontFilenames();
}

View File

@@ -0,0 +1,7 @@
package net.sf.briar.api.invitation;
public interface InvitationWorkerFactory {
Runnable createWorker(InvitationCallback callback,
InvitationParameters parameters);
}

View File

@@ -0,0 +1,36 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
public class AuthorId {
public static final int LENGTH = 32;
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
});
private final byte[] id;
public AuthorId(byte[] id) {
assert id.length == LENGTH;
this.id = id;
}
public byte[] getBytes() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof AuthorId)
return Arrays.equals(id, ((AuthorId) o).id);
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(id);
}
}

View File

@@ -0,0 +1,13 @@
package net.sf.briar.api.protocol;
public interface Batch {
public static final long CAPACITY = 1024L * 1024L;
public void seal();
BatchId getId();
long getSize();
Iterable<Message> getMessages();
void addMessage(Message m);
}

View File

@@ -0,0 +1,31 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
public class BatchId {
public static final int LENGTH = 32;
private final byte[] id;
public BatchId(byte[] id) {
assert id.length == LENGTH;
this.id = id;
}
public byte[] getBytes() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof BatchId)
return Arrays.equals(id, ((BatchId) o).id);
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(id);
}
}

View File

@@ -0,0 +1,16 @@
package net.sf.briar.api.protocol;
public interface Bundle {
public void seal();
BundleId getId();
long getCapacity();
long getSize();
Iterable<BatchId> getAcks();
void addAck(BatchId b);
Iterable<GroupId> getSubscriptions();
void addSubscription(GroupId g);
Iterable<Batch> getBatches();
void addBatch(Batch b);
}

View File

@@ -0,0 +1,36 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
public class BundleId {
public static final BundleId NONE = new BundleId(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 int LENGTH = 32;
private final byte[] id;
public BundleId(byte[] id) {
assert id.length == LENGTH;
this.id = id;
}
public byte[] getBytes() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof BundleId)
return Arrays.equals(id, ((BundleId) o).id);
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(id);
}
}

View File

@@ -0,0 +1,31 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
public class GroupId {
public static final int LENGTH = 32;
private final byte[] id;
public GroupId(byte[] id) {
assert id.length == LENGTH;
this.id = id;
}
public byte[] getBytes() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof GroupId)
return Arrays.equals(id, ((GroupId) o).id);
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(id);
}
}

View File

@@ -0,0 +1,13 @@
package net.sf.briar.api.protocol;
public interface Message {
MessageId getId();
MessageId getParent();
GroupId getGroup();
AuthorId getAuthor();
long getTimestamp();
int getSize();
byte[] getBody();
}

View File

@@ -0,0 +1,7 @@
package net.sf.briar.api.protocol;
public interface MessageFactory {
Message createMessage(MessageId id, MessageId parent, GroupId group,
AuthorId author, long timestamp, byte[] body);
}

View File

@@ -0,0 +1,36 @@
package net.sf.briar.api.protocol;
import java.util.Arrays;
public class MessageId {
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 int LENGTH = 32;
private final byte[] id;
public MessageId(byte[] id) {
assert id.length == LENGTH;
this.id = id;
}
public byte[] getBytes() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof MessageId)
return Arrays.equals(id, ((MessageId) o).id);
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(id);
}
}

View File

@@ -0,0 +1,22 @@
package net.sf.briar.api.setup;
import java.io.File;
public interface SetupCallback {
boolean isCancelled();
void extractingFile(File f);
void copyingFile(File f);
void installed(File f);
void error(String message);
void notFound(File f);
void notDirectory(File f);
void notAllowed(File f);
}

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.setup;
import java.io.File;
public interface SetupParameters {
File getChosenLocation();
String[] getBundledFontFilenames();
}

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.setup;
public interface SetupWorkerFactory {
Runnable createWorker(SetupCallback callback, SetupParameters parameters);
}