The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/internal/utils/blockedpeers/manager.go

44 lines
791 B

package blockedpeers
import (
"time"
1 year ago
"github.com/harmony-one/harmony/internal/utils/lrucache"
"github.com/libp2p/go-libp2p/core/peer"
)
type Manager struct {
1 year ago
internal *lrucache.Cache[peer.ID, time.Time]
}
func NewManager(size int) *Manager {
return &Manager{
1 year ago
internal: lrucache.NewCache[peer.ID, time.Time](size),
}
}
1 year ago
func (m *Manager) IsBanned(key peer.ID, now time.Time) bool {
future, ok := m.internal.Get(key)
if ok {
return future.After(now) // future > now
}
return ok
}
1 year ago
func (m *Manager) Ban(key peer.ID, future time.Time) {
m.internal.Set(key, future)
}
1 year ago
func (m *Manager) Contains(key peer.ID) bool {
return m.internal.Contains(key)
}
func (m *Manager) Len() int {
return m.internal.Len()
}
1 year ago
func (m *Manager) Keys() []peer.ID {
return m.internal.Keys()
}