all: switch out defunct set library to different one (#16873)

* keystore, ethash, eth, miner, rpc, whisperv6: tech debt with now defunct set.

* whisperv5: swap out gopkg.in/fatih/set.v0 with supported set
This commit is contained in:
Ralph Caraveo III 2018-07-16 00:54:19 -07:00 committed by Péter Szilágyi
parent 6d0071d84c
commit 9f139cbd6b
5 changed files with 20 additions and 20 deletions

View File

@ -20,11 +20,11 @@ import (
"fmt" "fmt"
"time" "time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
set "gopkg.in/fatih/set.v0"
) )
// Peer represents a whisper protocol peer connection. // Peer represents a whisper protocol peer connection.
@ -34,7 +34,7 @@ type Peer struct {
ws p2p.MsgReadWriter ws p2p.MsgReadWriter
trusted bool trusted bool
known *set.Set // Messages already known by the peer to avoid wasting bandwidth known mapset.Set // Messages already known by the peer to avoid wasting bandwidth
quit chan struct{} quit chan struct{}
} }
@ -46,7 +46,7 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
peer: remote, peer: remote,
ws: rw, ws: rw,
trusted: false, trusted: false,
known: set.New(), known: mapset.NewSet(),
quit: make(chan struct{}), quit: make(chan struct{}),
} }
} }
@ -127,7 +127,7 @@ func (peer *Peer) mark(envelope *Envelope) {
// marked checks if an envelope is already known to the remote peer. // marked checks if an envelope is already known to the remote peer.
func (peer *Peer) marked(envelope *Envelope) bool { func (peer *Peer) marked(envelope *Envelope) bool {
return peer.known.Has(envelope.Hash()) return peer.known.Contains(envelope.Hash())
} }
// expire iterates over all the known envelopes in the host and removes all // expire iterates over all the known envelopes in the host and removes all

View File

@ -26,6 +26,7 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -34,7 +35,6 @@ import (
"github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/errors"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/sync/syncmap" "golang.org/x/sync/syncmap"
set "gopkg.in/fatih/set.v0"
) )
type Statistics struct { type Statistics struct {
@ -63,7 +63,7 @@ type Whisper struct {
poolMu sync.RWMutex // Mutex to sync the message and expiration pools poolMu sync.RWMutex // Mutex to sync the message and expiration pools
envelopes map[common.Hash]*Envelope // Pool of envelopes currently tracked by this node envelopes map[common.Hash]*Envelope // Pool of envelopes currently tracked by this node
expirations map[uint32]*set.SetNonTS // Message expiration pool expirations map[uint32]mapset.Set // Message expiration pool
peerMu sync.RWMutex // Mutex to sync the active peer set peerMu sync.RWMutex // Mutex to sync the active peer set
peers map[*Peer]struct{} // Set of currently active peers peers map[*Peer]struct{} // Set of currently active peers
@ -90,7 +90,7 @@ func New(cfg *Config) *Whisper {
privateKeys: make(map[string]*ecdsa.PrivateKey), privateKeys: make(map[string]*ecdsa.PrivateKey),
symKeys: make(map[string][]byte), symKeys: make(map[string][]byte),
envelopes: make(map[common.Hash]*Envelope), envelopes: make(map[common.Hash]*Envelope),
expirations: make(map[uint32]*set.SetNonTS), expirations: make(map[uint32]mapset.Set),
peers: make(map[*Peer]struct{}), peers: make(map[*Peer]struct{}),
messageQueue: make(chan *Envelope, messageQueueLimit), messageQueue: make(chan *Envelope, messageQueueLimit),
p2pMsgQueue: make(chan *Envelope, messageQueueLimit), p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
@ -608,9 +608,9 @@ func (w *Whisper) add(envelope *Envelope) (bool, error) {
if !alreadyCached { if !alreadyCached {
w.envelopes[hash] = envelope w.envelopes[hash] = envelope
if w.expirations[envelope.Expiry] == nil { if w.expirations[envelope.Expiry] == nil {
w.expirations[envelope.Expiry] = set.NewNonTS() w.expirations[envelope.Expiry] = mapset.NewThreadUnsafeSet()
} }
if !w.expirations[envelope.Expiry].Has(hash) { if !w.expirations[envelope.Expiry].Contains(hash) {
w.expirations[envelope.Expiry].Add(hash) w.expirations[envelope.Expiry].Add(hash)
} }
} }

View File

@ -22,8 +22,8 @@ import (
"testing" "testing"
"time" "time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
set "gopkg.in/fatih/set.v0"
) )
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) { func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
@ -31,7 +31,7 @@ func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
privateKeys: make(map[string]*ecdsa.PrivateKey), privateKeys: make(map[string]*ecdsa.PrivateKey),
symKeys: make(map[string][]byte), symKeys: make(map[string][]byte),
envelopes: make(map[common.Hash]*Envelope), envelopes: make(map[common.Hash]*Envelope),
expirations: make(map[uint32]*set.SetNonTS), expirations: make(map[uint32]mapset.Set),
peers: make(map[*Peer]struct{}), peers: make(map[*Peer]struct{}),
messageQueue: make(chan *Envelope, messageQueueLimit), messageQueue: make(chan *Envelope, messageQueueLimit),
p2pMsgQueue: make(chan *Envelope, messageQueueLimit), p2pMsgQueue: make(chan *Envelope, messageQueueLimit),

View File

@ -22,11 +22,11 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
set "gopkg.in/fatih/set.v0"
) )
// Peer represents a whisper protocol peer connection. // Peer represents a whisper protocol peer connection.
@ -41,7 +41,7 @@ type Peer struct {
bloomFilter []byte bloomFilter []byte
fullNode bool fullNode bool
known *set.Set // Messages already known by the peer to avoid wasting bandwidth known mapset.Set // Messages already known by the peer to avoid wasting bandwidth
quit chan struct{} quit chan struct{}
} }
@ -54,7 +54,7 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
ws: rw, ws: rw,
trusted: false, trusted: false,
powRequirement: 0.0, powRequirement: 0.0,
known: set.New(), known: mapset.NewSet(),
quit: make(chan struct{}), quit: make(chan struct{}),
bloomFilter: MakeFullNodeBloom(), bloomFilter: MakeFullNodeBloom(),
fullNode: true, fullNode: true,
@ -165,7 +165,7 @@ func (peer *Peer) mark(envelope *Envelope) {
// marked checks if an envelope is already known to the remote peer. // marked checks if an envelope is already known to the remote peer.
func (peer *Peer) marked(envelope *Envelope) bool { func (peer *Peer) marked(envelope *Envelope) bool {
return peer.known.Has(envelope.Hash()) return peer.known.Contains(envelope.Hash())
} }
// expire iterates over all the known envelopes in the host and removes all // expire iterates over all the known envelopes in the host and removes all

View File

@ -26,6 +26,7 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -35,7 +36,6 @@ import (
"github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/errors"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/sync/syncmap" "golang.org/x/sync/syncmap"
set "gopkg.in/fatih/set.v0"
) )
// Statistics holds several message-related counter for analytics // Statistics holds several message-related counter for analytics
@ -69,7 +69,7 @@ type Whisper struct {
poolMu sync.RWMutex // Mutex to sync the message and expiration pools poolMu sync.RWMutex // Mutex to sync the message and expiration pools
envelopes map[common.Hash]*Envelope // Pool of envelopes currently tracked by this node envelopes map[common.Hash]*Envelope // Pool of envelopes currently tracked by this node
expirations map[uint32]*set.SetNonTS // Message expiration pool expirations map[uint32]mapset.Set // Message expiration pool
peerMu sync.RWMutex // Mutex to sync the active peer set peerMu sync.RWMutex // Mutex to sync the active peer set
peers map[*Peer]struct{} // Set of currently active peers peers map[*Peer]struct{} // Set of currently active peers
@ -100,7 +100,7 @@ func New(cfg *Config) *Whisper {
privateKeys: make(map[string]*ecdsa.PrivateKey), privateKeys: make(map[string]*ecdsa.PrivateKey),
symKeys: make(map[string][]byte), symKeys: make(map[string][]byte),
envelopes: make(map[common.Hash]*Envelope), envelopes: make(map[common.Hash]*Envelope),
expirations: make(map[uint32]*set.SetNonTS), expirations: make(map[uint32]mapset.Set),
peers: make(map[*Peer]struct{}), peers: make(map[*Peer]struct{}),
messageQueue: make(chan *Envelope, messageQueueLimit), messageQueue: make(chan *Envelope, messageQueueLimit),
p2pMsgQueue: make(chan *Envelope, messageQueueLimit), p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
@ -796,9 +796,9 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
if !alreadyCached { if !alreadyCached {
whisper.envelopes[hash] = envelope whisper.envelopes[hash] = envelope
if whisper.expirations[envelope.Expiry] == nil { if whisper.expirations[envelope.Expiry] == nil {
whisper.expirations[envelope.Expiry] = set.NewNonTS() whisper.expirations[envelope.Expiry] = mapset.NewThreadUnsafeSet()
} }
if !whisper.expirations[envelope.Expiry].Has(hash) { if !whisper.expirations[envelope.Expiry].Contains(hash) {
whisper.expirations[envelope.Expiry].Add(hash) whisper.expirations[envelope.Expiry].Add(hash)
} }
} }