mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Use a hashset instead of list to avoid duplicates. Filter out my own node from persisted peers.
Remove log in DisputeAgentManager which gets called repeatedly
This commit is contained in:
parent
cfda0aff68
commit
351db88992
@ -214,8 +214,6 @@ public abstract class DisputeAgentManager<T extends DisputeAgent> {
|
||||
|
||||
observableMap.putAll(filtered);
|
||||
observableMap.values().forEach(this::addAcceptedDisputeAgentToUser);
|
||||
|
||||
log.info("Available disputeAgents: {}", observableMap.keySet());
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,7 +186,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
||||
public void readPersisted() {
|
||||
PeerList persisted = persistenceManager.getPersisted();
|
||||
if (persisted != null) {
|
||||
peerList.setAll(persisted.getList());
|
||||
peerList.setAll(persisted.getSet());
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
||||
}
|
||||
|
||||
public Collection<Peer> getPersistedPeers() {
|
||||
return peerList.getList();
|
||||
return peerList.getSet();
|
||||
}
|
||||
|
||||
public void addToReportedPeers(Set<Peer> reportedPeersToAdd,
|
||||
@ -329,6 +329,10 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
||||
Capabilities capabilities) {
|
||||
applyCapabilities(connection, capabilities);
|
||||
|
||||
reportedPeersToAdd = reportedPeersToAdd.stream()
|
||||
.filter(peer -> !isSelf(peer.getNodeAddress()))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
printNewReportedPeers(reportedPeersToAdd);
|
||||
|
||||
// We check if the reported msg is not violating our rules
|
||||
|
@ -21,46 +21,55 @@ import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@EqualsAndHashCode
|
||||
public class PeerList implements PersistableEnvelope {
|
||||
@Getter
|
||||
private final List<Peer> list = new ArrayList<>();
|
||||
private final Set<Peer> set = new HashSet<>();
|
||||
|
||||
public PeerList() {
|
||||
}
|
||||
|
||||
public PeerList(List<Peer> list) {
|
||||
setAll(list);
|
||||
public PeerList(Set<Peer> set) {
|
||||
setAll(set);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return list.size();
|
||||
return set.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
return protobuf.PersistableEnvelope.newBuilder()
|
||||
.setPeerList(protobuf.PeerList.newBuilder()
|
||||
.addAllPeer(list.stream().map(Peer::toProtoMessage).collect(Collectors.toList())))
|
||||
.addAllPeer(set.stream().map(Peer::toProtoMessage).collect(Collectors.toList())))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static PeerList fromProto(protobuf.PeerList proto) {
|
||||
return new PeerList(new ArrayList<>(proto.getPeerList().stream()
|
||||
return new PeerList(proto.getPeerList().stream()
|
||||
.map(Peer::fromProto)
|
||||
.collect(Collectors.toList())));
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public void setAll(Collection<Peer> collection) {
|
||||
this.list.clear();
|
||||
this.list.addAll(collection);
|
||||
this.set.clear();
|
||||
this.set.addAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PeerList{" +
|
||||
"\n set=" + set +
|
||||
"\n}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user