mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +01:00
Type-safe transport IDs.
This commit is contained in:
47
api/net/sf/briar/api/TransportId.java
Normal file
47
api/net/sf/briar/api/TransportId.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package net.sf.briar.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.sf.briar.api.serial.Writable;
|
||||||
|
import net.sf.briar.api.serial.Writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type-safe wrapper for an integer that uniquely identifies a transport plugin.
|
||||||
|
*/
|
||||||
|
public class TransportId implements Writable, Comparable<TransportId> {
|
||||||
|
|
||||||
|
public static final int MIN_ID = 0;
|
||||||
|
public static final int MAX_ID = 65535;
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
public TransportId(int id) {
|
||||||
|
if(id < MIN_ID || id > MAX_ID) throw new IllegalArgumentException();
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(Writer w) throws IOException {
|
||||||
|
w.writeInt32(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o instanceof TransportId) return id == ((TransportId) o).id;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(TransportId t) {
|
||||||
|
if(id < t.id) return -1;
|
||||||
|
if(id > t.id) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.Batch;
|
import net.sf.briar.api.protocol.Batch;
|
||||||
@@ -50,7 +51,7 @@ public interface DatabaseComponent {
|
|||||||
* Adds a new contact to the database with the given transport properties
|
* Adds a new contact to the database with the given transport properties
|
||||||
* and shared secret, returns an ID for the contact.
|
* and shared secret, returns an ID for the contact.
|
||||||
*/
|
*/
|
||||||
ContactId addContact(Map<Integer, Map<String, String>> transports,
|
ContactId addContact(Map<TransportId, Map<String, String>> transports,
|
||||||
byte[] secret) throws DbException;
|
byte[] secret) throws DbException;
|
||||||
|
|
||||||
/** Adds a locally generated group message to the database. */
|
/** Adds a locally generated group message to the database. */
|
||||||
@@ -102,13 +103,13 @@ public interface DatabaseComponent {
|
|||||||
* Returns an outgoing connection number for the given contact and
|
* Returns an outgoing connection number for the given contact and
|
||||||
* transport.
|
* transport.
|
||||||
*/
|
*/
|
||||||
long getConnectionNumber(ContactId c, int transportId) throws DbException;
|
long getConnectionNumber(ContactId c, TransportId t) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection reordering window for the given contact and
|
* Returns the connection reordering window for the given contact and
|
||||||
* transport.
|
* transport.
|
||||||
*/
|
*/
|
||||||
ConnectionWindow getConnectionWindow(ContactId c, int transportId)
|
ConnectionWindow getConnectionWindow(ContactId c, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/** Returns the IDs of all contacts. */
|
/** Returns the IDs of all contacts. */
|
||||||
@@ -124,13 +125,13 @@ public interface DatabaseComponent {
|
|||||||
Collection<Group> getSubscriptions() throws DbException;
|
Collection<Group> getSubscriptions() throws DbException;
|
||||||
|
|
||||||
/** Returns the configuration for the given transport. */
|
/** Returns the configuration for the given transport. */
|
||||||
Map<String, String> getTransportConfig(int transportId) throws DbException;
|
Map<String, String> getTransportConfig(TransportId t) throws DbException;
|
||||||
|
|
||||||
/** Returns all local transport properties. */
|
/** Returns all local transport properties. */
|
||||||
Map<Integer, Map<String, String>> getTransports() throws DbException;
|
Map<TransportId, Map<String, String>> getTransports() throws DbException;
|
||||||
|
|
||||||
/** Returns all transport properties for the given contact. */
|
/** Returns all transport properties for the given contact. */
|
||||||
Map<Integer, Map<String, String>> getTransports(ContactId c)
|
Map<TransportId, Map<String, String>> getTransports(ContactId c)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/** Returns the contacts to which the given group is visible. */
|
/** Returns the contacts to which the given group is visible. */
|
||||||
@@ -171,7 +172,7 @@ public interface DatabaseComponent {
|
|||||||
* Sets the connection reordering window for the given contact and
|
* Sets the connection reordering window for the given contact and
|
||||||
* transport.
|
* transport.
|
||||||
*/
|
*/
|
||||||
void setConnectionWindow(ContactId c, int transportId, ConnectionWindow w)
|
void setConnectionWindow(ContactId c, TransportId t, ConnectionWindow w)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/** Records the user's rating for the given author. */
|
/** Records the user's rating for the given author. */
|
||||||
@@ -184,14 +185,14 @@ public interface DatabaseComponent {
|
|||||||
* Sets the configuration for the given transport, replacing any existing
|
* Sets the configuration for the given transport, replacing any existing
|
||||||
* configuration for that transport.
|
* configuration for that transport.
|
||||||
*/
|
*/
|
||||||
void setTransportConfig(int transportId, Map<String, String> config)
|
void setTransportConfig(TransportId t, Map<String, String> config)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the transport properties for the given transport, replacing any
|
* Sets the transport properties for the given transport, replacing any
|
||||||
* existing properties for that transport.
|
* existing properties for that transport.
|
||||||
*/
|
*/
|
||||||
void setTransportProperties(int transportId, Map<String, String> properties)
|
void setTransportProperties(TransportId t, Map<String, String> properties)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.sf.briar.api.protocol;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
|
|
||||||
/** A packet updating the sender's transport properties. */
|
/** A packet updating the sender's transport properties. */
|
||||||
public interface TransportUpdate {
|
public interface TransportUpdate {
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ public interface TransportUpdate {
|
|||||||
static final int MAX_PLUGINS_PER_UPDATE = 50;
|
static final int MAX_PLUGINS_PER_UPDATE = 50;
|
||||||
|
|
||||||
/** Returns the transport properties contained in the update. */
|
/** Returns the transport properties contained in the update. */
|
||||||
Map<Integer, Map<String, String>> getTransports();
|
Map<TransportId, Map<String, String>> getTransports();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the update's timestamp. Updates that are older than the newest
|
* Returns the update's timestamp. Updates that are older than the newest
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package net.sf.briar.api.protocol.writers;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
|
|
||||||
/** An interface for creating a transport update. */
|
/** An interface for creating a transport update. */
|
||||||
public interface TransportWriter {
|
public interface TransportWriter {
|
||||||
|
|
||||||
/** Writes the contents of the update. */
|
/** Writes the contents of the update. */
|
||||||
void writeTransports(Map<Integer, Map<String, String>> transports,
|
void writeTransports(Map<TransportId, Map<String, String>> transports,
|
||||||
long timestamp) throws IOException;
|
long timestamp) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.sf.briar.api.transport;
|
package net.sf.briar.api.transport;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
|
|
||||||
public interface ConnectionRecogniserFactory {
|
public interface ConnectionRecogniserFactory {
|
||||||
|
|
||||||
ConnectionRecogniser createConnectionRecogniser(int transportId);
|
ConnectionRecogniser createConnectionRecogniser(TransportId t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package net.sf.briar.api.transport;
|
|||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
|
|
||||||
public interface ConnectionWriterFactory {
|
public interface ConnectionWriterFactory {
|
||||||
|
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out,
|
ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, boolean initiator, int transportId, long connection,
|
long capacity, boolean initiator, TransportId t, long connection,
|
||||||
byte[] secret);
|
byte[] secret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.sf.briar.api.transport.batch;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.transport.InvalidConfigException;
|
import net.sf.briar.api.transport.InvalidConfigException;
|
||||||
import net.sf.briar.api.transport.InvalidTransportException;
|
import net.sf.briar.api.transport.InvalidTransportException;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ import net.sf.briar.api.transport.InvalidTransportException;
|
|||||||
public interface BatchTransportPlugin {
|
public interface BatchTransportPlugin {
|
||||||
|
|
||||||
/** Returns the plugin's transport identifier. */
|
/** Returns the plugin's transport identifier. */
|
||||||
int getTransportId();
|
TransportId getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the plugin. Any connections that are later initiated by contacts
|
* Starts the plugin. Any connections that are later initiated by contacts
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.sf.briar.api.transport.stream;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.transport.InvalidConfigException;
|
import net.sf.briar.api.transport.InvalidConfigException;
|
||||||
import net.sf.briar.api.transport.InvalidTransportException;
|
import net.sf.briar.api.transport.InvalidTransportException;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ import net.sf.briar.api.transport.InvalidTransportException;
|
|||||||
public interface StreamTransportPlugin {
|
public interface StreamTransportPlugin {
|
||||||
|
|
||||||
/** Returns the plugin's transport identifier. */
|
/** Returns the plugin's transport identifier. */
|
||||||
int getTransportId();
|
TransportId getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the plugin. Any connections that are later initiated by contacts
|
* Starts the plugin. Any connections that are later initiated by contacts
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
@@ -83,8 +84,9 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contacts write, transports write.
|
* Locking: contacts write, transports write.
|
||||||
*/
|
*/
|
||||||
ContactId addContact(T txn, Map<Integer, Map<String, String>> transports,
|
ContactId addContact(T txn,
|
||||||
byte[] secret) throws DbException;
|
Map<TransportId, Map<String, String>> transports, byte[] secret)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns false if the given message is already in the database. Otherwise
|
* Returns false if the given message is already in the database. Otherwise
|
||||||
@@ -171,7 +173,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contacts read, windows write.
|
* Locking: contacts read, windows write.
|
||||||
*/
|
*/
|
||||||
long getConnectionNumber(T txn, ContactId c, int transportId)
|
long getConnectionNumber(T txn, ContactId c, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,7 +182,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contacts read, windows read.
|
* Locking: contacts read, windows read.
|
||||||
*/
|
*/
|
||||||
ConnectionWindow getConnectionWindow(T txn, ContactId c, int transportId)
|
ConnectionWindow getConnectionWindow(T txn, ContactId c, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -319,7 +321,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: transports read.
|
* Locking: transports read.
|
||||||
*/
|
*/
|
||||||
Map<String, String> getTransportConfig(T txn, int transportId)
|
Map<String, String> getTransportConfig(T txn, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,14 +329,15 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: transports read.
|
* Locking: transports read.
|
||||||
*/
|
*/
|
||||||
Map<Integer, Map<String, String>> getTransports(T txn) throws DbException;
|
Map<TransportId, Map<String, String>> getTransports(T txn)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all transport properties for the given contact.
|
* Returns all transport properties for the given contact.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: contacts read, transports read.
|
* Locking: contacts read, transports read.
|
||||||
*/
|
*/
|
||||||
Map<Integer, Map<String, String>> getTransports(T txn, ContactId c)
|
Map<TransportId, Map<String, String>> getTransports(T txn, ContactId c)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,7 +418,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contacts read, windows write.
|
* Locking: contacts read, windows write.
|
||||||
*/
|
*/
|
||||||
void setConnectionWindow(T txn, ContactId c, int transportId,
|
void setConnectionWindow(T txn, ContactId c, TransportId t,
|
||||||
ConnectionWindow w) throws DbException;
|
ConnectionWindow w) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -476,7 +479,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: transports write.
|
* Locking: transports write.
|
||||||
*/
|
*/
|
||||||
void setTransportConfig(T txn, int transportId, Map<String, String> config)
|
void setTransportConfig(T txn, TransportId t, Map<String, String> config)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -485,7 +488,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: transports write.
|
* Locking: transports write.
|
||||||
*/
|
*/
|
||||||
void setTransportProperties(T txn, int transportId,
|
void setTransportProperties(T txn, TransportId t,
|
||||||
Map<String, String> properties) throws DbException;
|
Map<String, String> properties) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -496,7 +499,7 @@ interface Database<T> {
|
|||||||
* Locking: contacts read, transports write.
|
* Locking: contacts read, transports write.
|
||||||
*/
|
*/
|
||||||
void setTransports(T txn, ContactId c,
|
void setTransports(T txn, ContactId c,
|
||||||
Map<Integer, Map<String, String>> transports, long timestamp)
|
Map<TransportId, Map<String, String>> transports, long timestamp)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
import net.sf.briar.api.Bytes;
|
import net.sf.briar.api.Bytes;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseListener;
|
import net.sf.briar.api.db.DatabaseListener;
|
||||||
import net.sf.briar.api.db.DatabaseListener.Event;
|
import net.sf.briar.api.db.DatabaseListener.Event;
|
||||||
@@ -117,8 +118,9 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactId addContact(Map<Integer, Map<String, String>> transports,
|
public ContactId addContact(
|
||||||
byte[] secret) throws DbException {
|
Map<TransportId, Map<String, String>> transports, byte[] secret)
|
||||||
|
throws DbException {
|
||||||
if(LOG.isLoggable(Level.FINE)) LOG.fine("Adding contact");
|
if(LOG.isLoggable(Level.FINE)) LOG.fine("Adding contact");
|
||||||
ContactId c;
|
ContactId c;
|
||||||
contactLock.writeLock().lock();
|
contactLock.writeLock().lock();
|
||||||
@@ -604,7 +606,7 @@ DatabaseCleaner.Callback {
|
|||||||
|
|
||||||
public void generateTransportUpdate(ContactId c, TransportWriter t)
|
public void generateTransportUpdate(ContactId c, TransportWriter t)
|
||||||
throws DbException, IOException {
|
throws DbException, IOException {
|
||||||
Map<Integer, Map<String, String>> transports;
|
Map<TransportId, Map<String, String>> transports;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -632,7 +634,7 @@ DatabaseCleaner.Callback {
|
|||||||
LOG.fine("Added " + transports.size() + " transports to update");
|
LOG.fine("Added " + transports.size() + " transports to update");
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getConnectionNumber(ContactId c, int transportId)
|
public long getConnectionNumber(ContactId c, TransportId t)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -641,7 +643,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
long outgoing = db.getConnectionNumber(txn, c, transportId);
|
long outgoing = db.getConnectionNumber(txn, c, t);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return outgoing;
|
return outgoing;
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
@@ -656,7 +658,7 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWindow getConnectionWindow(ContactId c, int transportId)
|
public ConnectionWindow getConnectionWindow(ContactId c, TransportId t)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -665,8 +667,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
ConnectionWindow w =
|
ConnectionWindow w = db.getConnectionWindow(txn, c, t);
|
||||||
db.getConnectionWindow(txn, c, transportId);
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return w;
|
return w;
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
@@ -750,14 +751,13 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getTransportConfig(int transportId)
|
public Map<String, String> getTransportConfig(TransportId t)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
transportLock.readLock().lock();
|
transportLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<String, String> config =
|
Map<String, String> config = db.getTransportConfig(txn, t);
|
||||||
db.getTransportConfig(txn, transportId);
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return config;
|
return config;
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
@@ -769,13 +769,13 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Map<String, String>> getTransports()
|
public Map<TransportId, Map<String, String>> getTransports()
|
||||||
throws DbException {
|
throws DbException {
|
||||||
transportLock.readLock().lock();
|
transportLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
db.getTransports(txn);
|
db.getTransports(txn);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return transports;
|
return transports;
|
||||||
@@ -788,7 +788,7 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Map<String, String>> getTransports(ContactId c)
|
public Map<TransportId, Map<String, String>> getTransports(ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -797,7 +797,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
db.getTransports(txn, c);
|
db.getTransports(txn, c);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return transports;
|
return transports;
|
||||||
@@ -1046,7 +1046,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
t.getTransports();
|
t.getTransports();
|
||||||
db.setTransports(txn, c, transports, t.getTimestamp());
|
db.setTransports(txn, c, transports, t.getTimestamp());
|
||||||
if(LOG.isLoggable(Level.FINE))
|
if(LOG.isLoggable(Level.FINE))
|
||||||
@@ -1104,7 +1104,7 @@ DatabaseCleaner.Callback {
|
|||||||
callListeners(Event.CONTACTS_UPDATED);
|
callListeners(Event.CONTACTS_UPDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionWindow(ContactId c, int transportId,
|
public void setConnectionWindow(ContactId c, TransportId t,
|
||||||
ConnectionWindow w) throws DbException {
|
ConnectionWindow w) throws DbException {
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -1113,7 +1113,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(txn, c, transportId, w);
|
db.setConnectionWindow(txn, c, t, w);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
@@ -1220,17 +1220,16 @@ DatabaseCleaner.Callback {
|
|||||||
+ indirect + " indirectly");
|
+ indirect + " indirectly");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransportConfig(int transportId,
|
public void setTransportConfig(TransportId t,
|
||||||
Map<String, String> config) throws DbException {
|
Map<String, String> config) throws DbException {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
transportLock.writeLock().lock();
|
transportLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<String, String> old =
|
Map<String, String> old = db.getTransportConfig(txn, t);
|
||||||
db.getTransportConfig(txn, transportId);
|
|
||||||
if(!config.equals(old)) {
|
if(!config.equals(old)) {
|
||||||
db.setTransportConfig(txn, transportId, config);
|
db.setTransportConfig(txn, t, config);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
@@ -1245,18 +1244,18 @@ DatabaseCleaner.Callback {
|
|||||||
if(changed) callListeners(Event.TRANSPORTS_UPDATED);
|
if(changed) callListeners(Event.TRANSPORTS_UPDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransportProperties(int transportId,
|
public void setTransportProperties(TransportId t,
|
||||||
Map<String, String> properties) throws DbException {
|
Map<String, String> properties) throws DbException {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
transportLock.writeLock().lock();
|
transportLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
db.getTransports(txn);
|
db.getTransports(txn);
|
||||||
Map<String, String> old = transports.get(transportId);
|
Map<String, String> old = transports.get(t);
|
||||||
if(!properties.equals(old)) {
|
if(!properties.equals(old)) {
|
||||||
db.setTransportProperties(txn, transportId, properties);
|
db.setTransportProperties(txn, t, properties);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
@@ -455,7 +456,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ContactId addContact(Connection txn,
|
public ContactId addContact(Connection txn,
|
||||||
Map<Integer, Map<String, String>> transports, byte[] secret)
|
Map<TransportId, Map<String, String>> transports, byte[] secret)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -486,8 +487,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
int batchSize = 0;
|
int batchSize = 0;
|
||||||
for(Entry<Integer, Map<String, String>> e : transports.entrySet()) {
|
for(Entry<TransportId, Map<String, String>> e
|
||||||
ps.setInt(2, e.getKey());
|
: transports.entrySet()) {
|
||||||
|
ps.setInt(2, e.getKey().getInt());
|
||||||
for(Entry<String, String> e1 : e.getValue().entrySet()) {
|
for(Entry<String, String> e1 : e.getValue().entrySet()) {
|
||||||
ps.setString(3, e1.getKey());
|
ps.setString(3, e1.getKey());
|
||||||
ps.setString(4, e1.getValue());
|
ps.setString(4, e1.getValue());
|
||||||
@@ -807,7 +809,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getConnectionNumber(Connection txn, ContactId c,
|
public long getConnectionNumber(Connection txn, ContactId c,
|
||||||
int transportId) throws DbException {
|
TransportId t) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
@@ -815,7 +817,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " WHERE contactId = ? AND transportId = ?";
|
+ " WHERE contactId = ? AND transportId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setInt(2, transportId);
|
ps.setInt(2, t.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if(rs.next()) {
|
if(rs.next()) {
|
||||||
long outgoing = rs.getLong(1);
|
long outgoing = rs.getLong(1);
|
||||||
@@ -827,7 +829,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setLong(1, outgoing + 1);
|
ps.setLong(1, outgoing + 1);
|
||||||
ps.setInt(2, c.getInt());
|
ps.setInt(2, c.getInt());
|
||||||
ps.setInt(3, transportId);
|
ps.setInt(3, t.getInt());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -840,7 +842,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " VALUES(?, ?, ?, ?, ?)";
|
+ " VALUES(?, ?, ?, ?, ?)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setInt(2, transportId);
|
ps.setInt(2, t.getInt());
|
||||||
ps.setLong(3, 0L);
|
ps.setLong(3, 0L);
|
||||||
ps.setInt(4, 0);
|
ps.setInt(4, 0);
|
||||||
ps.setLong(5, 0L);
|
ps.setLong(5, 0L);
|
||||||
@@ -857,7 +859,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWindow getConnectionWindow(Connection txn, ContactId c,
|
public ConnectionWindow getConnectionWindow(Connection txn, ContactId c,
|
||||||
int transportId) throws DbException {
|
TransportId t) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
@@ -865,7 +867,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " WHERE contactId = ? AND transportId = ?";
|
+ " WHERE contactId = ? AND transportId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setInt(2, transportId);
|
ps.setInt(2, t.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
long centre = 0L;
|
long centre = 0L;
|
||||||
int bitmap = 0;
|
int bitmap = 0;
|
||||||
@@ -1394,14 +1396,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getTransportConfig(Connection txn,
|
public Map<String, String> getTransportConfig(Connection txn,
|
||||||
int transportId) throws DbException {
|
TransportId t) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT key, value FROM transportConfig"
|
String sql = "SELECT key, value FROM transportConfig"
|
||||||
+ " WHERE transportId = ?";
|
+ " WHERE transportId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, transportId);
|
ps.setInt(1, t.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
Map<String, String> config = new TreeMap<String, String>();
|
Map<String, String> config = new TreeMap<String, String>();
|
||||||
while(rs.next()) config.put(rs.getString(1), rs.getString(2));
|
while(rs.next()) config.put(rs.getString(1), rs.getString(2));
|
||||||
@@ -1415,7 +1417,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Map<String, String>> getTransports(Connection txn)
|
public Map<TransportId, Map<String, String>> getTransports(Connection txn)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -1424,15 +1426,15 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " ORDER BY transportId";
|
+ " ORDER BY transportId";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
Map<String, String> properties = null;
|
Map<String, String> properties = null;
|
||||||
Integer lastId = null;
|
TransportId lastId = null;
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
Integer transportId = rs.getInt(1);
|
TransportId id = new TransportId(rs.getInt(1));
|
||||||
if(!transportId.equals(lastId)) {
|
if(!id.equals(lastId)) {
|
||||||
properties = new TreeMap<String, String>();
|
properties = new TreeMap<String, String>();
|
||||||
transports.put(transportId, properties);
|
transports.put(id, properties);
|
||||||
}
|
}
|
||||||
properties.put(rs.getString(2), rs.getString(3));
|
properties.put(rs.getString(2), rs.getString(3));
|
||||||
}
|
}
|
||||||
@@ -1446,7 +1448,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Map<String, String>> getTransports(Connection txn,
|
public Map<TransportId, Map<String, String>> getTransports(Connection txn,
|
||||||
ContactId c) throws DbException {
|
ContactId c) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -1457,15 +1459,15 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
Map<String, String> properties = null;
|
Map<String, String> properties = null;
|
||||||
Integer lastId = null;
|
TransportId lastId = null;
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
Integer transportId = rs.getInt(1);
|
TransportId id = new TransportId(rs.getInt(1));
|
||||||
if(!transportId.equals(lastId)) {
|
if(!id.equals(lastId)) {
|
||||||
properties = new TreeMap<String, String>();
|
properties = new TreeMap<String, String>();
|
||||||
transports.put(transportId, properties);
|
transports.put(id, properties);
|
||||||
}
|
}
|
||||||
properties.put(rs.getString(2), rs.getString(3));
|
properties.put(rs.getString(2), rs.getString(3));
|
||||||
}
|
}
|
||||||
@@ -1767,7 +1769,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionWindow(Connection txn, ContactId c,
|
public void setConnectionWindow(Connection txn, ContactId c,
|
||||||
int transportId, ConnectionWindow w) throws DbException {
|
TransportId t, ConnectionWindow w) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
@@ -1775,7 +1777,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " WHERE contactId = ? AND transportId = ?";
|
+ " WHERE contactId = ? AND transportId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setInt(2, transportId);
|
ps.setInt(2, t.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if(rs.next()) {
|
if(rs.next()) {
|
||||||
if(rs.next()) throw new DbStateException();
|
if(rs.next()) throw new DbStateException();
|
||||||
@@ -1787,7 +1789,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setLong(1, w.getCentre());
|
ps.setLong(1, w.getCentre());
|
||||||
ps.setInt(2, w.getBitmap());
|
ps.setInt(2, w.getBitmap());
|
||||||
ps.setInt(3, c.getInt());
|
ps.setInt(3, c.getInt());
|
||||||
ps.setInt(4, transportId);
|
ps.setInt(4, t.getInt());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -1799,7 +1801,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " VALUES(?, ?, ?, ?, ?)";
|
+ " VALUES(?, ?, ?, ?, ?)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setInt(2, transportId);
|
ps.setInt(2, t.getInt());
|
||||||
ps.setLong(3, w.getCentre());
|
ps.setLong(3, w.getCentre());
|
||||||
ps.setInt(4, w.getBitmap());
|
ps.setInt(4, w.getBitmap());
|
||||||
ps.setLong(5, 0L);
|
ps.setLong(5, 0L);
|
||||||
@@ -2039,26 +2041,26 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransportConfig(Connection txn, int transportId,
|
public void setTransportConfig(Connection txn, TransportId t,
|
||||||
Map<String, String> config) throws DbException {
|
Map<String, String> config) throws DbException {
|
||||||
setTransportDetails(txn, transportId, config, "transportConfig");
|
setTransportDetails(txn, t, config, "transportConfig");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTransportDetails(Connection txn, int transportId,
|
private void setTransportDetails(Connection txn, TransportId t,
|
||||||
Map<String, String> details, String table) throws DbException {
|
Map<String, String> details, String table) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
// Delete any existing details for the given transport
|
// Delete any existing details for the given transport
|
||||||
String sql = "DELETE FROM " + table + " WHERE transportId = ?";
|
String sql = "DELETE FROM " + table + " WHERE transportId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, transportId);
|
ps.setInt(1, t.getInt());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
// Store the new details
|
// Store the new details
|
||||||
sql = "INSERT INTO " + table + " (transportId, key, value)"
|
sql = "INSERT INTO " + table + " (transportId, key, value)"
|
||||||
+ " VALUES (?, ?, ?)";
|
+ " VALUES (?, ?, ?)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, transportId);
|
ps.setInt(1, t.getInt());
|
||||||
for(Entry<String, String> e : details.entrySet()) {
|
for(Entry<String, String> e : details.entrySet()) {
|
||||||
ps.setString(2, e.getKey());
|
ps.setString(2, e.getKey());
|
||||||
ps.setString(3, e.getValue());
|
ps.setString(3, e.getValue());
|
||||||
@@ -2077,13 +2079,13 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransportProperties(Connection txn, int transportId,
|
public void setTransportProperties(Connection txn, TransportId t,
|
||||||
Map<String, String> properties) throws DbException {
|
Map<String, String> properties) throws DbException {
|
||||||
setTransportDetails(txn, transportId, properties, "transports");
|
setTransportDetails(txn, t, properties, "transports");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransports(Connection txn, ContactId c,
|
public void setTransports(Connection txn, ContactId c,
|
||||||
Map<Integer, Map<String, String>> transports, long timestamp)
|
Map<TransportId, Map<String, String>> transports, long timestamp)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -2113,8 +2115,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
int batchSize = 0;
|
int batchSize = 0;
|
||||||
for(Entry<Integer, Map<String, String>> e : transports.entrySet()) {
|
for(Entry<TransportId, Map<String, String>> e
|
||||||
ps.setInt(2, e.getKey());
|
: transports.entrySet()) {
|
||||||
|
ps.setInt(2, e.getKey().getInt());
|
||||||
for(Entry<String, String> e1 : e.getValue().entrySet()) {
|
for(Entry<String, String> e1 : e.getValue().entrySet()) {
|
||||||
ps.setString(3, e1.getKey());
|
ps.setString(3, e1.getKey());
|
||||||
ps.setString(4, e1.getValue());
|
ps.setString(4, e1.getValue());
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.invitation.InvitationCallback;
|
import net.sf.briar.api.invitation.InvitationCallback;
|
||||||
@@ -70,7 +71,7 @@ class InvitationWorker implements Runnable {
|
|||||||
File invitationDat = new File(dir, "invitation.dat");
|
File invitationDat = new File(dir, "invitation.dat");
|
||||||
callback.encryptingFile(invitationDat);
|
callback.encryptingFile(invitationDat);
|
||||||
// FIXME: Create a real invitation
|
// FIXME: Create a real invitation
|
||||||
Map<Integer, Map<String, String>> transports;
|
Map<TransportId, Map<String, String>> transports;
|
||||||
try {
|
try {
|
||||||
transports = db.getTransports();
|
transports = db.getTransports();
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
|
|
||||||
interface TransportFactory {
|
interface TransportFactory {
|
||||||
|
|
||||||
TransportUpdate createTransportUpdate(
|
TransportUpdate createTransportUpdate(
|
||||||
Map<Integer, Map<String, String>> transports, long timestamp);
|
Map<TransportId, Map<String, String>> transports, long timestamp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
|
|
||||||
class TransportFactoryImpl implements TransportFactory {
|
class TransportFactoryImpl implements TransportFactory {
|
||||||
|
|
||||||
public TransportUpdate createTransportUpdate(
|
public TransportUpdate createTransportUpdate(
|
||||||
Map<Integer, Map<String, String>> transports, long timestamp) {
|
Map<TransportId, Map<String, String>> transports, long timestamp) {
|
||||||
return new TransportUpdateImpl(transports, timestamp);
|
return new TransportUpdateImpl(transports, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import java.util.Map;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -37,11 +38,11 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
|||||||
r.removeObjectReader(Types.TRANSPORT_PROPERTIES);
|
r.removeObjectReader(Types.TRANSPORT_PROPERTIES);
|
||||||
if(l.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE)
|
if(l.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
for(TransportProperties t : l) {
|
for(TransportProperties t : l) {
|
||||||
if(transports.put(t.transportId, t.properties) != null)
|
if(transports.put(t.id, t.properties) != null)
|
||||||
throw new FormatException(); // Duplicate plugin name
|
throw new FormatException(); // Duplicate transport ID
|
||||||
}
|
}
|
||||||
long timestamp = r.readInt64();
|
long timestamp = r.readInt64();
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
@@ -51,11 +52,11 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
|||||||
|
|
||||||
private static class TransportProperties {
|
private static class TransportProperties {
|
||||||
|
|
||||||
private final int transportId;
|
private final TransportId id;
|
||||||
private final Map<String, String> properties;
|
private final Map<String, String> properties;
|
||||||
|
|
||||||
TransportProperties(int transportId, Map<String, String> properties) {
|
TransportProperties(TransportId id, Map<String, String> properties) {
|
||||||
this.transportId = transportId;
|
this.id = id;
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,14 +66,17 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
|||||||
|
|
||||||
public TransportProperties readObject(Reader r) throws IOException {
|
public TransportProperties readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
r.readUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
||||||
int transportId = r.readInt32();
|
int i = r.readInt32();
|
||||||
|
if(i < TransportId.MIN_ID || i > TransportId.MAX_ID)
|
||||||
|
throw new FormatException();
|
||||||
|
TransportId id = new TransportId(i);
|
||||||
r.setMaxStringLength(TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
r.setMaxStringLength(TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||||
Map<String, String> properties =
|
Map<String, String> properties =
|
||||||
r.readMap(String.class, String.class);
|
r.readMap(String.class, String.class);
|
||||||
r.resetMaxStringLength();
|
r.resetMaxStringLength();
|
||||||
if(properties.size() > TransportUpdate.MAX_PROPERTIES_PER_PLUGIN)
|
if(properties.size() > TransportUpdate.MAX_PROPERTIES_PER_PLUGIN)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
return new TransportProperties(transportId, properties);
|
return new TransportProperties(id, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
|
|
||||||
class TransportUpdateImpl implements TransportUpdate {
|
class TransportUpdateImpl implements TransportUpdate {
|
||||||
|
|
||||||
private final Map<Integer, Map<String, String>> transports;
|
private final Map<TransportId, Map<String, String>> transports;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
|
|
||||||
TransportUpdateImpl(Map<Integer, Map<String, String>> transports,
|
TransportUpdateImpl(Map<TransportId, Map<String, String>> transports,
|
||||||
long timestamp) {
|
long timestamp) {
|
||||||
this.transports = transports;
|
this.transports = transports;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Map<String, String>> getTransports() {
|
public Map<TransportId, Map<String, String>> getTransports() {
|
||||||
return transports;
|
return transports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.TransportWriter;
|
import net.sf.briar.api.protocol.writers.TransportWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -20,13 +21,14 @@ class TransportWriterImpl implements TransportWriter {
|
|||||||
w = writerFactory.createWriter(out);
|
w = writerFactory.createWriter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeTransports(Map<Integer, Map<String, String>> transports,
|
public void writeTransports(
|
||||||
long timestamp) throws IOException {
|
Map<TransportId, Map<String, String>> transports, long timestamp)
|
||||||
|
throws IOException {
|
||||||
w.writeUserDefinedId(Types.TRANSPORT_UPDATE);
|
w.writeUserDefinedId(Types.TRANSPORT_UPDATE);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for(Entry<Integer, Map<String, String>> e : transports.entrySet()) {
|
for(Entry<TransportId, Map<String, String>> e : transports.entrySet()) {
|
||||||
w.writeUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
w.writeUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
||||||
w.writeInt32(e.getKey());
|
w.writeInt32(e.getKey().getInt());
|
||||||
w.writeMap(e.getValue());
|
w.writeMap(e.getValue());
|
||||||
}
|
}
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||||
@@ -19,7 +20,7 @@ class ConnectionRecogniserFactoryImpl implements ConnectionRecogniserFactory {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionRecogniser createConnectionRecogniser(int transportId) {
|
public ConnectionRecogniser createConnectionRecogniser(TransportId t) {
|
||||||
return new ConnectionRecogniserImpl(transportId, crypto, db);
|
return new ConnectionRecogniserImpl(t, crypto, db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import javax.crypto.SecretKey;
|
|||||||
|
|
||||||
import net.sf.briar.api.Bytes;
|
import net.sf.briar.api.Bytes;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseListener;
|
import net.sf.briar.api.db.DatabaseListener;
|
||||||
@@ -24,7 +25,7 @@ import net.sf.briar.api.transport.ConnectionWindow;
|
|||||||
class ConnectionRecogniserImpl implements ConnectionRecogniser,
|
class ConnectionRecogniserImpl implements ConnectionRecogniser,
|
||||||
DatabaseListener {
|
DatabaseListener {
|
||||||
|
|
||||||
private final int transportId;
|
private final TransportId id;
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final Map<Bytes, ContactId> ivToContact;
|
private final Map<Bytes, ContactId> ivToContact;
|
||||||
@@ -34,9 +35,9 @@ DatabaseListener {
|
|||||||
private final Map<ContactId, ConnectionWindow> contactToWindow;
|
private final Map<ContactId, ConnectionWindow> contactToWindow;
|
||||||
private boolean initialised = false;
|
private boolean initialised = false;
|
||||||
|
|
||||||
ConnectionRecogniserImpl(int transportId, CryptoComponent crypto,
|
ConnectionRecogniserImpl(TransportId id, CryptoComponent crypto,
|
||||||
DatabaseComponent db) {
|
DatabaseComponent db) {
|
||||||
this.transportId = transportId;
|
this.id = id;
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
// FIXME: There's probably a tidier way of maintaining all this state
|
// FIXME: There's probably a tidier way of maintaining all this state
|
||||||
@@ -62,7 +63,7 @@ DatabaseListener {
|
|||||||
}
|
}
|
||||||
contactToCipher.put(c, cipher);
|
contactToCipher.put(c, cipher);
|
||||||
// Calculate the IVs for the contact's connection window
|
// Calculate the IVs for the contact's connection window
|
||||||
ConnectionWindow w = db.getConnectionWindow(c, transportId);
|
ConnectionWindow w = db.getConnectionWindow(c, id);
|
||||||
Map<Long, Bytes> ivs = new HashMap<Long, Bytes>();
|
Map<Long, Bytes> ivs = new HashMap<Long, Bytes>();
|
||||||
for(Long unseen : w.getUnseenConnectionNumbers()) {
|
for(Long unseen : w.getUnseenConnectionNumbers()) {
|
||||||
Bytes expectedIv = new Bytes(encryptIv(c, unseen));
|
Bytes expectedIv = new Bytes(encryptIv(c, unseen));
|
||||||
@@ -81,7 +82,7 @@ DatabaseListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized byte[] encryptIv(ContactId c, long connection) {
|
private synchronized byte[] encryptIv(ContactId c, long connection) {
|
||||||
byte[] iv = IvEncoder.encodeIv(true, transportId, connection);
|
byte[] iv = IvEncoder.encodeIv(true, id, connection);
|
||||||
Cipher cipher = contactToCipher.get(c);
|
Cipher cipher = contactToCipher.get(c);
|
||||||
assert cipher != null;
|
assert cipher != null;
|
||||||
try {
|
try {
|
||||||
@@ -107,7 +108,7 @@ DatabaseListener {
|
|||||||
ConnectionWindow w = contactToWindow.get(contactId);
|
ConnectionWindow w = contactToWindow.get(contactId);
|
||||||
assert w != null;
|
assert w != null;
|
||||||
w.setSeen(connection);
|
w.setSeen(connection);
|
||||||
db.setConnectionWindow(contactId, transportId, w);
|
db.setConnectionWindow(contactId, id, w);
|
||||||
// Update the set of expected IVs
|
// Update the set of expected IVs
|
||||||
Map<Long, Bytes> oldIvs = contactToIvs.remove(contactId);
|
Map<Long, Bytes> oldIvs = contactToIvs.remove(contactId);
|
||||||
assert oldIvs != null;
|
assert oldIvs != null;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import javax.crypto.Cipher;
|
|||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
@@ -22,14 +23,14 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createConnectionWriter(OutputStream out,
|
public ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, boolean initiator, int transportId, long connection,
|
long capacity, boolean initiator, TransportId t, long connection,
|
||||||
byte[] secret) {
|
byte[] secret) {
|
||||||
// Create the encrypter
|
// Create the encrypter
|
||||||
Cipher ivCipher = crypto.getIvCipher();
|
Cipher ivCipher = crypto.getIvCipher();
|
||||||
Cipher frameCipher = crypto.getFrameCipher();
|
Cipher frameCipher = crypto.getFrameCipher();
|
||||||
SecretKey ivKey = crypto.deriveOutgoingIvKey(secret);
|
SecretKey ivKey = crypto.deriveOutgoingIvKey(secret);
|
||||||
SecretKey frameKey = crypto.deriveOutgoingFrameKey(secret);
|
SecretKey frameKey = crypto.deriveOutgoingFrameKey(secret);
|
||||||
byte[] iv = IvEncoder.encodeIv(initiator, transportId, connection);
|
byte[] iv = IvEncoder.encodeIv(initiator, t, connection);
|
||||||
ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out,
|
ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out,
|
||||||
capacity, iv, ivCipher, frameCipher, ivKey, frameKey);
|
capacity, iv, ivCipher, frameCipher, ivKey, frameKey);
|
||||||
// Create the writer
|
// Create the writer
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
import static net.sf.briar.api.transport.TransportConstants.IV_LENGTH;
|
import static net.sf.briar.api.transport.TransportConstants.IV_LENGTH;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.util.ByteUtils;
|
import net.sf.briar.util.ByteUtils;
|
||||||
|
|
||||||
class IvEncoder {
|
class IvEncoder {
|
||||||
|
|
||||||
static byte[] encodeIv(boolean initiator, int transportId,
|
static byte[] encodeIv(boolean initiator, TransportId transport,
|
||||||
long connection) {
|
long connection) {
|
||||||
byte[] iv = new byte[IV_LENGTH];
|
byte[] iv = new byte[IV_LENGTH];
|
||||||
// Bit 31 is the initiator flag
|
// Bit 31 is the initiator flag
|
||||||
if(initiator) iv[3] = 1;
|
if(initiator) iv[3] = 1;
|
||||||
// Encode the transport identifier as an unsigned 16-bit integer
|
// Encode the transport identifier as an unsigned 16-bit integer
|
||||||
ByteUtils.writeUint16(transportId, iv, 4);
|
ByteUtils.writeUint16(transport.getInt(), iv, 4);
|
||||||
// Encode the connection number as an unsigned 32-bit integer
|
// Encode the connection number as an unsigned 32-bit integer
|
||||||
ByteUtils.writeUint32(connection, iv, 6);
|
ByteUtils.writeUint32(connection, iv, 6);
|
||||||
return iv;
|
return iv;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
@@ -66,14 +67,14 @@ public class ProtocolIntegrationTest extends TestCase {
|
|||||||
private final ProtocolWriterFactory protocolWriterFactory;
|
private final ProtocolWriterFactory protocolWriterFactory;
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final byte[] aliceSecret, bobSecret;
|
private final byte[] aliceSecret, bobSecret;
|
||||||
private final int transportId = 123;
|
private final TransportId transportId = new TransportId(123);
|
||||||
private final long connection = 234L;
|
private final long connection = 12345L;
|
||||||
private final Author author;
|
private final Author author;
|
||||||
private final Group group, group1;
|
private final Group group, group1;
|
||||||
private final Message message, message1, message2, message3;
|
private final Message message, message1, message2, message3;
|
||||||
private final String authorName = "Alice";
|
private final String authorName = "Alice";
|
||||||
private final String messageBody = "Hello world";
|
private final String messageBody = "Hello world";
|
||||||
private final Map<Integer, Map<String, String>> transports;
|
private final Map<TransportId, Map<String, String>> transports;
|
||||||
|
|
||||||
public ProtocolIntegrationTest() throws Exception {
|
public ProtocolIntegrationTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import junit.framework.TestCase;
|
|||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseListener;
|
import net.sf.briar.api.db.DatabaseListener;
|
||||||
import net.sf.briar.api.db.DatabaseListener.Event;
|
import net.sf.briar.api.db.DatabaseListener.Event;
|
||||||
@@ -53,7 +54,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
private final byte[] raw;
|
private final byte[] raw;
|
||||||
private final Message message, privateMessage;
|
private final Message message, privateMessage;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Map<Integer, Map<String, String>> transports;
|
private final TransportId transportId;
|
||||||
|
private final Map<TransportId, Map<String, String>> transports;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
|
|
||||||
public DatabaseComponentTest() {
|
public DatabaseComponentTest() {
|
||||||
@@ -72,7 +74,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
privateMessage =
|
privateMessage =
|
||||||
new TestMessage(messageId, null, null, null, timestamp, raw);
|
new TestMessage(messageId, null, null, null, timestamp, raw);
|
||||||
group = new TestGroup(groupId, "The really exciting group", null);
|
group = new TestGroup(groupId, "The really exciting group", null);
|
||||||
transports = Collections.singletonMap(123,
|
transportId = new TransportId(123);
|
||||||
|
transports = Collections.singletonMap(transportId,
|
||||||
Collections.singletonMap("bar", "baz"));
|
Collections.singletonMap("bar", "baz"));
|
||||||
secret = new byte[123];
|
secret = new byte[123];
|
||||||
}
|
}
|
||||||
@@ -112,7 +115,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
// getConnectionWindow(contactId, 123)
|
// getConnectionWindow(contactId, 123)
|
||||||
oneOf(database).containsContact(txn, contactId);
|
oneOf(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getConnectionWindow(txn, contactId, 123);
|
oneOf(database).getConnectionWindow(txn, contactId, transportId);
|
||||||
will(returnValue(connectionWindow));
|
will(returnValue(connectionWindow));
|
||||||
// getSharedSecret(contactId)
|
// getSharedSecret(contactId)
|
||||||
oneOf(database).containsContact(txn, contactId);
|
oneOf(database).containsContact(txn, contactId);
|
||||||
@@ -150,7 +153,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
// setConnectionWindow(contactId, 123, connectionWindow)
|
// setConnectionWindow(contactId, 123, connectionWindow)
|
||||||
oneOf(database).containsContact(txn, contactId);
|
oneOf(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).setConnectionWindow(txn, contactId, 123,
|
oneOf(database).setConnectionWindow(txn, contactId, transportId,
|
||||||
connectionWindow);
|
connectionWindow);
|
||||||
// removeContact(contactId)
|
// removeContact(contactId)
|
||||||
oneOf(database).removeContact(txn, contactId);
|
oneOf(database).removeContact(txn, contactId);
|
||||||
@@ -166,7 +169,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
assertEquals(Rating.UNRATED, db.getRating(authorId));
|
assertEquals(Rating.UNRATED, db.getRating(authorId));
|
||||||
assertEquals(contactId, db.addContact(transports, secret));
|
assertEquals(contactId, db.addContact(transports, secret));
|
||||||
assertEquals(Collections.singletonList(contactId), db.getContacts());
|
assertEquals(Collections.singletonList(contactId), db.getContacts());
|
||||||
assertEquals(connectionWindow, db.getConnectionWindow(contactId, 123));
|
assertEquals(connectionWindow,
|
||||||
|
db.getConnectionWindow(contactId, transportId));
|
||||||
assertEquals(secret, db.getSharedSecret(contactId));
|
assertEquals(secret, db.getSharedSecret(contactId));
|
||||||
assertEquals(transports, db.getTransports(contactId));
|
assertEquals(transports, db.getTransports(contactId));
|
||||||
db.subscribe(group); // First time - check listeners are called
|
db.subscribe(group); // First time - check listeners are called
|
||||||
@@ -174,7 +178,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
assertEquals(Collections.singletonList(groupId), db.getSubscriptions());
|
assertEquals(Collections.singletonList(groupId), db.getSubscriptions());
|
||||||
db.unsubscribe(groupId); // First time - check listeners are called
|
db.unsubscribe(groupId); // First time - check listeners are called
|
||||||
db.unsubscribe(groupId); // Second time - check listeners aren't called
|
db.unsubscribe(groupId); // Second time - check listeners aren't called
|
||||||
db.setConnectionWindow(contactId, 123, connectionWindow);
|
db.setConnectionWindow(contactId, transportId, connectionWindow);
|
||||||
db.removeContact(contactId);
|
db.removeContact(contactId);
|
||||||
db.removeListener(listener);
|
db.removeListener(listener);
|
||||||
db.close();
|
db.close();
|
||||||
@@ -510,7 +514,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.getConnectionWindow(contactId, 123);
|
db.getConnectionWindow(contactId, transportId);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
@@ -555,7 +559,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(contactId, 123, null);
|
db.setConnectionWindow(contactId, transportId, null);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
@@ -1284,15 +1288,17 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).getTransports(txn);
|
oneOf(database).getTransports(txn);
|
||||||
will(returnValue(Collections.singletonMap(123, properties)));
|
will(returnValue(Collections.singletonMap(transportId,
|
||||||
oneOf(database).setTransportProperties(txn, 123, properties1);
|
properties)));
|
||||||
|
oneOf(database).setTransportProperties(txn, transportId,
|
||||||
|
properties1);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setTransportProperties(123, properties1);
|
db.setTransportProperties(transportId, properties1);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1311,13 +1317,14 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).getTransports(txn);
|
oneOf(database).getTransports(txn);
|
||||||
will(returnValue(Collections.singletonMap(123, properties)));
|
will(returnValue(Collections.singletonMap(transportId,
|
||||||
|
properties)));
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setTransportProperties(123, properties);
|
db.setTransportProperties(transportId, properties);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1336,16 +1343,16 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).getTransportConfig(txn, 123);
|
oneOf(database).getTransportConfig(txn, transportId);
|
||||||
will(returnValue(config));
|
will(returnValue(config));
|
||||||
oneOf(database).setTransportConfig(txn, 123, config1);
|
oneOf(database).setTransportConfig(txn, transportId, config1);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
oneOf(listener).eventOccurred(Event.TRANSPORTS_UPDATED);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setTransportConfig(123, config1);
|
db.setTransportConfig(transportId, config1);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1363,14 +1370,14 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).getTransportConfig(txn, 123);
|
oneOf(database).getTransportConfig(txn, transportId);
|
||||||
will(returnValue(config));
|
will(returnValue(config));
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setTransportConfig(123, config);
|
db.setTransportConfig(transportId, config);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.sf.briar.TestDatabaseModule;
|
|||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.Password;
|
import net.sf.briar.api.crypto.Password;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.Status;
|
import net.sf.briar.api.db.Status;
|
||||||
@@ -65,7 +66,8 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
private final byte[] raw;
|
private final byte[] raw;
|
||||||
private final Message message, privateMessage;
|
private final Message message, privateMessage;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Map<Integer, Map<String, String>> transports;
|
private final TransportId transportId;
|
||||||
|
private final Map<TransportId, Map<String, String>> transports;
|
||||||
private final Map<Group, Long> subscriptions;
|
private final Map<Group, Long> subscriptions;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
|
|
||||||
@@ -91,7 +93,8 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
privateMessage =
|
privateMessage =
|
||||||
new TestMessage(privateMessageId, null, null, null, timestamp, raw);
|
new TestMessage(privateMessageId, null, null, null, timestamp, raw);
|
||||||
group = groupFactory.createGroup(groupId, "Group name", null);
|
group = groupFactory.createGroup(groupId, "Group name", null);
|
||||||
transports = Collections.singletonMap(123,
|
transportId = new TransportId(0);
|
||||||
|
transports = Collections.singletonMap(transportId,
|
||||||
Collections.singletonMap("bar", "baz"));
|
Collections.singletonMap("bar", "baz"));
|
||||||
subscriptions = Collections.singletonMap(group, 0L);
|
subscriptions = Collections.singletonMap(group, 0L);
|
||||||
secret = new byte[123];
|
secret = new byte[123];
|
||||||
@@ -991,28 +994,29 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
assertEquals(transports, db.getTransports(txn, contactId));
|
assertEquals(transports, db.getTransports(txn, contactId));
|
||||||
|
|
||||||
// Replace the transport properties
|
// Replace the transport properties
|
||||||
Map<Integer, Map<String, String>> transports1 =
|
TransportId transportId1 = new TransportId(1);
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
Map<TransportId, Map<String, String>> transports1 =
|
||||||
transports1.put(123, Collections.singletonMap("bar", "baz"));
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
transports1.put(456, Collections.singletonMap("baz", "quux"));
|
transports1.put(transportId, Collections.singletonMap("bar", "baz"));
|
||||||
|
transports1.put(transportId1, Collections.singletonMap("baz", "quux"));
|
||||||
db.setTransports(txn, contactId, transports1, 1);
|
db.setTransports(txn, contactId, transports1, 1);
|
||||||
assertEquals(transports1, db.getTransports(txn, contactId));
|
assertEquals(transports1, db.getTransports(txn, contactId));
|
||||||
|
|
||||||
// Remove the transport properties
|
// Remove the transport properties
|
||||||
db.setTransports(txn, contactId,
|
db.setTransports(txn, contactId,
|
||||||
Collections.<Integer, Map<String, String>>emptyMap(), 2);
|
Collections.<TransportId, Map<String, String>>emptyMap(), 2);
|
||||||
assertEquals(Collections.emptyMap(), db.getTransports(txn, contactId));
|
assertEquals(Collections.emptyMap(), db.getTransports(txn, contactId));
|
||||||
|
|
||||||
// Set the local transport properties
|
// Set the local transport properties
|
||||||
for(Integer transportId : transports.keySet()) {
|
for(TransportId t : transports.keySet()) {
|
||||||
Map<String, String> properties = transports.get(transportId);
|
Map<String, String> properties = transports.get(t);
|
||||||
db.setTransportProperties(txn, transportId, properties);
|
db.setTransportProperties(txn, transportId, properties);
|
||||||
}
|
}
|
||||||
assertEquals(transports, db.getTransports(txn));
|
assertEquals(transports, db.getTransports(txn));
|
||||||
|
|
||||||
// Remove the local transport properties
|
// Remove the local transport properties
|
||||||
for(Integer transportId : transports.keySet()) {
|
for(TransportId t : transports.keySet()) {
|
||||||
db.setTransportProperties(txn, transportId,
|
db.setTransportProperties(txn, t,
|
||||||
Collections.<String, String>emptyMap());
|
Collections.<String, String>emptyMap());
|
||||||
}
|
}
|
||||||
assertEquals(Collections.emptyMap(), db.getTransports(txn));
|
assertEquals(Collections.emptyMap(), db.getTransports(txn));
|
||||||
@@ -1030,17 +1034,18 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Set the transport config
|
// Set the transport config
|
||||||
db.setTransportConfig(txn, 123, config);
|
db.setTransportConfig(txn, transportId, config);
|
||||||
assertEquals(config, db.getTransportConfig(txn, 123));
|
assertEquals(config, db.getTransportConfig(txn, transportId));
|
||||||
|
|
||||||
// Update the transport config
|
// Update the transport config
|
||||||
db.setTransportConfig(txn, 123, config1);
|
db.setTransportConfig(txn, transportId, config1);
|
||||||
assertEquals(config1, db.getTransportConfig(txn, 123));
|
assertEquals(config1, db.getTransportConfig(txn, transportId));
|
||||||
|
|
||||||
// Remove the transport config
|
// Remove the transport config
|
||||||
db.setTransportConfig(txn, 123,
|
db.setTransportConfig(txn, transportId,
|
||||||
Collections.<String, String>emptyMap());
|
Collections.<String, String>emptyMap());
|
||||||
assertEquals(Collections.emptyMap(), db.getTransportConfig(txn, 123));
|
assertEquals(Collections.emptyMap(),
|
||||||
|
db.getTransportConfig(txn, transportId));
|
||||||
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
db.close();
|
db.close();
|
||||||
@@ -1056,18 +1061,20 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
assertEquals(transports, db.getTransports(txn, contactId));
|
assertEquals(transports, db.getTransports(txn, contactId));
|
||||||
|
|
||||||
// Replace the transport properties using a timestamp of 2
|
// Replace the transport properties using a timestamp of 2
|
||||||
Map<Integer, Map<String, String>> transports1 =
|
TransportId transportId1 = new TransportId(1);
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
Map<TransportId, Map<String, String>> transports1 =
|
||||||
transports1.put(123, Collections.singletonMap("bar", "baz"));
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
transports1.put(456, Collections.singletonMap("baz", "quux"));
|
transports1.put(transportId, Collections.singletonMap("bar", "baz"));
|
||||||
|
transports1.put(transportId1, Collections.singletonMap("baz", "quux"));
|
||||||
db.setTransports(txn, contactId, transports1, 2);
|
db.setTransports(txn, contactId, transports1, 2);
|
||||||
assertEquals(transports1, db.getTransports(txn, contactId));
|
assertEquals(transports1, db.getTransports(txn, contactId));
|
||||||
|
|
||||||
// Try to replace the transport properties using a timestamp of 1
|
// Try to replace the transport properties using a timestamp of 1
|
||||||
Map<Integer, Map<String, String>> transports2 =
|
TransportId transportId2 = new TransportId(2);
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
Map<TransportId, Map<String, String>> transports2 =
|
||||||
transports2.put(456, Collections.singletonMap("baz", "quux"));
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
transports2.put(789, Collections.singletonMap("quux", "fnord"));
|
transports2.put(transportId1, Collections.singletonMap("baz", "quux"));
|
||||||
|
transports2.put(transportId2, Collections.singletonMap("quux", "etc"));
|
||||||
db.setTransports(txn, contactId, transports2, 1);
|
db.setTransports(txn, contactId, transports2, 1);
|
||||||
|
|
||||||
// The old properties should still be there
|
// The old properties should still be there
|
||||||
@@ -1395,7 +1402,8 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
// Add a contact
|
// Add a contact
|
||||||
assertEquals(contactId, db.addContact(txn, transports, secret));
|
assertEquals(contactId, db.addContact(txn, transports, secret));
|
||||||
// Get the connection window for a new transport
|
// Get the connection window for a new transport
|
||||||
ConnectionWindow w = db.getConnectionWindow(txn, contactId, 123);
|
ConnectionWindow w = db.getConnectionWindow(txn, contactId,
|
||||||
|
transportId);
|
||||||
// The connection window should exist and be in the initial state
|
// The connection window should exist and be in the initial state
|
||||||
assertNotNull(w);
|
assertNotNull(w);
|
||||||
assertEquals(0L, w.getCentre());
|
assertEquals(0L, w.getCentre());
|
||||||
@@ -1413,16 +1421,17 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
// Add a contact
|
// Add a contact
|
||||||
assertEquals(contactId, db.addContact(txn, transports, secret));
|
assertEquals(contactId, db.addContact(txn, transports, secret));
|
||||||
// Get the connection window for a new transport
|
// Get the connection window for a new transport
|
||||||
ConnectionWindow w = db.getConnectionWindow(txn, contactId, 123);
|
ConnectionWindow w = db.getConnectionWindow(txn, contactId,
|
||||||
|
transportId);
|
||||||
// The connection window should exist and be in the initial state
|
// The connection window should exist and be in the initial state
|
||||||
assertNotNull(w);
|
assertNotNull(w);
|
||||||
assertEquals(0L, w.getCentre());
|
assertEquals(0L, w.getCentre());
|
||||||
assertEquals(0, w.getBitmap());
|
assertEquals(0, w.getBitmap());
|
||||||
// Update the connection window and store it
|
// Update the connection window and store it
|
||||||
w.setSeen(5L);
|
w.setSeen(5L);
|
||||||
db.setConnectionWindow(txn, contactId, 123, w);
|
db.setConnectionWindow(txn, contactId, transportId, w);
|
||||||
// Check that the connection window was stored
|
// Check that the connection window was stored
|
||||||
w = db.getConnectionWindow(txn, contactId, 123);
|
w = db.getConnectionWindow(txn, contactId, transportId);
|
||||||
assertNotNull(w);
|
assertNotNull(w);
|
||||||
assertEquals(6L, w.getCentre());
|
assertEquals(6L, w.getCentre());
|
||||||
assertTrue(w.isSeen(5L));
|
assertTrue(w.isSeen(5L));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.Batch;
|
import net.sf.briar.api.protocol.Batch;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
@@ -47,7 +48,8 @@ public class ProtocolReadWriteTest extends TestCase {
|
|||||||
private final String messageBody = "Hello world";
|
private final String messageBody = "Hello world";
|
||||||
private final BitSet bitSet;
|
private final BitSet bitSet;
|
||||||
private final Map<Group, Long> subscriptions;
|
private final Map<Group, Long> subscriptions;
|
||||||
private final Map<Integer, Map<String, String>> transports;
|
private final TransportId transportId;
|
||||||
|
private final Map<TransportId, Map<String, String>> transports;
|
||||||
private final long timestamp = System.currentTimeMillis();
|
private final long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
public ProtocolReadWriteTest() throws Exception {
|
public ProtocolReadWriteTest() throws Exception {
|
||||||
@@ -67,7 +69,8 @@ public class ProtocolReadWriteTest extends TestCase {
|
|||||||
bitSet.set(3);
|
bitSet.set(3);
|
||||||
bitSet.set(7);
|
bitSet.set(7);
|
||||||
subscriptions = Collections.singletonMap(group, 123L);
|
subscriptions = Collections.singletonMap(group, 123L);
|
||||||
transports = Collections.singletonMap(123,
|
transportId = new TransportId(123);
|
||||||
|
transports = Collections.singletonMap(transportId,
|
||||||
Collections.singletonMap("bar", "baz"));
|
Collections.singletonMap("bar", "baz"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.AuthorFactory;
|
import net.sf.briar.api.protocol.AuthorFactory;
|
||||||
@@ -190,8 +191,8 @@ public class ConstantsTest extends TestCase {
|
|||||||
public void testTransportsFitIntoUpdate() throws Exception {
|
public void testTransportsFitIntoUpdate() throws Exception {
|
||||||
// Create the maximum number of plugins, each with the maximum number
|
// Create the maximum number of plugins, each with the maximum number
|
||||||
// of maximum-length properties
|
// of maximum-length properties
|
||||||
Map<Integer, Map<String, String>> transports =
|
Map<TransportId, Map<String, String>> transports =
|
||||||
new TreeMap<Integer, Map<String, String>>();
|
new TreeMap<TransportId, Map<String, String>>();
|
||||||
for(int i = 0; i < TransportUpdate.MAX_PLUGINS_PER_UPDATE; i++) {
|
for(int i = 0; i < TransportUpdate.MAX_PLUGINS_PER_UPDATE; i++) {
|
||||||
Map<String, String> properties = new TreeMap<String, String>();
|
Map<String, String> properties = new TreeMap<String, String>();
|
||||||
for(int j = 0; j < TransportUpdate.MAX_PROPERTIES_PER_PLUGIN; j++) {
|
for(int j = 0; j < TransportUpdate.MAX_PROPERTIES_PER_PLUGIN; j++) {
|
||||||
@@ -201,7 +202,7 @@ public class ConstantsTest extends TestCase {
|
|||||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||||
properties.put(key, value);
|
properties.put(key, value);
|
||||||
}
|
}
|
||||||
transports.put(i, properties);
|
transports.put(new TransportId(i), properties);
|
||||||
}
|
}
|
||||||
// Add the transports to an update
|
// Add the transports to an update
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import javax.crypto.spec.IvParameterSpec;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ public class ConnectionDecrypterImplTest extends TestCase {
|
|||||||
|
|
||||||
private final Cipher ivCipher, frameCipher;
|
private final Cipher ivCipher, frameCipher;
|
||||||
private final SecretKey ivKey, frameKey;
|
private final SecretKey ivKey, frameKey;
|
||||||
private final int transportId = 1234;
|
private final TransportId transportId = new TransportId(123);
|
||||||
private final long connection = 12345L;
|
private final long connection = 12345L;
|
||||||
|
|
||||||
public ConnectionDecrypterImplTest() {
|
public ConnectionDecrypterImplTest() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.crypto.SecretKey;
|
|||||||
import javax.crypto.spec.IvParameterSpec;
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class ConnectionEncrypterImplTest extends TestCase {
|
|||||||
|
|
||||||
private final Cipher ivCipher, frameCipher;
|
private final Cipher ivCipher, frameCipher;
|
||||||
private final SecretKey ivKey, frameKey;
|
private final SecretKey ivKey, frameKey;
|
||||||
private final int transportId = 1234;
|
private final TransportId transportId = new TransportId(123);
|
||||||
private final long connection = 12345L;
|
private final long connection = 12345L;
|
||||||
|
|
||||||
public ConnectionEncrypterImplTest() {
|
public ConnectionEncrypterImplTest() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.crypto.SecretKey;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.transport.ConnectionWindow;
|
import net.sf.briar.api.transport.ConnectionWindow;
|
||||||
@@ -27,7 +28,7 @@ public class ConnectionRecogniserImplTest extends TestCase {
|
|||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final int transportId;
|
private final TransportId transportId;
|
||||||
private final ConnectionWindow connectionWindow;
|
private final ConnectionWindow connectionWindow;
|
||||||
|
|
||||||
public ConnectionRecogniserImplTest() {
|
public ConnectionRecogniserImplTest() {
|
||||||
@@ -36,7 +37,7 @@ public class ConnectionRecogniserImplTest extends TestCase {
|
|||||||
crypto = i.getInstance(CryptoComponent.class);
|
crypto = i.getInstance(CryptoComponent.class);
|
||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
secret = new byte[18];
|
secret = new byte[18];
|
||||||
transportId = 123;
|
transportId = new TransportId(123);
|
||||||
connectionWindow = new ConnectionWindowImpl(0L, 0);
|
connectionWindow = new ConnectionWindowImpl(0L, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.TestDatabaseModule;
|
import net.sf.briar.TestDatabaseModule;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
@@ -23,8 +24,8 @@ public class ConnectionWriterTest extends TestCase {
|
|||||||
|
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final ConnectionWriterFactory connectionWriterFactory;
|
||||||
private final byte[] secret = new byte[100];
|
private final byte[] secret = new byte[100];
|
||||||
private final int transportId = 999;
|
private final TransportId transportId = new TransportId(123);
|
||||||
private final long connection = 1234L;
|
private final long connection = 12345L;
|
||||||
|
|
||||||
public ConnectionWriterTest() throws Exception {
|
public ConnectionWriterTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.crypto.Mac;
|
|||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.transport.ConnectionReader;
|
import net.sf.briar.api.transport.ConnectionReader;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
@@ -32,8 +33,8 @@ public class FrameReadWriteTest extends TestCase {
|
|||||||
private final Mac mac;
|
private final Mac mac;
|
||||||
private final Random random;
|
private final Random random;
|
||||||
private final byte[] secret = new byte[100];
|
private final byte[] secret = new byte[100];
|
||||||
private final int transportId = 999;
|
private final TransportId transportId = new TransportId(123);
|
||||||
private final long connection = 1234L;
|
private final long connection = 12345L;
|
||||||
|
|
||||||
public FrameReadWriteTest() {
|
public FrameReadWriteTest() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import junit.framework.TestCase;
|
|||||||
import net.sf.briar.TestDatabaseModule;
|
import net.sf.briar.TestDatabaseModule;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseListener;
|
import net.sf.briar.api.db.DatabaseListener;
|
||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
@@ -43,10 +44,10 @@ public class BatchConnectionReadWriteTest extends TestCase {
|
|||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final File aliceDir = new File(testDir, "alice");
|
private final File aliceDir = new File(testDir, "alice");
|
||||||
private final File bobDir = new File(testDir, "bob");
|
private final File bobDir = new File(testDir, "bob");
|
||||||
private final Map<Integer, Map<String, String>> transports =
|
private final TransportId transportId = new TransportId(123);
|
||||||
|
private final Map<TransportId, Map<String, String>> transports =
|
||||||
Collections.emptyMap();
|
Collections.emptyMap();
|
||||||
private final byte[] aliceSecret, bobSecret;
|
private final byte[] aliceSecret, bobSecret;
|
||||||
private final int transportId = 123;
|
|
||||||
|
|
||||||
private Injector alice, bob;
|
private Injector alice, bob;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user