mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Protocol Buffers will be used for the wire protocol. As a quick test it's now used to serialize transport details when creating an invitation.
This commit is contained in:
@@ -1062,6 +1062,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " WHERE contactSubscriptions.contactId = ?"
|
||||
+ " AND statuses.contactId = ? AND status = ?"
|
||||
+ " AND sendability > ZERO()";
|
||||
// FIXME: Investigate the performance impact of "ORDER BY timestamp"
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setInt(2, c.getInt());
|
||||
|
||||
@@ -393,6 +393,23 @@ class ReadWriteLockDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getTransports() throws DbException {
|
||||
transportLock.readLock().lock();
|
||||
try {
|
||||
Txn txn = db.startTransaction();
|
||||
try {
|
||||
Map<String, String> transports = db.getTransports(txn);
|
||||
db.commitTransaction(txn);
|
||||
return transports;
|
||||
} catch(DbException e) {
|
||||
db.abortTransaction(txn);
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
transportLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getTransports(ContactId c) throws DbException {
|
||||
contactLock.readLock().lock();
|
||||
try {
|
||||
|
||||
@@ -296,6 +296,20 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getTransports() throws DbException {
|
||||
synchronized(transportLock) {
|
||||
Txn txn = db.startTransaction();
|
||||
try {
|
||||
Map<String, String> transports = db.getTransports(txn);
|
||||
db.commitTransaction(txn);
|
||||
return transports;
|
||||
} catch(DbException e) {
|
||||
db.abortTransaction(txn);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getTransports(ContactId c) throws DbException {
|
||||
synchronized(contactLock) {
|
||||
if(!containsContact(c)) throw new NoSuchContactException();
|
||||
|
||||
@@ -6,21 +6,29 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.invitation.InvitationCallback;
|
||||
import net.sf.briar.api.invitation.InvitationParameters;
|
||||
import net.sf.briar.api.protocol.Transport.TransportDetails;
|
||||
import net.sf.briar.api.protocol.Transport.TransportDetails.TransportDetail;
|
||||
import net.sf.briar.util.FileUtils;
|
||||
|
||||
class InvitationWorker implements Runnable {
|
||||
|
||||
private final InvitationCallback callback;
|
||||
private final InvitationParameters parameters;
|
||||
private final DatabaseComponent databaseComponent;
|
||||
|
||||
InvitationWorker(final InvitationCallback callback,
|
||||
InvitationParameters parameters) {
|
||||
InvitationParameters parameters,
|
||||
DatabaseComponent databaseComponent) {
|
||||
this.callback = callback;
|
||||
this.parameters = parameters;
|
||||
this.databaseComponent = databaseComponent;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -60,16 +68,25 @@ class InvitationWorker implements Runnable {
|
||||
File invitationDat = new File(dir, "invitation.dat");
|
||||
callback.encryptingFile(invitationDat);
|
||||
// FIXME: Create a real invitation
|
||||
Map<String, String> transports;
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch(InterruptedException ignored) {}
|
||||
Arrays.fill(password, (char) 0);
|
||||
transports = databaseComponent.getTransports();
|
||||
} catch(DbException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
TransportDetails.Builder b = TransportDetails.newBuilder();
|
||||
for(Entry<String, String> e : transports.entrySet()) {
|
||||
TransportDetail.Builder b1 = TransportDetail.newBuilder();
|
||||
b1.setKey(e.getKey());
|
||||
b1.setValue(e.getValue());
|
||||
b.addDetails(b1.build());
|
||||
}
|
||||
TransportDetails t = b.build();
|
||||
FileOutputStream out = new FileOutputStream(invitationDat);
|
||||
byte[] buf = new byte[1024];
|
||||
new Random().nextBytes(buf);
|
||||
out.write(buf, 0, buf.length);
|
||||
t.writeTo(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
Arrays.fill(password, (char) 0);
|
||||
return invitationDat;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
package net.sf.briar.invitation;
|
||||
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.invitation.InvitationCallback;
|
||||
import net.sf.briar.api.invitation.InvitationParameters;
|
||||
import net.sf.briar.api.invitation.InvitationWorkerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
class InvitationWorkerFactoryImpl implements InvitationWorkerFactory {
|
||||
|
||||
private final DatabaseComponent databaseComponent;
|
||||
|
||||
@Inject
|
||||
InvitationWorkerFactoryImpl(DatabaseComponent databaseComponent) {
|
||||
this.databaseComponent = databaseComponent;
|
||||
}
|
||||
|
||||
public Runnable createWorker(InvitationCallback callback,
|
||||
InvitationParameters parameters) {
|
||||
return new InvitationWorker(callback, parameters);
|
||||
return new InvitationWorker(callback, parameters, databaseComponent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user