Commit 15cf4af6 authored by Andreas Bigger's avatar Andreas Bigger

cleanup

parent bf3945d6
...@@ -132,7 +132,7 @@ func loadPeerScoreBands(conf *p2p.Config, ctx *cli.Context) error { ...@@ -132,7 +132,7 @@ func loadPeerScoreBands(conf *p2p.Config, ctx *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
conf.BandScoreThresholds = bandScorer conf.BandScoreThresholds = *bandScorer
return nil return nil
} }
......
...@@ -55,7 +55,7 @@ type Config struct { ...@@ -55,7 +55,7 @@ type Config struct {
TopicScoring pubsub.TopicScoreParams TopicScoring pubsub.TopicScoreParams
// Peer Score Band Thresholds // Peer Score Band Thresholds
BandScoreThresholds BandScorer BandScoreThresholds BandScoreThresholds
// Whether to ban peers based on their [PeerScoring] score. // Whether to ban peers based on their [PeerScoring] score.
BanningEnabled bool BanningEnabled bool
...@@ -154,8 +154,8 @@ func (conf *Config) PeerScoringParams() *pubsub.PeerScoreParams { ...@@ -154,8 +154,8 @@ func (conf *Config) PeerScoringParams() *pubsub.PeerScoreParams {
return &conf.PeerScoring return &conf.PeerScoring
} }
func (conf *Config) PeerBandScorer() BandScorer { func (conf *Config) PeerBandScorer() *BandScoreThresholds {
return conf.BandScoreThresholds return &conf.BandScoreThresholds
} }
func (conf *Config) BanPeers() bool { func (conf *Config) BanPeers() bool {
......
...@@ -55,7 +55,7 @@ type GossipSetupConfigurables interface { ...@@ -55,7 +55,7 @@ type GossipSetupConfigurables interface {
TopicScoringParams() *pubsub.TopicScoreParams TopicScoringParams() *pubsub.TopicScoreParams
BanPeers() bool BanPeers() bool
ConfigureGossip(params *pubsub.GossipSubParams) []pubsub.Option ConfigureGossip(params *pubsub.GossipSubParams) []pubsub.Option
PeerBandScorer() BandScorer PeerBandScorer() *BandScoreThresholds
} }
type GossipRuntimeConfig interface { type GossipRuntimeConfig interface {
......
...@@ -16,7 +16,7 @@ type scorer struct { ...@@ -16,7 +16,7 @@ type scorer struct {
metricer GossipMetricer metricer GossipMetricer
log log.Logger log log.Logger
gater PeerGater gater PeerGater
bandScoreThresholds BandScorer bandScoreThresholds BandScoreThresholds
} }
// scorePair holds a band and its corresponding threshold. // scorePair holds a band and its corresponding threshold.
...@@ -31,17 +31,6 @@ type BandScoreThresholds struct { ...@@ -31,17 +31,6 @@ type BandScoreThresholds struct {
bands []scorePair bands []scorePair
} }
// BandScorer is an interface for placing peer scores
// into various bands.
//
// Implementations are expected to construct internals using the
// [Parse] function and then expose the [Bucket] function for
// downstream [BandScorer] consumers.
type BandScorer interface {
Bucket(score float64) string
Reset()
}
// NewBandScorer constructs a new [BandScoreThresholds] instance. // NewBandScorer constructs a new [BandScoreThresholds] instance.
func NewBandScorer(str string) (*BandScoreThresholds, error) { func NewBandScorer(str string) (*BandScoreThresholds, error) {
s := &BandScoreThresholds{ s := &BandScoreThresholds{
...@@ -76,11 +65,6 @@ func NewBandScorer(str string) (*BandScoreThresholds, error) { ...@@ -76,11 +65,6 @@ func NewBandScorer(str string) (*BandScoreThresholds, error) {
return s, nil return s, nil
} }
// Reset wipes the internal state of the [BandScorer].
func (s *BandScoreThresholds) Reset() {
s.bands = s.bands[:0]
}
// Bucket returns the appropriate band for a given score. // Bucket returns the appropriate band for a given score.
func (s *BandScoreThresholds) Bucket(score float64) string { func (s *BandScoreThresholds) Bucket(score float64) string {
for _, pair := range s.bands { for _, pair := range s.bands {
...@@ -117,7 +101,7 @@ type Scorer interface { ...@@ -117,7 +101,7 @@ type Scorer interface {
} }
// NewScorer returns a new peer scorer. // NewScorer returns a new peer scorer.
func NewScorer(peerGater PeerGater, peerStore Peerstore, metricer GossipMetricer, bandScoreThresholds BandScorer, log log.Logger) Scorer { func NewScorer(peerGater PeerGater, peerStore Peerstore, metricer GossipMetricer, bandScoreThresholds BandScoreThresholds, log log.Logger) Scorer {
return &scorer{ return &scorer{
peerStore: peerStore, peerStore: peerStore,
metricer: metricer, metricer: metricer,
......
...@@ -20,7 +20,7 @@ type PeerScorerTestSuite struct { ...@@ -20,7 +20,7 @@ type PeerScorerTestSuite struct {
mockGater *p2pMocks.PeerGater mockGater *p2pMocks.PeerGater
mockStore *p2pMocks.Peerstore mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer mockMetricer *p2pMocks.GossipMetricer
bandScorer p2p.BandScorer bandScorer p2p.BandScoreThresholds
logger log.Logger logger log.Logger
} }
...@@ -31,7 +31,7 @@ func (testSuite *PeerScorerTestSuite) SetupTest() { ...@@ -31,7 +31,7 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
testSuite.mockMetricer = &p2pMocks.GossipMetricer{} testSuite.mockMetricer = &p2pMocks.GossipMetricer{}
bandScorer, err := p2p.NewBandScorer("0:graylist;") bandScorer, err := p2p.NewBandScorer("0:graylist;")
testSuite.NoError(err) testSuite.NoError(err)
testSuite.bandScorer = bandScorer testSuite.bandScorer = *bandScorer
testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError) testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError)
} }
......
...@@ -14,7 +14,7 @@ func ConfigurePeerScoring(h host.Host, g ConnectionGater, gossipConf GossipSetup ...@@ -14,7 +14,7 @@ func ConfigurePeerScoring(h host.Host, g ConnectionGater, gossipConf GossipSetup
peerScoreThresholds := NewPeerScoreThresholds() peerScoreThresholds := NewPeerScoreThresholds()
banEnabled := gossipConf.BanPeers() banEnabled := gossipConf.BanPeers()
peerGater := NewPeerGater(g, log, banEnabled) peerGater := NewPeerGater(g, log, banEnabled)
scorer := NewScorer(peerGater, h.Peerstore(), m, gossipConf.PeerBandScorer(), log) scorer := NewScorer(peerGater, h.Peerstore(), m, *gossipConf.PeerBandScorer(), log)
opts := []pubsub.Option{} opts := []pubsub.Option{}
// Check the app specific score since libp2p doesn't export it's [validate] function :/ // Check the app specific score since libp2p doesn't export it's [validate] function :/
if peerScoreParams != nil && peerScoreParams.AppSpecificScore != nil { if peerScoreParams != nil && peerScoreParams.AppSpecificScore != nil {
......
...@@ -30,7 +30,7 @@ type PeerScoresTestSuite struct { ...@@ -30,7 +30,7 @@ type PeerScoresTestSuite struct {
mockGater *p2pMocks.ConnectionGater mockGater *p2pMocks.ConnectionGater
mockStore *p2pMocks.Peerstore mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer mockMetricer *p2pMocks.GossipMetricer
bandScorer p2p.BandScorer bandScorer p2p.BandScoreThresholds
logger log.Logger logger log.Logger
} }
...@@ -41,7 +41,7 @@ func (testSuite *PeerScoresTestSuite) SetupTest() { ...@@ -41,7 +41,7 @@ func (testSuite *PeerScoresTestSuite) SetupTest() {
testSuite.mockMetricer = &p2pMocks.GossipMetricer{} testSuite.mockMetricer = &p2pMocks.GossipMetricer{}
bandScorer, err := p2p.NewBandScorer("0:graylist;") bandScorer, err := p2p.NewBandScorer("0:graylist;")
testSuite.NoError(err) testSuite.NoError(err)
testSuite.bandScorer = bandScorer testSuite.bandScorer = *bandScorer
testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError) testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError)
} }
......
...@@ -68,7 +68,7 @@ func (p *Prepared) PeerScoringParams() *pubsub.PeerScoreParams { ...@@ -68,7 +68,7 @@ func (p *Prepared) PeerScoringParams() *pubsub.PeerScoreParams {
return nil return nil
} }
func (p *Prepared) PeerBandScorer() BandScorer { func (p *Prepared) PeerBandScorer() *BandScoreThresholds {
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment