Skip to content

Commit

Permalink
Merge pull request #7100 from stejbac/fix-ignored-mailbox-map-data-race
Browse files Browse the repository at this point in the history
Fix data race in `IgnoredMailboxMap`
  • Loading branch information
alejandrogarcia83 authored May 9, 2024
2 parents b89bb3d + 23f871a commit 3b428df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 6 additions & 12 deletions p2p/src/main/java/bisq/network/p2p/mailbox/IgnoredMailboxMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

package bisq.network.p2p.mailbox;


import bisq.common.proto.persistable.PersistableEnvelope;
import bisq.common.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -32,17 +30,17 @@
@EqualsAndHashCode
public class IgnoredMailboxMap implements PersistableEnvelope {
@Getter
private final Map<String, Long> dataMap;
private final ConcurrentMap<String, Long> dataMap;

public IgnoredMailboxMap() {
this.dataMap = new HashMap<>();
this.dataMap = new ConcurrentHashMap<>();
}

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

public IgnoredMailboxMap(Map<String, Long> ignored) {
private IgnoredMailboxMap(ConcurrentMap<String, Long> ignored) {
this.dataMap = ignored;
}

Expand All @@ -54,11 +52,7 @@ public protobuf.PersistableEnvelope toProtoMessage() {
}

public static IgnoredMailboxMap fromProto(protobuf.IgnoredMailboxMap proto) {
return new IgnoredMailboxMap(CollectionUtils.isEmpty(proto.getDataMap()) ? new HashMap<>() : proto.getDataMap());
}

public void putAll(Map<String, Long> map) {
dataMap.putAll(map);
return new IgnoredMailboxMap(new ConcurrentHashMap<>(proto.getDataMap()));
}

public boolean containsKey(String uid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import com.google.common.base.Joiner;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;

Expand Down

0 comments on commit 3b428df

Please sign in to comment.