Add check for empty list

This commit is contained in:
Manfred Karrer 2017-12-04 17:23:57 -05:00
parent 0aaab849eb
commit ddd857a7f9
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
2 changed files with 73 additions and 61 deletions

View File

@ -67,6 +67,14 @@ public class CoreSeedNodesRepository implements SeedNodesRepository {
new NodeAddress("s67qglwhkgkyvr74.onion:8000"), // @emzy
new NodeAddress("jhgcy2won7xnslrb.onion:8000"), // @sqrrm
/* old nodes pre 0.6.0 (still running for 0.5.* versions
new NodeAddress("3f3cu2yw7u457ztq.onion:8000"),
new NodeAddress("723ljisnynbtdohi.onion:8000"),
new NodeAddress("rm7b56wbrcczpjvl.onion:8000"),
new NodeAddress("fl3mmribyxgrv63c.onion:8000"),
*/
//TODO dev
// local dev
// new NodeAddress("joehwtpe7ijnz4df.onion:8000"),

View File

@ -422,9 +422,11 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
List<Peer> list = new ArrayList<>(reportedPeers);
// we dont use sorting by lastActivityDate to keep it more random
for (int i = 0; i < diff; i++) {
if (!list.isEmpty()) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removeReportedPeer(toRemove);
}
}
} else {
log.trace("No need to purge reported peers.\n\tWe don't have more then {} reported peers yet.", MAX_REPORTED_PEERS);
}
@ -501,9 +503,11 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
List<Peer> list = new ArrayList<>(persistedPeers);
// we dont use sorting by lastActivityDate to avoid attack vectors and keep it more random
for (int i = 0; i < diff; i++) {
if (!list.isEmpty()) {
Peer toRemove = list.remove(new Random().nextInt(list.size()));
removePersistedPeer(toRemove);
}
}
} else {
log.trace("No need to purge persisted peers.\n\tWe don't have more then {} persisted peers yet.", MAX_PERSISTED_PEERS);
}