Source File
blacklist.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub
package pubsubimport ()// Blacklist is an interface for peer blacklisting.type Blacklist interface {Add(peer.ID) boolContains(peer.ID) bool}// MapBlacklist is a blacklist implementation using a perfect maptype MapBlacklist map[peer.ID]struct{}// NewMapBlacklist creates a new MapBlacklistfunc () Blacklist {return MapBlacklist(make(map[peer.ID]struct{}))}func ( MapBlacklist) ( peer.ID) bool {[] = struct{}{}return true}func ( MapBlacklist) ( peer.ID) bool {, := []return}// TimeCachedBlacklist is a blacklist implementation using a time cachetype TimeCachedBlacklist struct {tc timecache.TimeCache}// NewTimeCachedBlacklist creates a new TimeCachedBlacklist with the given expiry durationfunc ( time.Duration) (Blacklist, error) {:= &TimeCachedBlacklist{tc: timecache.NewTimeCache()}return , nil}// Add returns a bool saying whether Add of peer was successfulfunc ( *TimeCachedBlacklist) ( peer.ID) bool {:= .String()if .tc.Has() {return false}.tc.Add()return true}func ( *TimeCachedBlacklist) ( peer.ID) bool {return .tc.Has(.String())}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |