mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Return key set IDs when adding unbound keys.
This commit is contained in:
@@ -19,8 +19,11 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.bramble.api.transport.KeyManager;
|
||||
import org.briarproject.bramble.api.transport.KeySetId;
|
||||
import org.briarproject.bramble.api.transport.StreamContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -105,10 +108,13 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUnboundKeys(Transaction txn, SecretKey master,
|
||||
long timestamp, boolean alice) throws DbException {
|
||||
public Collection<KeySetId> addUnboundKeys(Transaction txn,
|
||||
SecretKey master, long timestamp, boolean alice)
|
||||
throws DbException {
|
||||
Collection<KeySetId> ids = new ArrayList<>();
|
||||
for (TransportKeyManager m : managers.values())
|
||||
m.addUnboundKeys(txn, master, timestamp, alice);
|
||||
ids.add(m.addUnboundKeys(txn, master, timestamp, alice));
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,7 +127,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
if (LOG.isLoggable(INFO)) LOG.info("No key manager for " + t);
|
||||
return null;
|
||||
}
|
||||
StreamContext ctx = null;
|
||||
StreamContext ctx;
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
ctx = m.getStreamContext(txn, c);
|
||||
@@ -140,7 +146,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
if (LOG.isLoggable(INFO)) LOG.info("No key manager for " + t);
|
||||
return null;
|
||||
}
|
||||
StreamContext ctx = null;
|
||||
StreamContext ctx;
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
ctx = m.getStreamContext(txn, tag);
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.transport.KeySetId;
|
||||
import org.briarproject.bramble.api.transport.StreamContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -17,7 +18,7 @@ interface TransportKeyManager {
|
||||
void addContact(Transaction txn, ContactId c, SecretKey master,
|
||||
long timestamp, boolean alice) throws DbException;
|
||||
|
||||
void addUnboundKeys(Transaction txn, SecretKey master, long timestamp,
|
||||
KeySetId addUnboundKeys(Transaction txn, SecretKey master, long timestamp,
|
||||
boolean alice) throws DbException;
|
||||
|
||||
void removeContact(ContactId c);
|
||||
|
||||
@@ -176,12 +176,12 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUnboundKeys(Transaction txn, SecretKey master,
|
||||
public KeySetId addUnboundKeys(Transaction txn, SecretKey master,
|
||||
long timestamp, boolean alice) throws DbException {
|
||||
deriveAndAddKeys(txn, null, master, timestamp, alice);
|
||||
return deriveAndAddKeys(txn, null, master, timestamp, alice);
|
||||
}
|
||||
|
||||
private void deriveAndAddKeys(Transaction txn, @Nullable ContactId c,
|
||||
private KeySetId deriveAndAddKeys(Transaction txn, @Nullable ContactId c,
|
||||
SecretKey master, long timestamp, boolean alice)
|
||||
throws DbException {
|
||||
lock.lock();
|
||||
@@ -198,6 +198,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
KeySetId keySetId = db.addTransportKeys(txn, c, k);
|
||||
// Initialise mutable state for the contact
|
||||
addKeys(keySetId, c, new MutableTransportKeys(k));
|
||||
return keySetId;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user