mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-11-17 00:07:49 +00:00
synchronize peer manager's reported peers to fix concurrency error
This commit is contained in:
parent
5d88936600
commit
9a6a9ac93e
1 changed files with 39 additions and 30 deletions
|
@ -365,6 +365,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
|
||||
// We check if the reported msg is not violating our rules
|
||||
if (peers.size() <= (MAX_REPORTED_PEERS + maxConnectionsAbsolute + 10)) {
|
||||
synchronized (reportedPeers) {
|
||||
reportedPeers.addAll(peers);
|
||||
purgeReportedPeersIfExceeds();
|
||||
|
||||
|
@ -373,6 +374,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
requestPersistence();
|
||||
|
||||
printReportedPeers();
|
||||
}
|
||||
} else {
|
||||
// If a node is trying to send too many list we treat it as rule violation.
|
||||
// Reported list include the connected list. We use the max value and give some extra headroom.
|
||||
|
@ -589,10 +591,13 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void removeReportedPeer(Peer reportedPeer) {
|
||||
synchronized (reportedPeers) {
|
||||
reportedPeers.remove(reportedPeer);
|
||||
printReportedPeers();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void removeReportedPeer(NodeAddress nodeAddress) {
|
||||
List<Peer> reportedPeersClone = new ArrayList<>(reportedPeers);
|
||||
reportedPeersClone.stream()
|
||||
|
@ -611,6 +616,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
|
||||
|
||||
private void purgeReportedPeersIfExceeds() {
|
||||
synchronized (reportedPeers) {
|
||||
int size = reportedPeers.size();
|
||||
if (size > MAX_REPORTED_PEERS) {
|
||||
log.info("We have already {} reported peers which exceeds our limit of {}." +
|
||||
|
@ -628,8 +634,10 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
log.trace("No need to purge reported peers.\n\tWe don't have more then {} reported peers yet.", MAX_REPORTED_PEERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printReportedPeers() {
|
||||
synchronized (reportedPeers) {
|
||||
if (!reportedPeers.isEmpty()) {
|
||||
if (PRINT_REPORTED_PEERS_DETAILS) {
|
||||
StringBuilder result = new StringBuilder("\n\n------------------------------------------------------------\n" +
|
||||
|
@ -642,6 +650,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||
log.debug("Number of reported peers: {}", reportedPeers.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printNewReportedPeers(Set<Peer> reportedPeers) {
|
||||
if (PRINT_REPORTED_PEERS_DETAILS) {
|
||||
|
|
Loading…
Reference in a new issue