mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
More static imports.
This commit is contained in:
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.account.AccountManager;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -18,6 +17,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
|
||||||
|
|
||||||
class AndroidAccountManager extends AccountManagerImpl
|
class AndroidAccountManager extends AccountManagerImpl
|
||||||
implements AccountManager {
|
implements AccountManager {
|
||||||
@@ -99,7 +99,7 @@ class AndroidAccountManager extends AccountManagerImpl
|
|||||||
for (File child : children) {
|
for (File child : children) {
|
||||||
String name = child.getName();
|
String name = child.getName();
|
||||||
if (!name.equals("lib") && !name.equals("shared_prefs")) {
|
if (!name.equals("lib") && !name.equals("shared_prefs")) {
|
||||||
IoUtils.deleteFileOrDir(child);
|
deleteFileOrDir(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.io.IOException;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
@@ -48,6 +47,7 @@ import static android.bluetooth.BluetoothAdapter.STATE_OFF;
|
|||||||
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||||
import static android.bluetooth.BluetoothDevice.ACTION_FOUND;
|
import static android.bluetooth.BluetoothDevice.ACTION_FOUND;
|
||||||
import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
|
import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
|
||||||
|
import static java.util.Collections.shuffle;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -260,7 +260,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
appContext.unregisterReceiver(receiver);
|
appContext.unregisterReceiver(receiver);
|
||||||
}
|
}
|
||||||
// Shuffle the addresses so we don't always try the same one first
|
// Shuffle the addresses so we don't always try the same one first
|
||||||
Collections.shuffle(addresses);
|
shuffle(addresses);
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.bramble.plugin.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.battery.BatteryManager;
|
import org.briarproject.bramble.api.battery.BatteryManager;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -104,7 +104,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Use position-independent executable for SDK >= 16
|
// Use position-independent executable for SDK >= 16
|
||||||
if (Build.VERSION.SDK_INT >= 16) architecture += "_pie";
|
if (SDK_INT >= 16) architecture += "_pie";
|
||||||
|
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -23,6 +22,9 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
import static android.os.Build.FINGERPRINT;
|
||||||
|
import static android.os.Build.SERIAL;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.provider.Settings.Secure.ANDROID_ID;
|
import static android.provider.Settings.Secure.ANDROID_ID;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -45,8 +47,8 @@ class AndroidSecureRandomProvider extends UnixSecureRandomProvider {
|
|||||||
out.writeInt(android.os.Process.myPid());
|
out.writeInt(android.os.Process.myPid());
|
||||||
out.writeInt(android.os.Process.myTid());
|
out.writeInt(android.os.Process.myTid());
|
||||||
out.writeInt(android.os.Process.myUid());
|
out.writeInt(android.os.Process.myUid());
|
||||||
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
|
if (FINGERPRINT != null) out.writeUTF(FINGERPRINT);
|
||||||
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
|
if (SERIAL != null) out.writeUTF(SERIAL);
|
||||||
ContentResolver contentResolver = appContext.getContentResolver();
|
ContentResolver contentResolver = appContext.getContentResolver();
|
||||||
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
|
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
|
||||||
if (id != null) out.writeUTF(id);
|
if (id != null) out.writeUTF(id);
|
||||||
@@ -74,15 +76,13 @@ class AndroidSecureRandomProvider extends UnixSecureRandomProvider {
|
|||||||
// Silence strict mode
|
// Silence strict mode
|
||||||
StrictMode.ThreadPolicy tp = StrictMode.allowThreadDiskWrites();
|
StrictMode.ThreadPolicy tp = StrictMode.allowThreadDiskWrites();
|
||||||
super.writeSeed();
|
super.writeSeed();
|
||||||
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT <= 18)
|
if (SDK_INT >= 16 && SDK_INT <= 18) applyOpenSslFix();
|
||||||
applyOpenSslFix();
|
|
||||||
StrictMode.setThreadPolicy(tp);
|
StrictMode.setThreadPolicy(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on https://android-developers.googleblog.com/2013/08/some-securerandom-thoughts.html
|
// Based on https://android-developers.googleblog.com/2013/08/some-securerandom-thoughts.html
|
||||||
private void applyOpenSslFix() {
|
private void applyOpenSslFix() {
|
||||||
byte[] seed = new UnixSecureRandomSpi().engineGenerateSeed(
|
byte[] seed = new UnixSecureRandomSpi().engineGenerateSeed(SEED_LENGTH);
|
||||||
SEED_LENGTH);
|
|
||||||
try {
|
try {
|
||||||
// Seed the OpenSSL PRNG
|
// Seed the OpenSSL PRNG
|
||||||
Class.forName("org.apache.harmony.xnet.provider.jsse.NativeCrypto")
|
Class.forName("org.apache.harmony.xnet.provider.jsse.NativeCrypto")
|
||||||
|
|||||||
@@ -3,17 +3,19 @@ package org.briarproject.bramble.util;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static android.os.Build.CPU_ABI;
|
||||||
|
import static android.os.Build.CPU_ABI2;
|
||||||
|
import static android.os.Build.SUPPORTED_ABIS;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
|
||||||
public class AndroidUtils {
|
public class AndroidUtils {
|
||||||
@@ -27,10 +29,10 @@ public class AndroidUtils {
|
|||||||
public static Collection<String> getSupportedArchitectures() {
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
List<String> abis = new ArrayList<>();
|
List<String> abis = new ArrayList<>();
|
||||||
if (SDK_INT >= 21) {
|
if (SDK_INT >= 21) {
|
||||||
abis.addAll(Arrays.asList(Build.SUPPORTED_ABIS));
|
abis.addAll(asList(SUPPORTED_ABIS));
|
||||||
} else {
|
} else {
|
||||||
abis.add(Build.CPU_ABI);
|
abis.add(CPU_ABI);
|
||||||
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
if (CPU_ABI2 != null) abis.add(CPU_ABI2);
|
||||||
}
|
}
|
||||||
return abis;
|
return abis;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.bramble.api;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@@ -10,6 +9,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Collections.unmodifiableSet;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class Multiset<T> {
|
public class Multiset<T> {
|
||||||
@@ -96,6 +97,6 @@ public class Multiset<T> {
|
|||||||
* is unmodifiable.
|
* is unmodifiable.
|
||||||
*/
|
*/
|
||||||
public Set<T> keySet() {
|
public Set<T> keySet() {
|
||||||
return Collections.unmodifiableSet(map.keySet());
|
return unmodifiableSet(map.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class BdfMessageContext {
|
public class BdfMessageContext {
|
||||||
@@ -23,7 +24,7 @@ public class BdfMessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BdfMessageContext(BdfDictionary dictionary) {
|
public BdfMessageContext(BdfDictionary dictionary) {
|
||||||
this(dictionary, Collections.emptyList());
|
this(dictionary, emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BdfDictionary getDictionary() {
|
public BdfDictionary getDictionary() {
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import org.briarproject.bramble.api.Bytes;
|
|||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@@ -22,7 +22,7 @@ public class BdfList extends ArrayList<Object> {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public static BdfList of(Object... items) {
|
public static BdfList of(Object... items) {
|
||||||
return new BdfList(Arrays.asList(items));
|
return new BdfList(asList(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BdfList() {
|
public BdfList() {
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package org.briarproject.bramble.api.db;
|
|||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||||
*/
|
*/
|
||||||
@@ -53,7 +54,7 @@ public class Transaction {
|
|||||||
* Returns any events attached to the transaction.
|
* Returns any events attached to the transaction.
|
||||||
*/
|
*/
|
||||||
public List<Event> getEvents() {
|
public List<Event> getEvents() {
|
||||||
if (events == null) return Collections.emptyList();
|
if (events == null) return emptyList();
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import org.briarproject.bramble.api.db.Metadata;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class MessageContext {
|
public class MessageContext {
|
||||||
@@ -22,7 +23,7 @@ public class MessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessageContext(Metadata metadata) {
|
public MessageContext(Metadata metadata) {
|
||||||
this(metadata, Collections.emptyList());
|
this(metadata, emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Metadata getMetadata() {
|
public Metadata getMetadata() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -19,15 +20,15 @@ public class BdfDictionaryTest extends BrambleTestCase {
|
|||||||
public void testConstructors() {
|
public void testConstructors() {
|
||||||
assertEquals(Collections.<String, Object>emptyMap(),
|
assertEquals(Collections.<String, Object>emptyMap(),
|
||||||
new BdfDictionary());
|
new BdfDictionary());
|
||||||
assertEquals(Collections.singletonMap("foo", NULL_VALUE),
|
assertEquals(singletonMap("foo", NULL_VALUE),
|
||||||
new BdfDictionary(Collections.singletonMap("foo", NULL_VALUE)));
|
new BdfDictionary(singletonMap("foo", NULL_VALUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryMethod() {
|
public void testFactoryMethod() {
|
||||||
assertEquals(Collections.<String, Object>emptyMap(),
|
assertEquals(Collections.<String, Object>emptyMap(),
|
||||||
BdfDictionary.of());
|
BdfDictionary.of());
|
||||||
assertEquals(Collections.singletonMap("foo", NULL_VALUE),
|
assertEquals(singletonMap("foo", NULL_VALUE),
|
||||||
BdfDictionary.of(new BdfEntry("foo", NULL_VALUE)));
|
BdfDictionary.of(new BdfEntry("foo", NULL_VALUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import org.briarproject.bramble.api.FormatException;
|
|||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import static java.util.Arrays.asList;
|
||||||
import java.util.Collections;
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -16,15 +15,15 @@ public class BdfListTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructors() {
|
public void testConstructors() {
|
||||||
assertEquals(Collections.emptyList(), new BdfList());
|
assertEquals(emptyList(), new BdfList());
|
||||||
assertEquals(Arrays.asList(1, 2, NULL_VALUE),
|
assertEquals(asList(1, 2, NULL_VALUE),
|
||||||
new BdfList(Arrays.asList(1, 2, NULL_VALUE)));
|
new BdfList(asList(1, 2, NULL_VALUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryMethod() {
|
public void testFactoryMethod() {
|
||||||
assertEquals(Collections.emptyList(), BdfList.of());
|
assertEquals(emptyList(), BdfList.of());
|
||||||
assertEquals(Arrays.asList(1, 2, NULL_VALUE),
|
assertEquals(asList(1, 2, NULL_VALUE),
|
||||||
BdfList.of(1, 2, NULL_VALUE));
|
BdfList.of(1, 2, NULL_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,10 @@ import org.briarproject.bramble.api.sync.Group;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -25,6 +23,7 @@ import java.util.Random;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.sort;
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
@@ -33,6 +32,7 @@ import static org.briarproject.bramble.api.properties.TransportPropertyConstants
|
|||||||
import static org.briarproject.bramble.api.sync.ClientId.MAX_CLIENT_ID_LENGTH;
|
import static org.briarproject.bramble.api.sync.ClientId.MAX_CLIENT_ID_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
@@ -48,7 +48,7 @@ public class TestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteTestDirectory(File testDir) {
|
public static void deleteTestDirectory(File testDir) {
|
||||||
IoUtils.deleteFileOrDir(testDir);
|
deleteFileOrDir(testDir);
|
||||||
testDir.getParentFile().delete(); // Delete if empty
|
testDir.getParentFile().delete(); // Delete if empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class TestUtils {
|
|||||||
if (size == 0) throw new IllegalArgumentException();
|
if (size == 0) throw new IllegalArgumentException();
|
||||||
List<Double> sorted = new ArrayList<>(size);
|
List<Double> sorted = new ArrayList<>(size);
|
||||||
for (Number n : samples) sorted.add(n.doubleValue());
|
for (Number n : samples) sorted.add(n.doubleValue());
|
||||||
Collections.sort(sorted);
|
sort(sorted);
|
||||||
if (size % 2 == 1) return sorted.get(size / 2);
|
if (size % 2 == 1) return sorted.get(size / 2);
|
||||||
double low = sorted.get(size / 2 - 1), high = sorted.get(size / 2);
|
double low = sorted.get(size / 2 - 1), high = sorted.get(size / 2);
|
||||||
return (low + high) / 2;
|
return (low + high) / 2;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.identity.IdentityManager;
|
|||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -23,6 +22,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||||
@@ -182,8 +182,8 @@ class AccountManagerImpl implements AccountManager {
|
|||||||
public void deleteAccount() {
|
public void deleteAccount() {
|
||||||
synchronized (stateChangeLock) {
|
synchronized (stateChangeLock) {
|
||||||
LOG.info("Deleting account");
|
LOG.info("Deleting account");
|
||||||
IoUtils.deleteFileOrDir(databaseConfig.getDatabaseKeyDirectory());
|
deleteFileOrDir(databaseConfig.getDatabaseKeyDirectory());
|
||||||
IoUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||||
databaseKey = null;
|
databaseKey = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.ByteUtils.INT_32_BYTES;
|
import static org.briarproject.bramble.util.ByteUtils.INT_32_BYTES;
|
||||||
@@ -190,7 +191,7 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
PrivateKey ourPriv = ourKeyPair.getPrivate();
|
PrivateKey ourPriv = ourKeyPair.getPrivate();
|
||||||
byte[][] hashInputs = new byte[inputs.length + 1][];
|
byte[][] hashInputs = new byte[inputs.length + 1][];
|
||||||
hashInputs[0] = performRawKeyAgreement(ourPriv, theirPublicKey);
|
hashInputs[0] = performRawKeyAgreement(ourPriv, theirPublicKey);
|
||||||
System.arraycopy(inputs, 0, hashInputs, 1, inputs.length);
|
arraycopy(inputs, 0, hashInputs, 1, inputs.length);
|
||||||
byte[] hash = hash(label, hashInputs);
|
byte[] hash = hash(label, hashInputs);
|
||||||
if (hash.length != SecretKey.LENGTH) throw new IllegalStateException();
|
if (hash.length != SecretKey.LENGTH) throw new IllegalStateException();
|
||||||
return new SecretKey(hash);
|
return new SecretKey(hash);
|
||||||
@@ -299,13 +300,13 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
output[outputOff] = PBKDF_FORMAT_SCRYPT;
|
output[outputOff] = PBKDF_FORMAT_SCRYPT;
|
||||||
outputOff++;
|
outputOff++;
|
||||||
// Salt
|
// Salt
|
||||||
System.arraycopy(salt, 0, output, outputOff, salt.length);
|
arraycopy(salt, 0, output, outputOff, salt.length);
|
||||||
outputOff += salt.length;
|
outputOff += salt.length;
|
||||||
// Cost parameter
|
// Cost parameter
|
||||||
writeUint32(cost, output, outputOff);
|
writeUint32(cost, output, outputOff);
|
||||||
outputOff += INT_32_BYTES;
|
outputOff += INT_32_BYTES;
|
||||||
// IV
|
// IV
|
||||||
System.arraycopy(iv, 0, output, outputOff, iv.length);
|
arraycopy(iv, 0, output, outputOff, iv.length);
|
||||||
outputOff += iv.length;
|
outputOff += iv.length;
|
||||||
// Initialise the cipher and encrypt the plaintext
|
// Initialise the cipher and encrypt the plaintext
|
||||||
try {
|
try {
|
||||||
@@ -335,7 +336,7 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
return null; // Unknown format
|
return null; // Unknown format
|
||||||
// Salt
|
// Salt
|
||||||
byte[] salt = new byte[PBKDF_SALT_BYTES];
|
byte[] salt = new byte[PBKDF_SALT_BYTES];
|
||||||
System.arraycopy(input, inputOff, salt, 0, salt.length);
|
arraycopy(input, inputOff, salt, 0, salt.length);
|
||||||
inputOff += salt.length;
|
inputOff += salt.length;
|
||||||
// Cost parameter
|
// Cost parameter
|
||||||
long cost = readUint32(input, inputOff);
|
long cost = readUint32(input, inputOff);
|
||||||
@@ -344,7 +345,7 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
return null; // Invalid cost parameter
|
return null; // Invalid cost parameter
|
||||||
// IV
|
// IV
|
||||||
byte[] iv = new byte[STORAGE_IV_BYTES];
|
byte[] iv = new byte[STORAGE_IV_BYTES];
|
||||||
System.arraycopy(input, inputOff, iv, 0, iv.length);
|
arraycopy(input, inputOff, iv, 0, iv.length);
|
||||||
inputOff += iv.length;
|
inputOff += iv.length;
|
||||||
// Derive the key from the password
|
// Derive the key from the password
|
||||||
SecretKey key = passwordBasedKdf.deriveKey(password, salt, (int) cost);
|
SecretKey key = passwordBasedKdf.deriveKey(password, salt, (int) cost);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class Curve25519KeyParser implements KeyParser {
|
class Curve25519KeyParser implements KeyParser {
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ class Curve25519KeyParser implements KeyParser {
|
|||||||
|
|
||||||
static byte[] clamp(byte[] b) {
|
static byte[] clamp(byte[] b) {
|
||||||
byte[] clamped = new byte[32];
|
byte[] clamped = new byte[32];
|
||||||
System.arraycopy(b, 0, clamped, 0, 32);
|
arraycopy(b, 0, clamped, 0, 32);
|
||||||
clamped[0] &= 248;
|
clamped[0] &= 248;
|
||||||
clamped[31] &= 127;
|
clamped[31] &= 127;
|
||||||
clamped[31] |= 64;
|
clamped[31] |= 64;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
||||||
|
|
||||||
class KeyAgreementCryptoImpl implements KeyAgreementCrypto {
|
class KeyAgreementCryptoImpl implements KeyAgreementCrypto {
|
||||||
@@ -24,7 +25,7 @@ class KeyAgreementCryptoImpl implements KeyAgreementCrypto {
|
|||||||
byte[] hash = crypto.hash(COMMIT_LABEL, publicKey.getEncoded());
|
byte[] hash = crypto.hash(COMMIT_LABEL, publicKey.getEncoded());
|
||||||
// The output is the first COMMIT_LENGTH bytes of the hash
|
// The output is the first COMMIT_LENGTH bytes of the hash
|
||||||
byte[] commitment = new byte[COMMIT_LENGTH];
|
byte[] commitment = new byte[COMMIT_LENGTH];
|
||||||
System.arraycopy(hash, 0, commitment, 0, COMMIT_LENGTH);
|
arraycopy(hash, 0, commitment, 0, COMMIT_LENGTH);
|
||||||
return commitment;
|
return commitment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
@@ -56,12 +57,12 @@ class Sec1KeyParser implements KeyParser {
|
|||||||
if (encodedKey[0] != 4) throw new GeneralSecurityException();
|
if (encodedKey[0] != 4) throw new GeneralSecurityException();
|
||||||
// The x co-ordinate must be >= 0 and < p
|
// The x co-ordinate must be >= 0 and < p
|
||||||
byte[] xBytes = new byte[bytesPerInt];
|
byte[] xBytes = new byte[bytesPerInt];
|
||||||
System.arraycopy(encodedKey, 1, xBytes, 0, bytesPerInt);
|
arraycopy(encodedKey, 1, xBytes, 0, bytesPerInt);
|
||||||
BigInteger x = new BigInteger(1, xBytes); // Positive signum
|
BigInteger x = new BigInteger(1, xBytes); // Positive signum
|
||||||
if (x.compareTo(modulus) >= 0) throw new GeneralSecurityException();
|
if (x.compareTo(modulus) >= 0) throw new GeneralSecurityException();
|
||||||
// The y co-ordinate must be >= 0 and < p
|
// The y co-ordinate must be >= 0 and < p
|
||||||
byte[] yBytes = new byte[bytesPerInt];
|
byte[] yBytes = new byte[bytesPerInt];
|
||||||
System.arraycopy(encodedKey, 1 + bytesPerInt, yBytes, 0, bytesPerInt);
|
arraycopy(encodedKey, 1 + bytesPerInt, yBytes, 0, bytesPerInt);
|
||||||
BigInteger y = new BigInteger(1, yBytes); // Positive signum
|
BigInteger y = new BigInteger(1, yBytes); // Positive signum
|
||||||
if (y.compareTo(modulus) >= 0) throw new GeneralSecurityException();
|
if (y.compareTo(modulus) >= 0) throw new GeneralSecurityException();
|
||||||
// Verify that y^2 == x^3 + ax + b (mod p)
|
// Verify that y^2 == x^3 + ax + b (mod p)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package org.briarproject.bramble.crypto;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class Sec1Utils {
|
class Sec1Utils {
|
||||||
|
|
||||||
@@ -10,10 +12,10 @@ class Sec1Utils {
|
|||||||
if (src.length < destLen) {
|
if (src.length < destLen) {
|
||||||
int padding = destLen - src.length;
|
int padding = destLen - src.length;
|
||||||
for (int i = destOff; i < destOff + padding; i++) dest[i] = 0;
|
for (int i = destOff; i < destOff + padding; i++) dest[i] = 0;
|
||||||
System.arraycopy(src, 0, dest, destOff + padding, src.length);
|
arraycopy(src, 0, dest, destOff + padding, src.length);
|
||||||
} else {
|
} else {
|
||||||
int srcOff = src.length - destLen;
|
int srcOff = src.length - destLen;
|
||||||
System.arraycopy(src, srcOff, dest, destOff, destLen);
|
arraycopy(src, srcOff, dest, destOff, destLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.security.GeneralSecurityException;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
|
||||||
@@ -131,7 +132,7 @@ class StreamDecrypterImpl implements StreamDecrypter {
|
|||||||
}
|
}
|
||||||
// Extract the nonce
|
// Extract the nonce
|
||||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||||
System.arraycopy(streamHeaderCiphertext, 0, streamHeaderNonce, 0,
|
arraycopy(streamHeaderCiphertext, 0, streamHeaderNonce, 0,
|
||||||
STREAM_HEADER_NONCE_LENGTH);
|
STREAM_HEADER_NONCE_LENGTH);
|
||||||
// Decrypt and authenticate the stream header
|
// Decrypt and authenticate the stream header
|
||||||
try {
|
try {
|
||||||
@@ -155,7 +156,7 @@ class StreamDecrypterImpl implements StreamDecrypter {
|
|||||||
if (receivedStreamNumber != streamNumber) throw new FormatException();
|
if (receivedStreamNumber != streamNumber) throw new FormatException();
|
||||||
// Extract the frame key
|
// Extract the frame key
|
||||||
byte[] frameKeyBytes = new byte[SecretKey.LENGTH];
|
byte[] frameKeyBytes = new byte[SecretKey.LENGTH];
|
||||||
System.arraycopy(streamHeaderPlaintext, INT_16_BYTES + INT_64_BYTES,
|
arraycopy(streamHeaderPlaintext, INT_16_BYTES + INT_64_BYTES,
|
||||||
frameKeyBytes, 0, SecretKey.LENGTH);
|
frameKeyBytes, 0, SecretKey.LENGTH);
|
||||||
frameKey = new SecretKey(frameKeyBytes);
|
frameKey = new SecretKey(frameKeyBytes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.security.GeneralSecurityException;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
|
||||||
@@ -89,7 +90,7 @@ class StreamEncrypterImpl implements StreamEncrypter {
|
|||||||
throw new RuntimeException(badCipher);
|
throw new RuntimeException(badCipher);
|
||||||
}
|
}
|
||||||
// Combine the payload and padding
|
// Combine the payload and padding
|
||||||
System.arraycopy(payload, 0, framePlaintext, 0, payloadLength);
|
arraycopy(payload, 0, framePlaintext, 0, payloadLength);
|
||||||
for (int i = 0; i < paddingLength; i++)
|
for (int i = 0; i < paddingLength; i++)
|
||||||
framePlaintext[payloadLength + i] = 0;
|
framePlaintext[payloadLength + i] = 0;
|
||||||
// Encrypt and authenticate the payload and padding
|
// Encrypt and authenticate the payload and padding
|
||||||
@@ -121,10 +122,10 @@ class StreamEncrypterImpl implements StreamEncrypter {
|
|||||||
byte[] streamHeaderPlaintext = new byte[STREAM_HEADER_PLAINTEXT_LENGTH];
|
byte[] streamHeaderPlaintext = new byte[STREAM_HEADER_PLAINTEXT_LENGTH];
|
||||||
writeUint16(PROTOCOL_VERSION, streamHeaderPlaintext, 0);
|
writeUint16(PROTOCOL_VERSION, streamHeaderPlaintext, 0);
|
||||||
writeUint64(streamNumber, streamHeaderPlaintext, INT_16_BYTES);
|
writeUint64(streamNumber, streamHeaderPlaintext, INT_16_BYTES);
|
||||||
System.arraycopy(frameKey.getBytes(), 0, streamHeaderPlaintext,
|
arraycopy(frameKey.getBytes(), 0, streamHeaderPlaintext,
|
||||||
INT_16_BYTES + INT_64_BYTES, SecretKey.LENGTH);
|
INT_16_BYTES + INT_64_BYTES, SecretKey.LENGTH);
|
||||||
byte[] streamHeaderCiphertext = new byte[STREAM_HEADER_LENGTH];
|
byte[] streamHeaderCiphertext = new byte[STREAM_HEADER_LENGTH];
|
||||||
System.arraycopy(streamHeaderNonce, 0, streamHeaderCiphertext, 0,
|
arraycopy(streamHeaderNonce, 0, streamHeaderCiphertext, 0,
|
||||||
STREAM_HEADER_NONCE_LENGTH);
|
STREAM_HEADER_NONCE_LENGTH);
|
||||||
// Encrypt and authenticate the stream header key
|
// Encrypt and authenticate the stream header key
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.spongycastle.crypto.digests.Blake2bDigest;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_HEADER_LABEL;
|
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_HEADER_LABEL;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_TAG_LABEL;
|
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_TAG_LABEL;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.BOB_HEADER_LABEL;
|
import static org.briarproject.bramble.api.transport.TransportConstants.BOB_HEADER_LABEL;
|
||||||
@@ -134,6 +135,6 @@ class TransportCryptoImpl implements TransportCrypto {
|
|||||||
byte[] mac = new byte[macLength];
|
byte[] mac = new byte[macLength];
|
||||||
prf.doFinal(mac, 0);
|
prf.doFinal(mac, 0);
|
||||||
// The output is the first TAG_LENGTH bytes of the MAC
|
// The output is the first TAG_LENGTH bytes of the MAC
|
||||||
System.arraycopy(mac, 0, tag, 0, TAG_LENGTH);
|
arraycopy(mac, 0, tag, 0, TAG_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ import org.briarproject.bramble.api.transport.TransportKeys;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -72,6 +71,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
@@ -899,7 +899,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
if (old == INVISIBLE) db.addGroupVisibility(txn, c, g, v == SHARED);
|
if (old == INVISIBLE) db.addGroupVisibility(txn, c, g, v == SHARED);
|
||||||
else if (v == INVISIBLE) db.removeGroupVisibility(txn, c, g);
|
else if (v == INVISIBLE) db.removeGroupVisibility(txn, c, g);
|
||||||
else db.setGroupVisibility(txn, c, g, v == SHARED);
|
else db.setGroupVisibility(txn, c, g, v == SHARED);
|
||||||
List<ContactId> affected = Collections.singletonList(c);
|
List<ContactId> affected = singletonList(c);
|
||||||
transaction.attach(new GroupVisibilityUpdatedEvent(affected));
|
transaction.attach(new GroupVisibilityUpdatedEvent(affected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -55,8 +53,12 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static java.sql.Types.INTEGER;
|
import static java.sql.Types.INTEGER;
|
||||||
import static java.sql.Types.VARCHAR;
|
import static java.sql.Types.VARCHAR;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
import static java.util.Collections.emptySet;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -424,7 +426,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
List<Migration<Connection>> getMigrations() {
|
List<Migration<Connection>> getMigrations() {
|
||||||
return Arrays.asList(
|
return asList(
|
||||||
new Migration38_39(),
|
new Migration38_39(),
|
||||||
new Migration39_40(),
|
new Migration39_40(),
|
||||||
new Migration40_41(dbTypes)
|
new Migration40_41(dbTypes)
|
||||||
@@ -1536,7 +1538,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if (raw == null) throw new MessageDeletedException();
|
if (raw == null) throw new MessageDeletedException();
|
||||||
if (raw.length <= MESSAGE_HEADER_LENGTH) throw new AssertionError();
|
if (raw.length <= MESSAGE_HEADER_LENGTH) throw new AssertionError();
|
||||||
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
|
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
|
||||||
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
|
arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
|
||||||
return new Message(m, g, timestamp, body);
|
return new Message(m, g, timestamp, body);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
tryToClose(rs, LOG, WARNING);
|
tryToClose(rs, LOG, WARNING);
|
||||||
@@ -1596,7 +1598,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if (intersection == null) intersection = ids;
|
if (intersection == null) intersection = ids;
|
||||||
else intersection.retainAll(ids);
|
else intersection.retainAll(ids);
|
||||||
// Return early if there are no matches
|
// Return early if there are no matches
|
||||||
if (intersection.isEmpty()) return Collections.emptySet();
|
if (intersection.isEmpty()) return emptySet();
|
||||||
}
|
}
|
||||||
if (intersection == null) throw new AssertionError();
|
if (intersection == null) throw new AssertionError();
|
||||||
return intersection;
|
return intersection;
|
||||||
@@ -1645,7 +1647,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
GroupId g, Metadata query) throws DbException {
|
GroupId g, Metadata query) throws DbException {
|
||||||
// Retrieve the matching message IDs
|
// Retrieve the matching message IDs
|
||||||
Collection<MessageId> matches = getMessageIds(txn, g, query);
|
Collection<MessageId> matches = getMessageIds(txn, g, query);
|
||||||
if (matches.isEmpty()) return Collections.emptyMap();
|
if (matches.isEmpty()) return emptyMap();
|
||||||
// Retrieve the metadata for each match
|
// Retrieve the metadata for each match
|
||||||
Map<MessageId, Metadata> all = new HashMap<>(matches.size());
|
Map<MessageId, Metadata> all = new HashMap<>(matches.size());
|
||||||
for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m));
|
for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m));
|
||||||
@@ -2395,7 +2397,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
if (notRemoved.isEmpty()) return Collections.emptyMap();
|
if (notRemoved.isEmpty()) return emptyMap();
|
||||||
// Update any keys that already exist
|
// Update any keys that already exist
|
||||||
String sql = "UPDATE " + tableName + " SET value = ?"
|
String sql = "UPDATE " + tableName + " SET value = ?"
|
||||||
+ " WHERE " + columnName + " = ? AND metaKey = ?";
|
+ " WHERE " + columnName + " = ? AND metaKey = ?";
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -24,6 +23,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Multiset<ContactId> m = connections.get(t);
|
Multiset<ContactId> m = connections.get(t);
|
||||||
if (m == null) return Collections.emptyList();
|
if (m == null) return emptyList();
|
||||||
List<ContactId> ids = new ArrayList<>(m.keySet());
|
List<ContactId> ids = new ArrayList<>(m.keySet());
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info(ids.size() + " contacts connected: " + t);
|
LOG.info(ids.size() + " contacts connected: " + t);
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import org.briarproject.bramble.api.properties.TransportProperties;
|
|||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.plugin.WanTcpConstants.ID;
|
import static org.briarproject.bramble.api.plugin.WanTcpConstants.ID;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -80,8 +81,7 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
protected List<InetSocketAddress> getRemoteSocketAddresses(
|
protected List<InetSocketAddress> getRemoteSocketAddresses(
|
||||||
TransportProperties p) {
|
TransportProperties p) {
|
||||||
InetSocketAddress parsed = parseSocketAddress(p.get(PROP_IP_PORT));
|
InetSocketAddress parsed = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||||
if (parsed == null) return Collections.emptyList();
|
return parsed == null ? emptyList() : singletonList(parsed);
|
||||||
return Collections.singletonList(parsed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -58,6 +56,9 @@ import java.util.zip.ZipInputStream;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -252,11 +253,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
controlConnection.authenticate(read(cookieFile));
|
controlConnection.authenticate(read(cookieFile));
|
||||||
// Tell Tor to exit when the control connection is closed
|
// Tell Tor to exit when the control connection is closed
|
||||||
controlConnection.takeOwnership();
|
controlConnection.takeOwnership();
|
||||||
controlConnection.resetConf(Collections.singletonList(OWNER));
|
controlConnection.resetConf(singletonList(OWNER));
|
||||||
running = true;
|
running = true;
|
||||||
// Register to receive events from the Tor process
|
// Register to receive events from the Tor process
|
||||||
controlConnection.setEventHandler(this);
|
controlConnection.setEventHandler(this);
|
||||||
controlConnection.setEvents(Arrays.asList(EVENTS));
|
controlConnection.setEvents(asList(EVENTS));
|
||||||
// Check whether Tor has already bootstrapped
|
// Check whether Tor has already bootstrapped
|
||||||
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
||||||
if (phase != null && phase.contains("PROGRESS=100")) {
|
if (phase != null && phase.contains("PROGRESS=100")) {
|
||||||
@@ -411,8 +412,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
if (!running) return;
|
if (!running) return;
|
||||||
LOG.info("Creating hidden service");
|
LOG.info("Creating hidden service");
|
||||||
String privKey = settings.get(HS_PRIVKEY);
|
String privKey = settings.get(HS_PRIVKEY);
|
||||||
Map<Integer, String> portLines =
|
Map<Integer, String> portLines = singletonMap(80, "127.0.0.1:" + port);
|
||||||
Collections.singletonMap(80, "127.0.0.1:" + port);
|
|
||||||
Map<String, String> response;
|
Map<String, String> response;
|
||||||
try {
|
try {
|
||||||
// Use the control connection to set up the hidden service
|
// Use the control connection to set up the hidden service
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import java.io.InputStream;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ReceiverInputStream extends InputStream {
|
class ReceiverInputStream extends InputStream {
|
||||||
@@ -44,7 +46,7 @@ class ReceiverInputStream extends InputStream {
|
|||||||
while (length == 0) if (!receive()) return -1;
|
while (length == 0) if (!receive()) return -1;
|
||||||
if (data == null) throw new AssertionError();
|
if (data == null) throw new AssertionError();
|
||||||
len = Math.min(len, length);
|
len = Math.min(len, length);
|
||||||
System.arraycopy(data.getBuffer(), offset, b, off, len);
|
arraycopy(data.getBuffer(), offset, b, off, len);
|
||||||
offset += len;
|
offset += len;
|
||||||
length -= len;
|
length -= len;
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class SenderOutputStream extends OutputStream {
|
class SenderOutputStream extends OutputStream {
|
||||||
@@ -59,20 +61,20 @@ class SenderOutputStream extends OutputStream {
|
|||||||
public void write(byte[] b, int off, int len) throws IOException {
|
public void write(byte[] b, int off, int len) throws IOException {
|
||||||
int available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
|
int available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
|
||||||
while (available <= len) {
|
while (available <= len) {
|
||||||
System.arraycopy(b, off, buf, offset, available);
|
arraycopy(b, off, buf, offset, available);
|
||||||
offset += available;
|
offset += available;
|
||||||
send(false);
|
send(false);
|
||||||
off += available;
|
off += available;
|
||||||
len -= available;
|
len -= available;
|
||||||
available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
|
available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
|
||||||
}
|
}
|
||||||
System.arraycopy(b, off, buf, offset, len);
|
arraycopy(b, off, buf, offset, len);
|
||||||
offset += len;
|
offset += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(boolean lastFrame) throws IOException {
|
private void send(boolean lastFrame) throws IOException {
|
||||||
byte[] frame = new byte[offset + Data.FOOTER_LENGTH];
|
byte[] frame = new byte[offset + Data.FOOTER_LENGTH];
|
||||||
System.arraycopy(buf, 0, frame, 0, frame.length);
|
arraycopy(buf, 0, frame, 0, frame.length);
|
||||||
Data d = new Data(frame);
|
Data d = new Data(frame);
|
||||||
d.setLastFrame(lastFrame);
|
d.setLastFrame(lastFrame);
|
||||||
d.setSequenceNumber(sequenceNumber++);
|
d.setSequenceNumber(sequenceNumber++);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class SlipDecoder implements ReadHandler {
|
class SlipDecoder implements ReadHandler {
|
||||||
@@ -36,7 +38,7 @@ class SlipDecoder implements ReadHandler {
|
|||||||
} else {
|
} else {
|
||||||
if (decodedLength > 0) {
|
if (decodedLength > 0) {
|
||||||
byte[] decoded = new byte[decodedLength];
|
byte[] decoded = new byte[decodedLength];
|
||||||
System.arraycopy(buf, 0, decoded, 0, decodedLength);
|
arraycopy(buf, 0, decoded, 0, decodedLength);
|
||||||
readHandler.handleRead(decoded);
|
readHandler.handleRead(decoded);
|
||||||
}
|
}
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.bramble.reporting;
|
package org.briarproject.bramble.reporting;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -17,6 +16,9 @@ import java.util.concurrent.Semaphore;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.io.File.createTempFile;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.getInputStream;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class DevReportServer {
|
public class DevReportServer {
|
||||||
@@ -131,9 +133,9 @@ public class DevReportServer {
|
|||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
||||||
in = IoUtils.getInputStream(socket);
|
in = getInputStream(socket);
|
||||||
reportDir.mkdirs();
|
reportDir.mkdirs();
|
||||||
reportFile = File.createTempFile(FILE_PREFIX, FILE_SUFFIX,
|
reportFile = createTempFile(FILE_PREFIX, FILE_SUFFIX,
|
||||||
reportDir);
|
reportDir);
|
||||||
out = new FileOutputStream(reportFile);
|
out = new FileOutputStream(reportFile);
|
||||||
System.out.println("Saving report to " + reportFile);
|
System.out.println("Saving report to " + reportFile);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.net.SocketAddress;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.briarproject.bramble.util.ByteUtils.writeUint16;
|
import static org.briarproject.bramble.util.ByteUtils.writeUint16;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.read;
|
||||||
|
|
||||||
class SocksSocket extends Socket {
|
class SocksSocket extends Socket {
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ class SocksSocket extends Socket {
|
|||||||
|
|
||||||
private void receiveMethodResponse(InputStream in) throws IOException {
|
private void receiveMethodResponse(InputStream in) throws IOException {
|
||||||
byte[] methodResponse = new byte[2];
|
byte[] methodResponse = new byte[2];
|
||||||
IoUtils.read(in, methodResponse);
|
read(in, methodResponse);
|
||||||
byte version = methodResponse[0];
|
byte version = methodResponse[0];
|
||||||
byte method = methodResponse[1];
|
byte method = methodResponse[1];
|
||||||
if (version != 5)
|
if (version != 5)
|
||||||
@@ -116,7 +117,7 @@ class SocksSocket extends Socket {
|
|||||||
|
|
||||||
private void receiveConnectResponse(InputStream in) throws IOException {
|
private void receiveConnectResponse(InputStream in) throws IOException {
|
||||||
byte[] connectResponse = new byte[4];
|
byte[] connectResponse = new byte[4];
|
||||||
IoUtils.read(in, connectResponse);
|
read(in, connectResponse);
|
||||||
int version = connectResponse[0] & 0xFF;
|
int version = connectResponse[0] & 0xFF;
|
||||||
int reply = connectResponse[1] & 0xFF;
|
int reply = connectResponse[1] & 0xFF;
|
||||||
int addressType = connectResponse[3] & 0xFF;
|
int addressType = connectResponse[3] & 0xFF;
|
||||||
@@ -127,9 +128,9 @@ class SocksSocket extends Socket {
|
|||||||
throw new IOException("Connection failed: " + ERRORS[reply]);
|
throw new IOException("Connection failed: " + ERRORS[reply]);
|
||||||
else throw new IOException("Connection failed: " + reply);
|
else throw new IOException("Connection failed: " + reply);
|
||||||
}
|
}
|
||||||
if (addressType == 1) IoUtils.read(in, new byte[4]); // IPv4
|
if (addressType == 1) read(in, new byte[4]); // IPv4
|
||||||
else if (addressType == 4) IoUtils.read(in, new byte[16]); // IPv6
|
else if (addressType == 4) read(in, new byte[16]); // IPv6
|
||||||
else throw new IOException("Unsupported address type: " + addressType);
|
else throw new IOException("Unsupported address type: " + addressType);
|
||||||
IoUtils.read(in, new byte[2]); // Port number
|
read(in, new byte[2]); // Port number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.sync.Message.FORMAT_VERSION;
|
import static org.briarproject.bramble.api.sync.Message.FORMAT_VERSION;
|
||||||
import static org.briarproject.bramble.api.sync.MessageId.BLOCK_LABEL;
|
import static org.briarproject.bramble.api.sync.MessageId.BLOCK_LABEL;
|
||||||
import static org.briarproject.bramble.api.sync.MessageId.ID_LABEL;
|
import static org.briarproject.bramble.api.sync.MessageId.ID_LABEL;
|
||||||
@@ -61,11 +62,11 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
if (raw.length > MAX_MESSAGE_LENGTH)
|
if (raw.length > MAX_MESSAGE_LENGTH)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
byte[] groupId = new byte[UniqueId.LENGTH];
|
byte[] groupId = new byte[UniqueId.LENGTH];
|
||||||
System.arraycopy(raw, 0, groupId, 0, UniqueId.LENGTH);
|
arraycopy(raw, 0, groupId, 0, UniqueId.LENGTH);
|
||||||
GroupId g = new GroupId(groupId);
|
GroupId g = new GroupId(groupId);
|
||||||
long timestamp = readUint64(raw, UniqueId.LENGTH);
|
long timestamp = readUint64(raw, UniqueId.LENGTH);
|
||||||
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
|
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
|
||||||
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
|
arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
|
||||||
MessageId id = getMessageId(g, timestamp, body);
|
MessageId id = getMessageId(g, timestamp, body);
|
||||||
return new Message(id, g, timestamp, body);
|
return new Message(id, g, timestamp, body);
|
||||||
}
|
}
|
||||||
@@ -74,9 +75,9 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
public byte[] getRawMessage(Message m) {
|
public byte[] getRawMessage(Message m) {
|
||||||
byte[] body = m.getBody();
|
byte[] body = m.getBody();
|
||||||
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
||||||
System.arraycopy(m.getGroupId().getBytes(), 0, raw, 0, UniqueId.LENGTH);
|
arraycopy(m.getGroupId().getBytes(), 0, raw, 0, UniqueId.LENGTH);
|
||||||
writeUint64(m.getTimestamp(), raw, UniqueId.LENGTH);
|
writeUint64(m.getTimestamp(), raw, UniqueId.LENGTH);
|
||||||
System.arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
|
arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.sync.RecordTypes.ACK;
|
import static org.briarproject.bramble.api.sync.RecordTypes.ACK;
|
||||||
import static org.briarproject.bramble.api.sync.RecordTypes.MESSAGE;
|
import static org.briarproject.bramble.api.sync.RecordTypes.MESSAGE;
|
||||||
import static org.briarproject.bramble.api.sync.RecordTypes.OFFER;
|
import static org.briarproject.bramble.api.sync.RecordTypes.OFFER;
|
||||||
@@ -107,7 +108,7 @@ class SyncRecordReaderImpl implements SyncRecordReader {
|
|||||||
List<MessageId> ids = new ArrayList<>(payload.length / UniqueId.LENGTH);
|
List<MessageId> ids = new ArrayList<>(payload.length / UniqueId.LENGTH);
|
||||||
for (int off = 0; off < payload.length; off += UniqueId.LENGTH) {
|
for (int off = 0; off < payload.length; off += UniqueId.LENGTH) {
|
||||||
byte[] id = new byte[UniqueId.LENGTH];
|
byte[] id = new byte[UniqueId.LENGTH];
|
||||||
System.arraycopy(payload, off, id, 0, UniqueId.LENGTH);
|
arraycopy(payload, off, id, 0, UniqueId.LENGTH);
|
||||||
ids.add(new MessageId(id));
|
ids.add(new MessageId(id));
|
||||||
}
|
}
|
||||||
nextRecord = null;
|
nextRecord = null;
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package org.briarproject.bramble.transport;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@@ -64,8 +65,8 @@ class ReorderingWindow {
|
|||||||
while (seen[slide]) slide++;
|
while (seen[slide]) slide++;
|
||||||
// If the window doesn't need to slide, return
|
// If the window doesn't need to slide, return
|
||||||
if (slide == 0) {
|
if (slide == 0) {
|
||||||
List<Long> added = Collections.emptyList();
|
List<Long> added = emptyList();
|
||||||
List<Long> removed = Collections.singletonList(index);
|
List<Long> removed = singletonList(index);
|
||||||
return new Change(added, removed);
|
return new Change(added, removed);
|
||||||
}
|
}
|
||||||
// Record the elements that will be added and removed
|
// Record the elements that will be added and removed
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +52,7 @@ class StreamReaderImpl extends InputStream {
|
|||||||
readFrame();
|
readFrame();
|
||||||
}
|
}
|
||||||
len = Math.min(len, length);
|
len = Math.min(len, length);
|
||||||
System.arraycopy(payload, offset, b, off, len);
|
arraycopy(payload, offset, b, off, len);
|
||||||
offset += len;
|
offset += len;
|
||||||
length -= len;
|
length -= len;
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,14 +71,14 @@ class StreamWriterImpl extends OutputStream implements StreamWriter {
|
|||||||
public void write(byte[] b, int off, int len) throws IOException {
|
public void write(byte[] b, int off, int len) throws IOException {
|
||||||
int available = payload.length - length;
|
int available = payload.length - length;
|
||||||
while (available <= len) {
|
while (available <= len) {
|
||||||
System.arraycopy(b, off, payload, length, available);
|
arraycopy(b, off, payload, length, available);
|
||||||
length += available;
|
length += available;
|
||||||
writeFrame(false);
|
writeFrame(false);
|
||||||
off += available;
|
off += available;
|
||||||
len -= available;
|
len -= available;
|
||||||
available = payload.length - length;
|
available = payload.length - length;
|
||||||
}
|
}
|
||||||
System.arraycopy(b, off, payload, length, len);
|
arraycopy(b, off, payload, length, len);
|
||||||
length += len;
|
length += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,6 +44,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.sort;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||||
@@ -134,7 +134,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
|||||||
@Override
|
@Override
|
||||||
public void startService() throws ServiceException {
|
public void startService() throws ServiceException {
|
||||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||||
Collections.sort(versions);
|
sort(versions);
|
||||||
try {
|
try {
|
||||||
db.transaction(false, txn -> {
|
db.transaction(false, txn -> {
|
||||||
if (updateClientVersions(txn, versions)) {
|
if (updateClientVersions(txn, versions)) {
|
||||||
@@ -167,7 +167,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
|||||||
}
|
}
|
||||||
// Create and store the first local update
|
// Create and store the first local update
|
||||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||||
Collections.sort(versions);
|
sort(versions);
|
||||||
storeFirstUpdate(txn, g.getId(), versions);
|
storeFirstUpdate(txn, g.getId(), versions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package org.briarproject.bramble;
|
|||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -119,12 +119,12 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
|||||||
private List<Integer> ascendingOrder() {
|
private List<Integer> ascendingOrder() {
|
||||||
Integer[] array = new Integer[TASKS];
|
Integer[] array = new Integer[TASKS];
|
||||||
for (int i = 0; i < TASKS; i++) array[i] = i;
|
for (int i = 0; i < TASKS; i++) array[i] = i;
|
||||||
return Arrays.asList(array);
|
return asList(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> descendingOrder() {
|
private List<Integer> descendingOrder() {
|
||||||
Integer[] array = new Integer[TASKS];
|
Integer[] array = new Integer[TASKS];
|
||||||
for (int i = 0; i < TASKS; i++) array[i] = TASKS - 1 - i;
|
for (int i = 0; i < TASKS; i++) array[i] = TASKS - 1 - i;
|
||||||
return Arrays.asList(array);
|
return asList(array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ import org.junit.Test;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||||
@@ -166,7 +166,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
oneOf(db).getMessageMetadata(txn, groupId);
|
oneOf(db).getMessageMetadata(txn, groupId);
|
||||||
will(returnValue(Collections.singletonMap(messageId, metadata)));
|
will(returnValue(singletonMap(messageId, metadata)));
|
||||||
oneOf(metadataParser).parse(metadata);
|
oneOf(metadataParser).parse(metadata);
|
||||||
will(returnValue(dictionary));
|
will(returnValue(dictionary));
|
||||||
}});
|
}});
|
||||||
@@ -190,7 +190,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
oneOf(metadataEncoder).encode(query);
|
oneOf(metadataEncoder).encode(query);
|
||||||
will(returnValue(queryMetadata));
|
will(returnValue(queryMetadata));
|
||||||
oneOf(db).getMessageMetadata(txn, groupId, queryMetadata);
|
oneOf(db).getMessageMetadata(txn, groupId, queryMetadata);
|
||||||
will(returnValue(Collections.singletonMap(messageId, metadata)));
|
will(returnValue(singletonMap(messageId, metadata)));
|
||||||
oneOf(metadataParser).parse(metadata);
|
oneOf(metadataParser).parse(metadata);
|
||||||
will(returnValue(dictionary));
|
will(returnValue(dictionary));
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
@@ -98,7 +97,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetContactByAuthor() throws Exception {
|
public void testGetContactByAuthor() throws Exception {
|
||||||
Transaction txn = new Transaction(null, true);
|
Transaction txn = new Transaction(null, true);
|
||||||
Collection<Contact> contacts = Collections.singleton(contact);
|
Collection<Contact> contacts = singletonList(contact);
|
||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||||
@@ -123,7 +122,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test(expected = NoSuchContactException.class)
|
@Test(expected = NoSuchContactException.class)
|
||||||
public void testGetContactByUnknownLocalAuthor() throws Exception {
|
public void testGetContactByUnknownLocalAuthor() throws Exception {
|
||||||
Transaction txn = new Transaction(null, true);
|
Transaction txn = new Transaction(null, true);
|
||||||
Collection<Contact> contacts = Collections.singleton(contact);
|
Collection<Contact> contacts = singletonList(contact);
|
||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||||
@@ -135,7 +134,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetActiveContacts() throws Exception {
|
public void testGetActiveContacts() throws Exception {
|
||||||
Collection<Contact> activeContacts = Collections.singletonList(contact);
|
Collection<Contact> activeContacts = singletonList(contact);
|
||||||
Collection<Contact> contacts = new ArrayList<>(activeContacts);
|
Collection<Contact> contacts = new ArrayList<>(activeContacts);
|
||||||
contacts.add(new Contact(new ContactId(3), remote, local, alias, true,
|
contacts.add(new Contact(new ContactId(3), remote, local, alias, true,
|
||||||
false));
|
false));
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ import java.security.Provider;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.sort;
|
||||||
import static net.i2p.crypto.eddsa.EdDSAEngine.SIGNATURE_ALGORITHM;
|
import static net.i2p.crypto.eddsa.EdDSAEngine.SIGNATURE_ALGORITHM;
|
||||||
|
|
||||||
// Not a JUnit test
|
// Not a JUnit test
|
||||||
@@ -45,9 +45,9 @@ public class EllipticCurvePerformanceTest {
|
|||||||
private static final SecureRandom random = new SecureRandom();
|
private static final SecureRandom random = new SecureRandom();
|
||||||
private static final int SAMPLES = 50;
|
private static final int SAMPLES = 50;
|
||||||
private static final int BYTES_TO_SIGN = 1024;
|
private static final int BYTES_TO_SIGN = 1024;
|
||||||
private static final List<String> SEC_NAMES = Arrays.asList(
|
private static final List<String> SEC_NAMES = asList(
|
||||||
"secp256k1", "secp256r1", "secp384r1", "secp521r1");
|
"secp256k1", "secp256r1", "secp384r1", "secp521r1");
|
||||||
private static final List<String> BRAINPOOL_NAMES = Arrays.asList(
|
private static final List<String> BRAINPOOL_NAMES = asList(
|
||||||
"brainpoolp256r1", "brainpoolp384r1", "brainpoolp512r1");
|
"brainpoolp256r1", "brainpoolp384r1", "brainpoolp512r1");
|
||||||
private static final Provider ED_PROVIDER = new EdDSASecurityProvider();
|
private static final Provider ED_PROVIDER = new EdDSASecurityProvider();
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ public class EllipticCurvePerformanceTest {
|
|||||||
private static long median(List<Long> list) {
|
private static long median(List<Long> list) {
|
||||||
int size = list.size();
|
int size = list.size();
|
||||||
if (size == 0) throw new IllegalArgumentException();
|
if (size == 0) throw new IllegalArgumentException();
|
||||||
Collections.sort(list);
|
sort(list);
|
||||||
if (size % 2 == 1) return list.get(size / 2);
|
if (size % 2 == 1) return list.get(size / 2);
|
||||||
return list.get(size / 2 - 1) + list.get(size / 2) / 2;
|
return list.get(size / 2 - 1) + list.get(size / 2) / 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.security.Provider;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.SecureRandomSpi;
|
import java.security.SecureRandomSpi;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
|
|
||||||
class PseudoSecureRandom extends SecureRandom {
|
class PseudoSecureRandom extends SecureRandom {
|
||||||
|
|
||||||
private static final Provider PROVIDER = new PseudoSecureRandomProvider();
|
private static final Provider PROVIDER = new PseudoSecureRandomProvider();
|
||||||
@@ -28,7 +30,7 @@ class PseudoSecureRandom extends SecureRandom {
|
|||||||
@Override
|
@Override
|
||||||
protected void engineNextBytes(byte[] b) {
|
protected void engineNextBytes(byte[] b) {
|
||||||
byte[] random = pseudoRandom.nextBytes(b.length);
|
byte[] random = pseudoRandom.nextBytes(b.length);
|
||||||
System.arraycopy(random, 0, b, 0, b.length);
|
arraycopy(random, 0, b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
@@ -287,7 +288,7 @@ public class StreamDecrypterImplTest extends BrambleTestCase {
|
|||||||
private static void assertArrayStartsWith(byte[] expected, byte[] actual,
|
private static void assertArrayStartsWith(byte[] expected, byte[] actual,
|
||||||
int len) {
|
int len) {
|
||||||
byte[] prefix = new byte[len];
|
byte[] prefix = new byte[len];
|
||||||
System.arraycopy(actual, 0, prefix, 0, len);
|
arraycopy(actual, 0, prefix, 0, len);
|
||||||
assertArrayEquals(expected, prefix);
|
assertArrayEquals(expected, prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -22,7 +23,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
|
|||||||
public int process(byte[] input, int inputOff, int len, byte[] output,
|
public int process(byte[] input, int inputOff, int len, byte[] output,
|
||||||
int outputOff) throws GeneralSecurityException {
|
int outputOff) throws GeneralSecurityException {
|
||||||
if (encrypt) {
|
if (encrypt) {
|
||||||
System.arraycopy(input, inputOff, output, outputOff, len);
|
arraycopy(input, inputOff, output, outputOff, len);
|
||||||
for (int i = 0; i < MAC_LENGTH; i++)
|
for (int i = 0; i < MAC_LENGTH; i++)
|
||||||
output[outputOff + len + i] = 0;
|
output[outputOff + len + i] = 0;
|
||||||
return len + MAC_LENGTH;
|
return len + MAC_LENGTH;
|
||||||
@@ -30,8 +31,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
|
|||||||
for (int i = 0; i < MAC_LENGTH; i++)
|
for (int i = 0; i < MAC_LENGTH; i++)
|
||||||
if (input[inputOff + len - MAC_LENGTH + i] != 0)
|
if (input[inputOff + len - MAC_LENGTH + i] != 0)
|
||||||
throw new GeneralSecurityException();
|
throw new GeneralSecurityException();
|
||||||
System.arraycopy(input, inputOff, output, outputOff,
|
arraycopy(input, inputOff, output, outputOff, len - MAC_LENGTH);
|
||||||
len - MAC_LENGTH);
|
|
||||||
return len - MAC_LENGTH;
|
return len - MAC_LENGTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.junit.Test;
|
|||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -74,7 +75,7 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BrambleTestCase {
|
|||||||
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
||||||
cipher.init(false, k, TEST_IV);
|
cipher.init(false, k, TEST_IV);
|
||||||
byte[] input = new byte[cipher.getMacBytes() - 1];
|
byte[] input = new byte[cipher.getMacBytes() - 1];
|
||||||
System.arraycopy(TEST_CIPHERTEXT, 0, input, 0, input.length);
|
arraycopy(TEST_CIPHERTEXT, 0, input, 0, input.length);
|
||||||
byte[] output = new byte[TEST_PLAINTEXT.length];
|
byte[] output = new byte[TEST_PLAINTEXT.length];
|
||||||
cipher.process(input, 0, input.length, output, 0);
|
cipher.process(input, 0, input.length, output, 0);
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,7 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BrambleTestCase {
|
|||||||
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
||||||
cipher.init(false, k, TEST_IV);
|
cipher.init(false, k, TEST_IV);
|
||||||
byte[] input = new byte[TEST_CIPHERTEXT.length];
|
byte[] input = new byte[TEST_CIPHERTEXT.length];
|
||||||
System.arraycopy(TEST_CIPHERTEXT, 0, input, 0, TEST_CIPHERTEXT.length);
|
arraycopy(TEST_CIPHERTEXT, 0, input, 0, TEST_CIPHERTEXT.length);
|
||||||
input[new Random().nextInt(TEST_CIPHERTEXT.length)] ^= 0xFF;
|
input[new Random().nextInt(TEST_CIPHERTEXT.length)] ^= 0xFF;
|
||||||
byte[] output = new byte[TEST_PLAINTEXT.length];
|
byte[] output = new byte[TEST_PLAINTEXT.length];
|
||||||
cipher.process(input, 0, input.length, output, 0);
|
cipher.process(input, 0, input.length, output, 0);
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import org.junit.Test;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -47,6 +46,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
@@ -399,10 +399,10 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Both message IDs should be returned
|
// Both message IDs should be returned
|
||||||
Collection<MessageId> ids = db.getMessagesToAck(txn, contactId, 1234);
|
Collection<MessageId> ids = db.getMessagesToAck(txn, contactId, 1234);
|
||||||
assertEquals(Arrays.asList(messageId, messageId1), ids);
|
assertEquals(asList(messageId, messageId1), ids);
|
||||||
|
|
||||||
// Remove both message IDs
|
// Remove both message IDs
|
||||||
db.lowerAckFlag(txn, contactId, Arrays.asList(messageId, messageId1));
|
db.lowerAckFlag(txn, contactId, asList(messageId, messageId1));
|
||||||
|
|
||||||
// Both message IDs should have been removed
|
// Both message IDs should have been removed
|
||||||
assertEquals(emptyList(), db.getMessagesToAck(txn,
|
assertEquals(emptyList(), db.getMessagesToAck(txn,
|
||||||
@@ -414,7 +414,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Both message IDs should be returned
|
// Both message IDs should be returned
|
||||||
ids = db.getMessagesToAck(txn, contactId, 1234);
|
ids = db.getMessagesToAck(txn, contactId, 1234);
|
||||||
assertEquals(Arrays.asList(messageId, messageId1), ids);
|
assertEquals(asList(messageId, messageId1), ids);
|
||||||
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
db.close();
|
db.close();
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||||
private final Collection<LocalAuthor> localAuthors =
|
private final Collection<LocalAuthor> localAuthors =
|
||||||
Collections.singletonList(localAuthor);
|
singletonList(localAuthor);
|
||||||
private final String authorName = localAuthor.getName();
|
private final String authorName = localAuthor.getName();
|
||||||
private final KeyPair keyPair = new KeyPair(publicKey, privateKey);
|
private final KeyPair keyPair = new KeyPair(publicKey, privateKey);
|
||||||
private final byte[] publicKeyBytes = localAuthor.getPublicKey();
|
private final byte[] publicKeyBytes = localAuthor.getPublicKey();
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import org.jmock.Mockery;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -52,38 +53,31 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
|
|||||||
ConnectionRegistry c = new ConnectionRegistryImpl(eventBus);
|
ConnectionRegistry c = new ConnectionRegistryImpl(eventBus);
|
||||||
|
|
||||||
// The registry should be empty
|
// The registry should be empty
|
||||||
assertEquals(Collections.emptyList(),
|
assertEquals(emptyList(), c.getConnectedContacts(transportId));
|
||||||
c.getConnectedContacts(transportId));
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
assertEquals(Collections.emptyList(),
|
|
||||||
c.getConnectedContacts(transportId1));
|
|
||||||
// Check that a registered connection shows up - this should
|
// Check that a registered connection shows up - this should
|
||||||
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
|
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
|
||||||
c.registerConnection(contactId, transportId, true);
|
c.registerConnection(contactId, transportId, true);
|
||||||
assertEquals(Collections.singletonList(contactId),
|
assertEquals(singletonList(contactId),
|
||||||
c.getConnectedContacts(transportId));
|
c.getConnectedContacts(transportId));
|
||||||
assertEquals(Collections.emptyList(),
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
c.getConnectedContacts(transportId1));
|
|
||||||
// Register an identical connection - this should broadcast a
|
// Register an identical connection - this should broadcast a
|
||||||
// ConnectionOpenedEvent and lookup should be unaffected
|
// ConnectionOpenedEvent and lookup should be unaffected
|
||||||
c.registerConnection(contactId, transportId, true);
|
c.registerConnection(contactId, transportId, true);
|
||||||
assertEquals(Collections.singletonList(contactId),
|
assertEquals(singletonList(contactId),
|
||||||
c.getConnectedContacts(transportId));
|
c.getConnectedContacts(transportId));
|
||||||
assertEquals(Collections.emptyList(),
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
c.getConnectedContacts(transportId1));
|
|
||||||
// Unregister one of the connections - this should broadcast a
|
// Unregister one of the connections - this should broadcast a
|
||||||
// ConnectionClosedEvent and lookup should be unaffected
|
// ConnectionClosedEvent and lookup should be unaffected
|
||||||
c.unregisterConnection(contactId, transportId, true);
|
c.unregisterConnection(contactId, transportId, true);
|
||||||
assertEquals(Collections.singletonList(contactId),
|
assertEquals(singletonList(contactId),
|
||||||
c.getConnectedContacts(transportId));
|
c.getConnectedContacts(transportId));
|
||||||
assertEquals(Collections.emptyList(),
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
c.getConnectedContacts(transportId1));
|
|
||||||
// Unregister the other connection - this should broadcast a
|
// Unregister the other connection - this should broadcast a
|
||||||
// ConnectionClosedEvent and a ContactDisconnectedEvent
|
// ConnectionClosedEvent and a ContactDisconnectedEvent
|
||||||
c.unregisterConnection(contactId, transportId, true);
|
c.unregisterConnection(contactId, transportId, true);
|
||||||
assertEquals(Collections.emptyList(),
|
assertEquals(emptyList(), c.getConnectedContacts(transportId));
|
||||||
c.getConnectedContacts(transportId));
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
assertEquals(Collections.emptyList(),
|
|
||||||
c.getConnectedContacts(transportId1));
|
|
||||||
// Try to unregister the connection again - exception should be thrown
|
// Try to unregister the connection again - exception should be thrown
|
||||||
try {
|
try {
|
||||||
c.unregisterConnection(contactId, transportId, true);
|
c.unregisterConnection(contactId, transportId, true);
|
||||||
@@ -101,7 +95,7 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
|
|||||||
assertEquals(2, connected.size());
|
assertEquals(2, connected.size());
|
||||||
assertTrue(connected.contains(contactId));
|
assertTrue(connected.contains(contactId));
|
||||||
assertTrue(connected.contains(contactId1));
|
assertTrue(connected.contains(contactId1));
|
||||||
assertEquals(Collections.singletonList(contactId1),
|
assertEquals(singletonList(contactId1),
|
||||||
c.getConnectedContacts(transportId1));
|
c.getConnectedContacts(transportId1));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ import org.jmock.lib.concurrent.Synchroniser;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
public class PluginManagerImplTest extends BrambleTestCase {
|
public class PluginManagerImplTest extends BrambleTestCase {
|
||||||
@@ -84,8 +84,7 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
|||||||
// start()
|
// start()
|
||||||
// First simplex plugin
|
// First simplex plugin
|
||||||
oneOf(pluginConfig).getSimplexFactories();
|
oneOf(pluginConfig).getSimplexFactories();
|
||||||
will(returnValue(Arrays.asList(simplexFactory,
|
will(returnValue(asList(simplexFactory, simplexFailFactory)));
|
||||||
simplexFailFactory)));
|
|
||||||
oneOf(simplexFactory).getId();
|
oneOf(simplexFactory).getId();
|
||||||
will(returnValue(simplexId));
|
will(returnValue(simplexId));
|
||||||
oneOf(simplexFactory).createPlugin(with(any(
|
oneOf(simplexFactory).createPlugin(with(any(
|
||||||
@@ -102,7 +101,7 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
|||||||
will(throwException(new PluginException()));
|
will(throwException(new PluginException()));
|
||||||
// First duplex plugin
|
// First duplex plugin
|
||||||
oneOf(pluginConfig).getDuplexFactories();
|
oneOf(pluginConfig).getDuplexFactories();
|
||||||
will(returnValue(Arrays.asList(duplexFactory, duplexFailFactory)));
|
will(returnValue(asList(duplexFactory, duplexFailFactory)));
|
||||||
oneOf(duplexFactory).getId();
|
oneOf(duplexFactory).getId();
|
||||||
will(returnValue(duplexId));
|
will(returnValue(duplexId));
|
||||||
oneOf(duplexFactory).createPlugin(with(any(
|
oneOf(duplexFactory).createPlugin(with(any(
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import static java.net.NetworkInterface.getNetworkInterfaces;
|
||||||
|
import static java.util.Collections.list;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
|
||||||
@@ -327,9 +328,8 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean systemHasLocalIpv4Address() throws Exception {
|
private boolean systemHasLocalIpv4Address() throws Exception {
|
||||||
for (NetworkInterface i : Collections.list(
|
for (NetworkInterface i : list(getNetworkInterfaces())) {
|
||||||
NetworkInterface.getNetworkInterfaces())) {
|
for (InetAddress a : list(i.getInetAddresses())) {
|
||||||
for (InetAddress a : Collections.list(i.getInetAddresses())) {
|
|
||||||
if (a instanceof Inet4Address)
|
if (a instanceof Inet4Address)
|
||||||
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
|
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ import org.briarproject.bramble.test.DbExpectations;
|
|||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||||
@@ -448,7 +448,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contactGroup2));
|
will(returnValue(contactGroup2));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup2.getId());
|
contactGroup2.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
// Third contact: returns an update
|
// Third contact: returns an update
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact3);
|
MAJOR_VERSION, contact3);
|
||||||
@@ -514,7 +514,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
// There are no existing properties to merge with
|
// There are no existing properties to merge with
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
localGroup.getId());
|
localGroup.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
// Store the new properties in the local group, version 1
|
// Store the new properties in the local group, version 1
|
||||||
expectStoreMessage(txn, localGroup.getId(), "foo",
|
expectStoreMessage(txn, localGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 1, true, false);
|
fooPropertiesDict, 1, true, false);
|
||||||
@@ -526,7 +526,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup.getId());
|
contactGroup.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(emptyMap()));
|
||||||
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 1, true, true);
|
fooPropertiesDict, 1, true, true);
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.record.Record.MAX_RECORD_PAYLOAD_BYTES;
|
import static org.briarproject.bramble.api.record.Record.MAX_RECORD_PAYLOAD_BYTES;
|
||||||
import static org.briarproject.bramble.api.record.Record.RECORD_HEADER_BYTES;
|
import static org.briarproject.bramble.api.record.Record.RECORD_HEADER_BYTES;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
@@ -42,7 +43,7 @@ public class RecordWriterImplTest extends BrambleTestCase {
|
|||||||
assertEquals(recordType, written[1]);
|
assertEquals(recordType, written[1]);
|
||||||
assertEquals(payloadLength, readUint16(written, 2));
|
assertEquals(payloadLength, readUint16(written, 2));
|
||||||
byte[] writtenPayload = new byte[payloadLength];
|
byte[] writtenPayload = new byte[payloadLength];
|
||||||
System.arraycopy(written, RECORD_HEADER_BYTES, writtenPayload, 0,
|
arraycopy(written, RECORD_HEADER_BYTES, writtenPayload, 0,
|
||||||
payloadLength);
|
payloadLength);
|
||||||
assertArrayEquals(payload, writtenPayload);
|
assertArrayEquals(payload, writtenPayload);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ import org.junit.Test;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
@@ -90,7 +90,7 @@ public class SyncIntegrationTest extends BrambleTestCase {
|
|||||||
byte[] body = "Hello world".getBytes("UTF-8");
|
byte[] body = "Hello world".getBytes("UTF-8");
|
||||||
message = messageFactory.createMessage(group.getId(), timestamp, body);
|
message = messageFactory.createMessage(group.getId(), timestamp, body);
|
||||||
message1 = messageFactory.createMessage(group.getId(), timestamp, body);
|
message1 = messageFactory.createMessage(group.getId(), timestamp, body);
|
||||||
messageIds = Arrays.asList(message.getId(), message1.getId());
|
messageIds = asList(message.getId(), message1.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.bramble.system;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -16,6 +15,7 @@ import java.util.Set;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.read;
|
||||||
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
||||||
import static org.briarproject.bramble.util.OsUtils.isMac;
|
import static org.briarproject.bramble.util.OsUtils.isMac;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
@@ -64,7 +64,7 @@ public class UnixSecureRandomSpiTest extends BrambleTestCase {
|
|||||||
assertEquals(SEED_BYTES, urandom.length());
|
assertEquals(SEED_BYTES, urandom.length());
|
||||||
byte[] written = new byte[SEED_BYTES];
|
byte[] written = new byte[SEED_BYTES];
|
||||||
FileInputStream in = new FileInputStream(urandom);
|
FileInputStream in = new FileInputStream(urandom);
|
||||||
IoUtils.read(in, written);
|
read(in, written);
|
||||||
in.close();
|
in.close();
|
||||||
assertArrayEquals(seed, written);
|
assertArrayEquals(seed, written);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -24,7 +25,7 @@ public class TestMessageFactory implements MessageFactory {
|
|||||||
public byte[] getRawMessage(Message m) {
|
public byte[] getRawMessage(Message m) {
|
||||||
byte[] body = m.getBody();
|
byte[] body = m.getBody();
|
||||||
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
||||||
System.arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
|
arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static java.util.Collections.sort;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
|
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.LARGER;
|
import static org.briarproject.bramble.test.UTest.Result.LARGER;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
|
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
|
||||||
@@ -80,7 +80,7 @@ public class UTest {
|
|||||||
List<Value> sorted = new ArrayList<>(nA + nB);
|
List<Value> sorted = new ArrayList<>(nA + nB);
|
||||||
for (Double d : a) sorted.add(new Value(d, true));
|
for (Double d : a) sorted.add(new Value(d, true));
|
||||||
for (Double d : b) sorted.add(new Value(d, false));
|
for (Double d : b) sorted.add(new Value(d, false));
|
||||||
Collections.sort(sorted);
|
sort(sorted);
|
||||||
|
|
||||||
// Assign ranks to the values
|
// Assign ranks to the values
|
||||||
int i = 0, size = sorted.size();
|
int i = 0, size = sorted.size();
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import org.briarproject.bramble.test.BrambleTestCase;
|
|||||||
import org.briarproject.bramble.transport.ReorderingWindow.Change;
|
import org.briarproject.bramble.transport.ReorderingWindow.Change;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import static java.util.Arrays.asList;
|
||||||
import java.util.Collections;
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
@@ -33,9 +33,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
|
|||||||
Change change = window.setSeen(0L);
|
Change change = window.setSeen(0L);
|
||||||
// The window should slide by one element
|
// The window should slide by one element
|
||||||
assertEquals(1L, window.getBase());
|
assertEquals(1L, window.getBase());
|
||||||
assertEquals(Collections.singletonList((long) REORDERING_WINDOW_SIZE),
|
assertEquals(singletonList((long) REORDERING_WINDOW_SIZE),
|
||||||
change.getAdded());
|
change.getAdded());
|
||||||
assertEquals(Collections.singletonList(0L), change.getRemoved());
|
assertEquals(singletonList(0L), change.getRemoved());
|
||||||
// All elements in the window should be unseen
|
// All elements in the window should be unseen
|
||||||
assertArrayEquals(bitmap, window.getBitmap());
|
assertArrayEquals(bitmap, window.getBitmap());
|
||||||
}
|
}
|
||||||
@@ -48,8 +48,8 @@ public class ReorderingWindowTest extends BrambleTestCase {
|
|||||||
Change change = window.setSeen(1L);
|
Change change = window.setSeen(1L);
|
||||||
// The window should not slide
|
// The window should not slide
|
||||||
assertEquals(0L, window.getBase());
|
assertEquals(0L, window.getBase());
|
||||||
assertEquals(Collections.emptyList(), change.getAdded());
|
assertEquals(emptyList(), change.getAdded());
|
||||||
assertEquals(Collections.singletonList(1L), change.getRemoved());
|
assertEquals(singletonList(1L), change.getRemoved());
|
||||||
// The second element in the window should be seen
|
// The second element in the window should be seen
|
||||||
bitmap[0] = 0x40; // 0100 0000
|
bitmap[0] = 0x40; // 0100 0000
|
||||||
assertArrayEquals(bitmap, window.getBitmap());
|
assertArrayEquals(bitmap, window.getBitmap());
|
||||||
@@ -64,9 +64,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
|
|||||||
Change change = window.setSeen(aboveMidpoint);
|
Change change = window.setSeen(aboveMidpoint);
|
||||||
// The window should slide by one element
|
// The window should slide by one element
|
||||||
assertEquals(1L, window.getBase());
|
assertEquals(1L, window.getBase());
|
||||||
assertEquals(Collections.singletonList((long) REORDERING_WINDOW_SIZE),
|
assertEquals(singletonList((long) REORDERING_WINDOW_SIZE),
|
||||||
change.getAdded());
|
change.getAdded());
|
||||||
assertEquals(Arrays.asList(0L, aboveMidpoint), change.getRemoved());
|
assertEquals(asList(0L, aboveMidpoint), change.getRemoved());
|
||||||
// The highest element below the midpoint should be seen
|
// The highest element below the midpoint should be seen
|
||||||
bitmap[bitmap.length / 2 - 1] = (byte) 0x01; // 0000 0001
|
bitmap[bitmap.length / 2 - 1] = (byte) 0x01; // 0000 0001
|
||||||
assertArrayEquals(bitmap, window.getBitmap());
|
assertArrayEquals(bitmap, window.getBitmap());
|
||||||
@@ -81,9 +81,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
|
|||||||
Change change = window.setSeen(0L);
|
Change change = window.setSeen(0L);
|
||||||
// The window should slide by two elements
|
// The window should slide by two elements
|
||||||
assertEquals(2L, window.getBase());
|
assertEquals(2L, window.getBase());
|
||||||
assertEquals(Arrays.asList((long) REORDERING_WINDOW_SIZE,
|
assertEquals(asList((long) REORDERING_WINDOW_SIZE,
|
||||||
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
|
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
|
||||||
assertEquals(Collections.singletonList(0L), change.getRemoved());
|
assertEquals(singletonList(0L), change.getRemoved());
|
||||||
// All elements in the window should be unseen
|
// All elements in the window should be unseen
|
||||||
assertArrayEquals(bitmap, window.getBitmap());
|
assertArrayEquals(bitmap, window.getBitmap());
|
||||||
}
|
}
|
||||||
@@ -98,9 +98,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
|
|||||||
Change change = window.setSeen(aboveMidpoint);
|
Change change = window.setSeen(aboveMidpoint);
|
||||||
// The window should slide by two elements
|
// The window should slide by two elements
|
||||||
assertEquals(2L, window.getBase());
|
assertEquals(2L, window.getBase());
|
||||||
assertEquals(Arrays.asList((long) REORDERING_WINDOW_SIZE,
|
assertEquals(asList((long) REORDERING_WINDOW_SIZE,
|
||||||
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
|
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
|
||||||
assertEquals(Arrays.asList(0L, aboveMidpoint), change.getRemoved());
|
assertEquals(asList(0L, aboveMidpoint), change.getRemoved());
|
||||||
// The second-highest element below the midpoint should be seen
|
// The second-highest element below the midpoint should be seen
|
||||||
bitmap[bitmap.length / 2 - 1] = (byte) 0x02; // 0000 0010
|
bitmap[bitmap.length / 2 - 1] = (byte) 0x02; // 0000 0010
|
||||||
assertArrayEquals(bitmap, window.getBitmap());
|
assertArrayEquals(bitmap, window.getBitmap());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.EOFException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
@@ -47,7 +48,7 @@ class TestStreamDecrypter implements StreamDecrypter {
|
|||||||
if (read == -1) throw new EOFException();
|
if (read == -1) throw new EOFException();
|
||||||
offset += read;
|
offset += read;
|
||||||
}
|
}
|
||||||
System.arraycopy(frame, FRAME_HEADER_LENGTH, payload, 0, payloadLength);
|
arraycopy(frame, FRAME_HEADER_LENGTH, payload, 0, payloadLength);
|
||||||
return payloadLength;
|
return payloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import com.sun.jna.win32.W32APITypeMapper;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -26,6 +25,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||||||
|
|
||||||
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
||||||
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
|
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
|
||||||
|
import static java.util.Collections.unmodifiableMap;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
@@ -51,7 +51,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
Map<String, Object> m = new HashMap<>();
|
Map<String, Object> m = new HashMap<>();
|
||||||
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||||
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||||
options = Collections.unmodifiableMap(m);
|
options = unmodifiableMap(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import javax.annotation.Nullable;
|
|||||||
import jssc.SerialPortEvent;
|
import jssc.SerialPortEvent;
|
||||||
import jssc.SerialPortEventListener;
|
import jssc.SerialPortEventListener;
|
||||||
|
|
||||||
|
import static java.lang.System.arraycopy;
|
||||||
import static java.nio.charset.CodingErrorAction.IGNORE;
|
import static java.nio.charset.CodingErrorAction.IGNORE;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
@@ -375,7 +376,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
int off = i + 1;
|
int off = i + 1;
|
||||||
if (off < b.length) {
|
if (off < b.length) {
|
||||||
byte[] data = new byte[b.length - off];
|
byte[] data = new byte[b.length - off];
|
||||||
System.arraycopy(b, off, data, 0, data.length);
|
arraycopy(b, off, data, 0, data.length);
|
||||||
handleData(data);
|
handleData(data);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import java.security.cert.CertificateFactory;
|
|||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -46,6 +45,9 @@ import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
|
|||||||
import static android.content.pm.PackageManager.GET_PERMISSIONS;
|
import static android.content.pm.PackageManager.GET_PERMISSIONS;
|
||||||
import static android.content.pm.PackageManager.GET_SIGNATURES;
|
import static android.content.pm.PackageManager.GET_SIGNATURES;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.util.Collections.emptySet;
|
||||||
|
import static java.util.Collections.sort;
|
||||||
|
import static java.util.Collections.unmodifiableList;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
@@ -105,8 +107,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
|
|||||||
@UiThread
|
@UiThread
|
||||||
public Collection<AppDetails> getApps() {
|
public Collection<AppDetails> getApps() {
|
||||||
if (cachedApps != null) return cachedApps;
|
if (cachedApps != null) return cachedApps;
|
||||||
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
|
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
|
||||||
Collections.emptySet());
|
|
||||||
List<AppDetails> apps = new ArrayList<>();
|
List<AppDetails> apps = new ArrayList<>();
|
||||||
List<PackageInfo> packageInfos =
|
List<PackageInfo> packageInfos =
|
||||||
pm.getInstalledPackages(GET_PERMISSIONS);
|
pm.getInstalledPackages(GET_PERMISSIONS);
|
||||||
@@ -117,8 +118,8 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
|
|||||||
apps.add(new AppDetails(name, packageInfo.packageName));
|
apps.add(new AppDetails(name, packageInfo.packageName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(apps, (a, b) -> a.name.compareTo(b.name));
|
sort(apps, (a, b) -> a.name.compareTo(b.name));
|
||||||
apps = Collections.unmodifiableList(apps);
|
apps = unmodifiableList(apps);
|
||||||
cachedApps = apps;
|
cachedApps = apps;
|
||||||
return apps;
|
return apps;
|
||||||
}
|
}
|
||||||
@@ -127,8 +128,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
|
|||||||
@UiThread
|
@UiThread
|
||||||
public void allowApps(Collection<String> packageNames) {
|
public void allowApps(Collection<String> packageNames) {
|
||||||
cachedApps = null;
|
cachedApps = null;
|
||||||
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
|
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
|
||||||
Collections.emptySet());
|
|
||||||
Set<String> merged = new HashSet<>(allowed);
|
Set<String> merged = new HashSet<>(allowed);
|
||||||
merged.addAll(packageNames);
|
merged.addAll(packageNames);
|
||||||
prefs.edit().putStringSet(PREF_KEY_ALLOWED, merged).apply();
|
prefs.edit().putStringSet(PREF_KEY_ALLOWED, merged).apply();
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import org.briarproject.briar.api.blog.BlogCommentHeader;
|
|||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.Collections.sort;
|
||||||
|
|
||||||
// This class is not thread-safe
|
// This class is not thread-safe
|
||||||
class BlogCommentItem extends BlogPostItem {
|
class BlogCommentItem extends BlogPostItem {
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ class BlogCommentItem extends BlogPostItem {
|
|||||||
BlogCommentItem(BlogCommentHeader header) {
|
BlogCommentItem(BlogCommentHeader header) {
|
||||||
super(header, null);
|
super(header, null);
|
||||||
postHeader = collectComments(header);
|
postHeader = collectComments(header);
|
||||||
Collections.sort(comments, COMPARATOR);
|
sort(comments, COMPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlogPostHeader collectComments(BlogPostHeader header) {
|
private BlogPostHeader collectComments(BlogPostHeader header) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -23,7 +22,6 @@ import org.briarproject.briar.android.logging.BriefLogFormatter;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -41,6 +39,8 @@ import static android.content.Context.WIFI_SERVICE;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.util.Collections.unmodifiableMap;
|
||||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubInetAddress;
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubInetAddress;
|
||||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
@@ -90,7 +90,7 @@ public class BriarReportPrimer implements ReportPrimer {
|
|||||||
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
|
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
|
||||||
am.getMemoryInfo(mem);
|
am.getMemoryInfo(mem);
|
||||||
String systemMemory;
|
String systemMemory;
|
||||||
if (Build.VERSION.SDK_INT >= 16) {
|
if (SDK_INT >= 16) {
|
||||||
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
|
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
|
||||||
+ (mem.availMem / 1024 / 1204) + " MiB free, "
|
+ (mem.availMem / 1024 / 1204) + " MiB free, "
|
||||||
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
|
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
|
||||||
@@ -213,7 +213,7 @@ public class BriarReportPrimer implements ReportPrimer {
|
|||||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||||
// Is Bluetooth LE scanning and advertising supported?
|
// Is Bluetooth LE scanning and advertising supported?
|
||||||
boolean btLeApi = false, btLeScan = false, btLeAdvertise = false;
|
boolean btLeApi = false, btLeScan = false, btLeAdvertise = false;
|
||||||
if (bt != null && Build.VERSION.SDK_INT >= 21) {
|
if (bt != null && SDK_INT >= 21) {
|
||||||
btLeApi = true;
|
btLeApi = true;
|
||||||
btLeScan = bt.getBluetoothLeScanner() != null;
|
btLeScan = bt.getBluetoothLeScanner() != null;
|
||||||
btLeAdvertise = bt.getBluetoothLeAdvertiser() != null;
|
btLeAdvertise = bt.getBluetoothLeAdvertiser() != null;
|
||||||
@@ -255,7 +255,7 @@ public class BriarReportPrimer implements ReportPrimer {
|
|||||||
// Git commit ID
|
// Git commit ID
|
||||||
customData.put("Commit ID", BuildConfig.GitHash);
|
customData.put("Commit ID", BuildConfig.GitHash);
|
||||||
|
|
||||||
return Collections.unmodifiableMap(customData);
|
return unmodifiableMap(customData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import org.briarproject.briar.android.Localizer;
|
|||||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -67,6 +66,7 @@ import static android.provider.Settings.EXTRA_CHANNEL_ID;
|
|||||||
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
|
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||||
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -222,7 +222,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
if (SDK_INT < 27) {
|
if (SDK_INT < 27) {
|
||||||
// remove System Default Theme option
|
// remove System Default Theme option
|
||||||
List<CharSequence> entries =
|
List<CharSequence> entries =
|
||||||
new ArrayList<>(Arrays.asList(theme.getEntries()));
|
new ArrayList<>(asList(theme.getEntries()));
|
||||||
entries.remove(getString(R.string.pref_theme_system));
|
entries.remove(getString(R.string.pref_theme_system));
|
||||||
theme.setEntries(entries.toArray(new CharSequence[0]));
|
theme.setEntries(entries.toArray(new CharSequence[0]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.briar.android.splash;
|
package org.briarproject.briar.android.splash;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
@@ -21,6 +20,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class SplashScreenActivity extends BaseActivity {
|
|||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (SDK_INT >= 21) {
|
||||||
getWindow().setExitTransition(new Fade());
|
getWindow().setExitTransition(new Fade());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ import org.briarproject.briar.api.client.PostHeader;
|
|||||||
import org.briarproject.briar.api.client.ThreadedMessage;
|
import org.briarproject.briar.api.client.ThreadedMessage;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -186,7 +186,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markItemRead(I item) {
|
public void markItemRead(I item) {
|
||||||
markItemsRead(Collections.singletonList(item));
|
markItemsRead(singletonList(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.annotation.TargetApi;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static android.content.Context.WINDOW_SERVICE;
|
import static android.content.Context.WINDOW_SERVICE;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.view.Surface.ROTATION_270;
|
import static android.view.Surface.ROTATION_270;
|
||||||
import static android.view.Surface.ROTATION_90;
|
import static android.view.Surface.ROTATION_90;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
@@ -106,7 +106,7 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewInset == 0 && Build.VERSION.SDK_INT >= 21)
|
if (viewInset == 0 && SDK_INT >= 21)
|
||||||
viewInset = getViewInset();
|
viewInset = getViewInset();
|
||||||
int availableHeight =
|
int availableHeight =
|
||||||
getRootView().getHeight() - statusBarHeight - viewInset;
|
getRootView().getHeight() - statusBarHeight - viewInset;
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ import org.robolectric.Robolectric;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
|
||||||
@@ -91,7 +90,7 @@ public class ForumActivityTest {
|
|||||||
forumItems[i].setLevel(LEVELS[i]);
|
forumItems[i].setLevel(LEVELS[i]);
|
||||||
}
|
}
|
||||||
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();
|
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();
|
||||||
list.addAll(Arrays.asList(forumItems));
|
list.addAll(asList(forumItems));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -50,6 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
|
||||||
@@ -560,8 +560,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||||
GroupId groupId, MessageId id, BdfDictionary meta)
|
GroupId groupId, MessageId id, BdfDictionary meta)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
return getPostHeaderFromMetadata(txn, groupId, id, meta,
|
return getPostHeaderFromMetadata(txn, groupId, id, meta, emptyMap());
|
||||||
Collections.emptyMap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.briarproject.briar.api.client.MessageTree;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,6 +13,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.Collections.sort;
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||||
@@ -47,7 +49,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void add(T node) {
|
public synchronized void add(T node) {
|
||||||
add(Collections.singletonList(node));
|
add(singletonList(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markAsUnsorted(List<T> list) {
|
private void markAsUnsorted(List<T> list) {
|
||||||
@@ -69,7 +71,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
|||||||
|
|
||||||
private void sortUnsorted() {
|
private void sortUnsorted() {
|
||||||
for (List<T> list : unsortedLists) {
|
for (List<T> list : unsortedLists) {
|
||||||
Collections.sort(list, comparator);
|
sort(list, comparator);
|
||||||
}
|
}
|
||||||
unsortedLists.clear();
|
unsortedLists.clear();
|
||||||
}
|
}
|
||||||
@@ -87,9 +89,9 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
|||||||
public synchronized void setComparator(Comparator<T> comparator) {
|
public synchronized void setComparator(Comparator<T> comparator) {
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
// Sort all lists with the new comparator
|
// Sort all lists with the new comparator
|
||||||
Collections.sort(roots, comparator);
|
sort(roots, comparator);
|
||||||
for (Map.Entry<MessageId, List<T>> entry : nodeMap.entrySet()) {
|
for (Map.Entry<MessageId, List<T>> entry : nodeMap.entrySet()) {
|
||||||
Collections.sort(entry.getValue(), comparator);
|
sort(entry.getValue(), comparator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package org.briarproject.briar.feed;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import okhttp3.Dns;
|
import okhttp3.Dns;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
class NoDns implements Dns {
|
class NoDns implements Dns {
|
||||||
|
|
||||||
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
|
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
|
||||||
@@ -22,7 +23,7 @@ class NoDns implements Dns {
|
|||||||
throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
InetAddress unspecified =
|
InetAddress unspecified =
|
||||||
InetAddress.getByAddress(hostname, UNSPECIFIED_ADDRESS);
|
InetAddress.getByAddress(hostname, UNSPECIFIED_ADDRESS);
|
||||||
return Collections.singletonList(unspecified);
|
return singletonList(unspecified);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
|||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,6 +44,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
|
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
|
||||||
@@ -249,7 +249,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
|
|
||||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||||
BdfDictionary meta) throws DbException, FormatException {
|
BdfDictionary meta) throws DbException, FormatException {
|
||||||
return getForumPostHeader(txn, id, meta, Collections.emptyMap());
|
return getForumPostHeader(txn, id, meta, emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
|
||||||
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
@@ -84,8 +83,7 @@ class IntroductionValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +116,7 @@ class IntroductionValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +141,7 @@ class IntroductionValidator extends BdfMessageValidator {
|
|||||||
.encodeMetadata(AUTH, sessionId, m.getTimestamp(), false, false,
|
.encodeMetadata(AUTH, sessionId, m.getTimestamp(), false, false,
|
||||||
false);
|
false);
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BdfMessageContext validateActivateMessage(Message m, BdfList body)
|
private BdfMessageContext validateActivateMessage(Message m, BdfList body)
|
||||||
@@ -169,8 +165,7 @@ class IntroductionValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,8 +187,7 @@ class IntroductionValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,6 +53,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
|
||||||
@@ -574,7 +574,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
BdfDictionary meta, boolean local)
|
BdfDictionary meta, boolean local)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
||||||
m.getId(), meta, Collections.emptyMap());
|
m.getId(), meta, emptyMap());
|
||||||
String text = getMessageText(clientHelper.toList(m));
|
String text = getMessageText(clientHelper.toList(m));
|
||||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
|
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
|
||||||
local));
|
local));
|
||||||
@@ -584,7 +584,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
BdfDictionary meta, boolean local, Visibility v)
|
BdfDictionary meta, boolean local, Visibility v)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
||||||
m.getId(), meta, Collections.emptyMap(), v);
|
m.getId(), meta, emptyMap(), v);
|
||||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
||||||
local));
|
local));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ import org.briarproject.briar.api.privategroup.PrivateGroup;
|
|||||||
import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||||
@@ -120,8 +120,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,8 +138,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.sync.Message;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||||
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
|
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
|
||||||
@@ -70,8 +69,7 @@ abstract class SharingValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +91,7 @@ abstract class SharingValidator extends BdfMessageValidator {
|
|||||||
return new BdfMessageContext(meta);
|
return new BdfMessageContext(meta);
|
||||||
} else {
|
} else {
|
||||||
MessageId dependency = new MessageId(previousMessageId);
|
MessageId dependency = new MessageId(previousMessageId);
|
||||||
return new BdfMessageContext(meta,
|
return new BdfMessageContext(meta, singletonList(dependency));
|
||||||
Collections.singletonList(dependency));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.briar.api.client.MessageTree;
|
import org.briarproject.briar.api.client.MessageTree;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Arrays.copyOf;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ public class MessageTreeImplTest {
|
|||||||
nodes[3].setTimestamp(timestamp - 2);
|
nodes[3].setTimestamp(timestamp - 2);
|
||||||
nodes[2].setTimestamp(timestamp - 1);
|
nodes[2].setTimestamp(timestamp - 1);
|
||||||
// add all nodes except the last one
|
// add all nodes except the last one
|
||||||
tree.add(Arrays.asList(Arrays.copyOf(nodes, nodes.length - 1)));
|
tree.add(asList(copyOf(nodes, nodes.length - 1)));
|
||||||
tree.add(Collections.singletonList(nodes[nodes.length - 1]));
|
tree.add(singletonList(nodes[nodes.length - 1]));
|
||||||
TestNode[] sortedNodes =
|
TestNode[] sortedNodes =
|
||||||
tree.depthFirstOrder().toArray(new TestNode[5]);
|
tree.depthFirstOrder().toArray(new TestNode[5]);
|
||||||
assertEquals(nodes[4], sortedNodes[0]);
|
assertEquals(nodes[4], sortedNodes[0]);
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ import org.jmock.Expectations;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
@@ -178,7 +179,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, JOIN, creatorList,
|
assertExpectedMessageContext(messageContext, JOIN, creatorList,
|
||||||
Collections.emptyList());
|
emptyList());
|
||||||
assertTrue(messageContext.getDictionary()
|
assertTrue(messageContext.getDictionary()
|
||||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||||
}
|
}
|
||||||
@@ -363,7 +364,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, JOIN, memberList,
|
assertExpectedMessageContext(messageContext, JOIN, memberList,
|
||||||
Collections.emptyList());
|
emptyList());
|
||||||
assertFalse(messageContext.getDictionary()
|
assertFalse(messageContext.getDictionary()
|
||||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||||
}
|
}
|
||||||
@@ -606,7 +607,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, POST, memberList,
|
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||||
Arrays.asList(parentId, previousMsgId));
|
asList(parentId, previousMsgId));
|
||||||
assertArrayEquals(previousMsgId.getBytes(),
|
assertArrayEquals(previousMsgId.getBytes(),
|
||||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||||
assertArrayEquals(parentId.getBytes(),
|
assertArrayEquals(parentId.getBytes(),
|
||||||
@@ -621,7 +622,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
|||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, body);
|
validator.validateMessage(message, group, body);
|
||||||
assertExpectedMessageContext(messageContext, POST, memberList,
|
assertExpectedMessageContext(messageContext, POST, memberList,
|
||||||
Collections.singletonList(previousMsgId));
|
singletonList(previousMsgId));
|
||||||
assertArrayEquals(previousMsgId.getBytes(),
|
assertArrayEquals(previousMsgId.getBytes(),
|
||||||
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
|
||||||
assertFalse(
|
assertFalse(
|
||||||
|
|||||||
@@ -35,14 +35,16 @@ import org.jmock.Expectations;
|
|||||||
import org.jmock.lib.legacy.ClassImposteriser;
|
import org.jmock.lib.legacy.ClassImposteriser;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static junit.framework.TestCase.fail;
|
import static junit.framework.TestCase.fail;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
@@ -112,9 +114,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final BdfDictionary bdfSession =
|
private final BdfDictionary bdfSession =
|
||||||
BdfDictionary.of(new BdfEntry("f", "o"));
|
BdfDictionary.of(new BdfEntry("f", "o"));
|
||||||
private final Map<MessageId, BdfDictionary> oneResult =
|
private final Map<MessageId, BdfDictionary> oneResult =
|
||||||
Collections.singletonMap(storageMessage.getId(), bdfSession);
|
singletonMap(storageMessage.getId(), bdfSession);
|
||||||
private final Map<MessageId, BdfDictionary> noResults =
|
private final Map<MessageId, BdfDictionary> noResults = emptyMap();
|
||||||
Collections.emptyMap();
|
|
||||||
|
|
||||||
|
|
||||||
public GroupInvitationManagerImplTest() {
|
public GroupInvitationManagerImplTest() {
|
||||||
@@ -156,7 +157,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(db).addGroup(txn, localGroup);
|
oneOf(db).addGroup(txn, localGroup);
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(singletonList(contact)));
|
||||||
}});
|
}});
|
||||||
expectAddingContact(contact);
|
expectAddingContact(contact);
|
||||||
groupInvitationManager.createLocalState(txn);
|
groupInvitationManager.createLocalState(txn);
|
||||||
@@ -192,7 +193,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
.mergeGroupMetadata(txn, contactGroup.getId(), meta);
|
.mergeGroupMetadata(txn, contactGroup.getId(), meta);
|
||||||
oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID,
|
oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID,
|
||||||
PrivateGroupManager.MAJOR_VERSION);
|
PrivateGroupManager.MAJOR_VERSION);
|
||||||
will(returnValue(Collections.singletonList(privateGroup)));
|
will(returnValue(singletonList(privateGroup)));
|
||||||
oneOf(privateGroupManager).isMember(txn, privateGroup.getId(),
|
oneOf(privateGroupManager).isMember(txn, privateGroup.getId(),
|
||||||
c.getAuthor());
|
c.getAuthor());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
@@ -743,7 +744,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).startTransaction(true);
|
oneOf(db).startTransaction(true);
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(singletonList(contact)));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact);
|
MAJOR_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
@@ -836,7 +837,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
expectAddingMember(privateGroup.getId(), contact);
|
expectAddingMember(privateGroup.getId(), contact);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContactsByAuthorId(txn, author.getId());
|
oneOf(db).getContactsByAuthorId(txn, author.getId());
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(singletonList(contact)));
|
||||||
}});
|
}});
|
||||||
groupInvitationManager.addingMember(txn, privateGroup.getId(), author);
|
groupInvitationManager.addingMember(txn, privateGroup.getId(), author);
|
||||||
}
|
}
|
||||||
@@ -847,8 +848,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
author.getId(), getRandomString(5), true, true);
|
author.getId(), getRandomString(5), true, true);
|
||||||
Contact contact3 = new Contact(new ContactId(3), author,
|
Contact contact3 = new Contact(new ContactId(3), author,
|
||||||
author.getId(), getRandomString(5), true, true);
|
author.getId(), getRandomString(5), true, true);
|
||||||
Collection<Contact> contacts =
|
Collection<Contact> contacts = asList(contact, contact2, contact3);
|
||||||
Arrays.asList(contact, contact2, contact3);
|
|
||||||
|
|
||||||
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
@@ -861,9 +861,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
BdfDictionary.of(new BdfEntry("f3", "o"));
|
BdfDictionary.of(new BdfEntry("f3", "o"));
|
||||||
|
|
||||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||||
expectGetSession(Collections.singletonMap(storageId2, bdfSession2),
|
expectGetSession(singletonMap(storageId2, bdfSession2),
|
||||||
sessionId, contactGroup2.getId());
|
sessionId, contactGroup2.getId());
|
||||||
expectGetSession(Collections.singletonMap(storageId3, bdfSession3),
|
expectGetSession(singletonMap(storageId3, bdfSession3),
|
||||||
sessionId, contactGroup3.getId());
|
sessionId, contactGroup3.getId());
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import org.briarproject.briar.api.privategroup.GroupMessage;
|
|||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||||
@@ -753,7 +753,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
|||||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
||||||
BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
||||||
Map<MessageId, BdfDictionary> invites =
|
Map<MessageId, BdfDictionary> invites =
|
||||||
Collections.singletonMap(lastRemoteMessageId, meta);
|
singletonMap(lastRemoteMessageId, meta);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(messageParser)
|
oneOf(messageParser)
|
||||||
.getInvitesAvailableToAnswerQuery(privateGroupId);
|
.getInvitesAvailableToAnswerQuery(privateGroupId);
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ import org.jmock.Expectations;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
@@ -66,8 +67,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final Contact contact =
|
private final Contact contact =
|
||||||
new Contact(contactId, author, localAuthor.getId(),
|
new Contact(contactId, author, localAuthor.getId(),
|
||||||
getRandomString(5), true, true);
|
getRandomString(5), true, true);
|
||||||
private final Collection<Contact> contacts =
|
private final Collection<Contact> contacts = singletonList(contact);
|
||||||
Collections.singletonList(contact);
|
|
||||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
private final Group blogGroup =
|
private final Group blogGroup =
|
||||||
@@ -120,7 +120,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
|||||||
private void expectAddingContact(Transaction txn) throws Exception {
|
private void expectAddingContact(Transaction txn) throws Exception {
|
||||||
BdfDictionary meta = BdfDictionary.of(
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||||
Map<MessageId, BdfDictionary> sessions = Collections.emptyMap();
|
Map<MessageId, BdfDictionary> sessions = emptyMap();
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Create the contact group and share it with the contact
|
// Create the contact group and share it with the contact
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.briarproject.briar.headless.contact.ContactController
|
|||||||
import org.briarproject.briar.headless.event.WebSocketController
|
import org.briarproject.briar.headless.event.WebSocketController
|
||||||
import org.briarproject.briar.headless.forums.ForumController
|
import org.briarproject.briar.headless.forums.ForumController
|
||||||
import org.briarproject.briar.headless.messaging.MessagingController
|
import org.briarproject.briar.headless.messaging.MessagingController
|
||||||
|
import java.lang.Integer.parseInt
|
||||||
import java.lang.Runtime.getRuntime
|
import java.lang.Runtime.getRuntime
|
||||||
import java.lang.System.exit
|
import java.lang.System.exit
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
@@ -128,7 +129,7 @@ constructor(
|
|||||||
fun Context.getContactIdFromPathParam(): ContactId {
|
fun Context.getContactIdFromPathParam(): ContactId {
|
||||||
val contactString = pathParam("contactId")
|
val contactString = pathParam("contactId")
|
||||||
val contactInt = try {
|
val contactInt = try {
|
||||||
Integer.parseInt(contactString)
|
parseInt(contactString)
|
||||||
} catch (e: NumberFormatException) {
|
} catch (e: NumberFormatException) {
|
||||||
throw NotFoundResponse()
|
throw NotFoundResponse()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user