mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +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.putAll(filtered);
|
||||||
observableMap.values().forEach(this::addAcceptedDisputeAgentToUser);
|
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() {
|
public void readPersisted() {
|
||||||
PeerList persisted = persistenceManager.getPersisted();
|
PeerList persisted = persistenceManager.getPersisted();
|
||||||
if (persisted != null) {
|
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() {
|
public Collection<Peer> getPersistedPeers() {
|
||||||
return peerList.getList();
|
return peerList.getSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToReportedPeers(Set<Peer> reportedPeersToAdd,
|
public void addToReportedPeers(Set<Peer> reportedPeersToAdd,
|
||||||
@ -329,6 +329,10 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
|
|||||||
Capabilities capabilities) {
|
Capabilities capabilities) {
|
||||||
applyCapabilities(connection, capabilities);
|
applyCapabilities(connection, capabilities);
|
||||||
|
|
||||||
|
reportedPeersToAdd = reportedPeersToAdd.stream()
|
||||||
|
.filter(peer -> !isSelf(peer.getNodeAddress()))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
printNewReportedPeers(reportedPeersToAdd);
|
printNewReportedPeers(reportedPeersToAdd);
|
||||||
|
|
||||||
// We check if the reported msg is not violating our rules
|
// 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 com.google.protobuf.Message;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public class PeerList implements PersistableEnvelope {
|
public class PeerList implements PersistableEnvelope {
|
||||||
@Getter
|
@Getter
|
||||||
private final List<Peer> list = new ArrayList<>();
|
private final Set<Peer> set = new HashSet<>();
|
||||||
|
|
||||||
public PeerList() {
|
public PeerList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PeerList(List<Peer> list) {
|
public PeerList(Set<Peer> set) {
|
||||||
setAll(list);
|
setAll(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return list.size();
|
return set.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message toProtoMessage() {
|
public Message toProtoMessage() {
|
||||||
return protobuf.PersistableEnvelope.newBuilder()
|
return protobuf.PersistableEnvelope.newBuilder()
|
||||||
.setPeerList(protobuf.PeerList.newBuilder()
|
.setPeerList(protobuf.PeerList.newBuilder()
|
||||||
.addAllPeer(list.stream().map(Peer::toProtoMessage).collect(Collectors.toList())))
|
.addAllPeer(set.stream().map(Peer::toProtoMessage).collect(Collectors.toList())))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PeerList fromProto(protobuf.PeerList proto) {
|
public static PeerList fromProto(protobuf.PeerList proto) {
|
||||||
return new PeerList(new ArrayList<>(proto.getPeerList().stream()
|
return new PeerList(proto.getPeerList().stream()
|
||||||
.map(Peer::fromProto)
|
.map(Peer::fromProto)
|
||||||
.collect(Collectors.toList())));
|
.collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAll(Collection<Peer> collection) {
|
public void setAll(Collection<Peer> collection) {
|
||||||
this.list.clear();
|
this.set.clear();
|
||||||
this.list.addAll(collection);
|
this.set.addAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PeerList{" +
|
||||||
|
"\n set=" + set +
|
||||||
|
"\n}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user