mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Store sync versions received from contacts.
This commit is contained in:
@@ -21,13 +21,14 @@ import org.briarproject.bramble.api.sync.SyncSession;
|
||||
import org.briarproject.bramble.api.sync.Versions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@@ -39,7 +40,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
class IncomingSession implements SyncSession, EventListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IncomingSession.class.getName());
|
||||
getLogger(IncomingSession.class.getName());
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final Executor dbExecutor;
|
||||
@@ -84,11 +85,7 @@ class IncomingSession implements SyncSession, EventListener {
|
||||
dbExecutor.execute(new ReceiveRequest(r));
|
||||
} else if (recordReader.hasVersions()) {
|
||||
Versions v = recordReader.readVersions();
|
||||
// TODO: Store remote peer's supported versions
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Received supported versions: "
|
||||
+ v.getSupportedVersions());
|
||||
}
|
||||
dbExecutor.execute(new ReceiveVersions(v));
|
||||
} else {
|
||||
// unknown records are ignored in RecordReader#eof()
|
||||
throw new FormatException();
|
||||
@@ -199,4 +196,26 @@ class IncomingSession implements SyncSession, EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ReceiveVersions implements Runnable {
|
||||
|
||||
private final Versions versions;
|
||||
|
||||
private ReceiveVersions(Versions versions) {
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<Byte> supported = versions.getSupportedVersions();
|
||||
db.transaction(false,
|
||||
txn -> db.setSyncVersions(txn, contactId, supported));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user