|
|
|
@ -1,22 +1,23 @@ |
|
|
|
|
package blockedpeers |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"github.com/harmony-one/harmony/internal/utils/lrucache" |
|
|
|
|
libp2p_peer "github.com/libp2p/go-libp2p/core/peer" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/utils/lrucache" |
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Manager struct { |
|
|
|
|
internal *lrucache.Cache[libp2p_peer.ID, time.Time] |
|
|
|
|
internal *lrucache.Cache[peer.ID, time.Time] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewManager(size int) *Manager { |
|
|
|
|
return &Manager{ |
|
|
|
|
internal: lrucache.NewCache[libp2p_peer.ID, time.Time](size), |
|
|
|
|
internal: lrucache.NewCache[peer.ID, time.Time](size), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) IsBanned(key libp2p_peer.ID, now time.Time) bool { |
|
|
|
|
func (m *Manager) IsBanned(key peer.ID, now time.Time) bool { |
|
|
|
|
future, ok := m.internal.Get(key) |
|
|
|
|
|
|
|
|
|
if ok { |
|
|
|
@ -25,11 +26,11 @@ func (m *Manager) IsBanned(key libp2p_peer.ID, now time.Time) bool { |
|
|
|
|
return ok |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) Ban(key libp2p_peer.ID, future time.Time) { |
|
|
|
|
func (m *Manager) Ban(key peer.ID, future time.Time) { |
|
|
|
|
m.internal.Set(key, future) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) Contains(key libp2p_peer.ID) bool { |
|
|
|
|
func (m *Manager) Contains(key peer.ID) bool { |
|
|
|
|
return m.internal.Contains(key) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -37,6 +38,6 @@ func (m *Manager) Len() int { |
|
|
|
|
return m.internal.Len() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) Keys() []libp2p_peer.ID { |
|
|
|
|
func (m *Manager) Keys() []peer.ID { |
|
|
|
|
return m.internal.Keys() |
|
|
|
|
} |
|
|
|
|