mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Poll contacts in series rather than parallel.
This commit is contained in:
@@ -26,7 +26,10 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -252,28 +255,35 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void poll(Collection<ContactId> connected) {
|
public void poll(Collection<ContactId> connected) {
|
||||||
if (!isRunning() || !shouldAllowContactConnections()) return;
|
if (!isRunning() || !shouldAllowContactConnections()) return;
|
||||||
backoff.increment();
|
// Try to connect to known devices in a random order
|
||||||
// Try to connect to known devices in parallel
|
|
||||||
Map<ContactId, TransportProperties> remote =
|
Map<ContactId, TransportProperties> remote =
|
||||||
callback.getRemoteProperties();
|
callback.getRemoteProperties();
|
||||||
|
List<Entry<ContactId, TransportProperties>> entries = new ArrayList<>();
|
||||||
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||||
ContactId c = e.getKey();
|
if (connected.contains(e.getKey())) continue;
|
||||||
if (connected.contains(c)) continue;
|
TransportProperties p = e.getValue();
|
||||||
String address = e.getValue().get(PROP_ADDRESS);
|
if (StringUtils.isNullOrEmpty(p.get(PROP_ADDRESS))) continue;
|
||||||
if (StringUtils.isNullOrEmpty(address)) continue;
|
if (StringUtils.isNullOrEmpty(p.get(PROP_UUID))) continue;
|
||||||
String uuid = e.getValue().get(PROP_UUID);
|
entries.add(e);
|
||||||
if (StringUtils.isNullOrEmpty(uuid)) continue;
|
}
|
||||||
ioExecutor.execute(() -> {
|
if (entries.isEmpty()) return;
|
||||||
|
Collections.shuffle(entries);
|
||||||
|
backoff.increment();
|
||||||
|
ioExecutor.execute(() -> {
|
||||||
|
for (Entry<ContactId, TransportProperties> e : entries) {
|
||||||
if (!isRunning() || !shouldAllowContactConnections()) return;
|
if (!isRunning() || !shouldAllowContactConnections()) return;
|
||||||
if (!connectionLimiter.canOpenContactConnection()) return;
|
if (!connectionLimiter.canOpenContactConnection()) return;
|
||||||
|
TransportProperties p = e.getValue();
|
||||||
|
String address = p.get(PROP_ADDRESS);
|
||||||
|
String uuid = p.get(PROP_UUID);
|
||||||
DuplexTransportConnection conn = connect(address, uuid);
|
DuplexTransportConnection conn = connect(address, uuid);
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
backoff.reset();
|
backoff.reset();
|
||||||
if (connectionLimiter.contactConnectionOpened(conn))
|
if (connectionLimiter.contactConnectionOpened(conn))
|
||||||
callback.outgoingConnectionCreated(c, conn);
|
callback.outgoingConnectionCreated(e.getKey(), conn);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
Reference in New Issue
Block a user