lru blackclist
This commit is contained in:
parent
f084087574
commit
f6ac3aab4f
25
blacklist.go
25
blacklist.go
|
@ -1,6 +1,7 @@
|
|||
package pubsub
|
||||
|
||||
import (
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
)
|
||||
|
||||
|
@ -26,3 +27,27 @@ func (b MapBlacklist) Contains(p peer.ID) bool {
|
|||
_, ok := b[p]
|
||||
return ok
|
||||
}
|
||||
|
||||
// LRUBlacklist is a blacklist implementation using an LRU cache
|
||||
type LRUBlacklist struct {
|
||||
lru *lru.Cache
|
||||
}
|
||||
|
||||
// NewLRUBlacklist creates a new LRUBlacklist with capacity cap
|
||||
func NewLRUBlacklist(cap int) (Blacklist, error) {
|
||||
c, err := lru.New(cap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b := &LRUBlacklist{lru: c}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (b LRUBlacklist) Add(p peer.ID) {
|
||||
b.lru.Add(p, nil)
|
||||
}
|
||||
|
||||
func (b LRUBlacklist) Contains(p peer.ID) bool {
|
||||
return b.lru.Contains(p)
|
||||
}
|
||||
|
|
|
@ -77,6 +77,12 @@
|
|||
"hash": "QmabLh8TrJ3emfAoQk5AbqbLTbMyj7XqumMFmAFxa9epo8",
|
||||
"name": "go-multistream",
|
||||
"version": "0.3.9"
|
||||
},
|
||||
{
|
||||
"author": "hashicorp",
|
||||
"hash": "QmQjMHF8ptRgx4E57UFMiT4YM6kqaJeYxZ1MCDX23aw4rK",
|
||||
"name": "golang-lru",
|
||||
"version": "2017.10.18"
|
||||
}
|
||||
],
|
||||
"gxVersion": "0.9.0",
|
||||
|
@ -86,3 +92,4 @@
|
|||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "0.11.10"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue