mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Initial commit with new directory structure.
This commit is contained in:
1
api/.gitignore
vendored
Normal file
1
api/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
3
api/build.xml
Normal file
3
api/build.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<project name='api' default='compile'>
|
||||
<import file='../build-common.xml'/>
|
||||
</project>
|
||||
6
api/net/sf/briar/api/crypto/Password.java
Normal file
6
api/net/sf/briar/api/crypto/Password.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
public interface Password {
|
||||
|
||||
char[] getPassword();
|
||||
}
|
||||
43
api/net/sf/briar/api/db/DatabaseComponent.java
Normal file
43
api/net/sf/briar/api/db/DatabaseComponent.java
Normal 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;
|
||||
}
|
||||
14
api/net/sf/briar/api/db/DatabasePassword.java
Normal file
14
api/net/sf/briar/api/db/DatabasePassword.java
Normal 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 {}
|
||||
10
api/net/sf/briar/api/db/DbException.java
Normal file
10
api/net/sf/briar/api/db/DbException.java
Normal 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);
|
||||
}
|
||||
}
|
||||
30
api/net/sf/briar/api/db/NeighbourId.java
Normal file
30
api/net/sf/briar/api/db/NeighbourId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
5
api/net/sf/briar/api/db/Rating.java
Normal file
5
api/net/sf/briar/api/db/Rating.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
public enum Rating {
|
||||
BAD, UNRATED, GOOD
|
||||
}
|
||||
5
api/net/sf/briar/api/db/Status.java
Normal file
5
api/net/sf/briar/api/db/Status.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
public enum Status {
|
||||
NEW, SENT, SEEN
|
||||
}
|
||||
18
api/net/sf/briar/api/i18n/FontManager.java
Normal file
18
api/net/sf/briar/api/i18n/FontManager.java
Normal 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);
|
||||
}
|
||||
33
api/net/sf/briar/api/i18n/I18n.java
Normal file
33
api/net/sf/briar/api/i18n/I18n.java
Normal 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);
|
||||
}
|
||||
}
|
||||
41
api/net/sf/briar/api/i18n/Stri18ng.java
Normal file
41
api/net/sf/briar/api/i18n/Stri18ng.java
Normal 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();
|
||||
}
|
||||
}
|
||||
23
api/net/sf/briar/api/invitation/InvitationCallback.java
Normal file
23
api/net/sf/briar/api/invitation/InvitationCallback.java
Normal 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);
|
||||
}
|
||||
16
api/net/sf/briar/api/invitation/InvitationParameters.java
Normal file
16
api/net/sf/briar/api/invitation/InvitationParameters.java
Normal 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();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.sf.briar.api.invitation;
|
||||
|
||||
public interface InvitationWorkerFactory {
|
||||
|
||||
Runnable createWorker(InvitationCallback callback,
|
||||
InvitationParameters parameters);
|
||||
}
|
||||
36
api/net/sf/briar/api/protocol/AuthorId.java
Normal file
36
api/net/sf/briar/api/protocol/AuthorId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
13
api/net/sf/briar/api/protocol/Batch.java
Normal file
13
api/net/sf/briar/api/protocol/Batch.java
Normal 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);
|
||||
}
|
||||
31
api/net/sf/briar/api/protocol/BatchId.java
Normal file
31
api/net/sf/briar/api/protocol/BatchId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
16
api/net/sf/briar/api/protocol/Bundle.java
Normal file
16
api/net/sf/briar/api/protocol/Bundle.java
Normal 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);
|
||||
}
|
||||
36
api/net/sf/briar/api/protocol/BundleId.java
Normal file
36
api/net/sf/briar/api/protocol/BundleId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
31
api/net/sf/briar/api/protocol/GroupId.java
Normal file
31
api/net/sf/briar/api/protocol/GroupId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
13
api/net/sf/briar/api/protocol/Message.java
Normal file
13
api/net/sf/briar/api/protocol/Message.java
Normal 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();
|
||||
}
|
||||
7
api/net/sf/briar/api/protocol/MessageFactory.java
Normal file
7
api/net/sf/briar/api/protocol/MessageFactory.java
Normal 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);
|
||||
}
|
||||
36
api/net/sf/briar/api/protocol/MessageId.java
Normal file
36
api/net/sf/briar/api/protocol/MessageId.java
Normal 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);
|
||||
}
|
||||
}
|
||||
22
api/net/sf/briar/api/setup/SetupCallback.java
Normal file
22
api/net/sf/briar/api/setup/SetupCallback.java
Normal 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);
|
||||
}
|
||||
10
api/net/sf/briar/api/setup/SetupParameters.java
Normal file
10
api/net/sf/briar/api/setup/SetupParameters.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package net.sf.briar.api.setup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface SetupParameters {
|
||||
|
||||
File getChosenLocation();
|
||||
|
||||
String[] getBundledFontFilenames();
|
||||
}
|
||||
6
api/net/sf/briar/api/setup/SetupWorkerFactory.java
Normal file
6
api/net/sf/briar/api/setup/SetupWorkerFactory.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package net.sf.briar.api.setup;
|
||||
|
||||
public interface SetupWorkerFactory {
|
||||
|
||||
Runnable createWorker(SetupCallback callback, SetupParameters parameters);
|
||||
}
|
||||
Reference in New Issue
Block a user