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 {
if err != nil {
return err
}
conf.BandScoreThresholds = bandScorer
conf.BandScoreThresholds = *bandScorer
return nil
}
......
......@@ -55,7 +55,7 @@ type Config struct {
TopicScoring pubsub.TopicScoreParams
// Peer Score Band Thresholds
BandScoreThresholds BandScorer
BandScoreThresholds BandScoreThresholds
// Whether to ban peers based on their [PeerScoring] score.
BanningEnabled bool
......@@ -154,8 +154,8 @@ func (conf *Config) PeerScoringParams() *pubsub.PeerScoreParams {
return &conf.PeerScoring
}
func (conf *Config) PeerBandScorer() BandScorer {
return conf.BandScoreThresholds
func (conf *Config) PeerBandScorer() *BandScoreThresholds {
return &conf.BandScoreThresholds
}
func (conf *Config) BanPeers() bool {
......
......@@ -55,7 +55,7 @@ type GossipSetupConfigurables interface {
TopicScoringParams() *pubsub.TopicScoreParams
BanPeers() bool
ConfigureGossip(params *pubsub.GossipSubParams) []pubsub.Option
PeerBandScorer() BandScorer
PeerBandScorer() *BandScoreThresholds
}
type GossipRuntimeConfig interface {
......
......@@ -16,7 +16,7 @@ type scorer struct {
metricer GossipMetricer
log log.Logger
gater PeerGater
bandScoreThresholds BandScorer
bandScoreThresholds BandScoreThresholds
}
// scorePair holds a band and its corresponding threshold.
......@@ -31,17 +31,6 @@ type BandScoreThresholds struct {
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.
func NewBandScorer(str string) (*BandScoreThresholds, error) {
s := &BandScoreThresholds{
......@@ -76,11 +65,6 @@ func NewBandScorer(str string) (*BandScoreThresholds, error) {
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.
func (s *BandScoreThresholds) Bucket(score float64) string {
for _, pair := range s.bands {
......@@ -117,7 +101,7 @@ type Scorer interface {
}
// 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{
peerStore: peerStore,
metricer: metricer,
......
......@@ -20,7 +20,7 @@ type PeerScorerTestSuite struct {
mockGater *p2pMocks.PeerGater
mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer
bandScorer p2p.BandScorer
bandScorer p2p.BandScoreThresholds
logger log.Logger
}
......@@ -31,7 +31,7 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
testSuite.mockMetricer = &p2pMocks.GossipMetricer{}
bandScorer, err := p2p.NewBandScorer("0:graylist;")
testSuite.NoError(err)
testSuite.bandScorer = bandScorer
testSuite.bandScorer = *bandScorer
testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError)
}
......
......@@ -14,7 +14,7 @@ func ConfigurePeerScoring(h host.Host, g ConnectionGater, gossipConf GossipSetup
peerScoreThresholds := NewPeerScoreThresholds()
banEnabled := gossipConf.BanPeers()
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{}
// Check the app specific score since libp2p doesn't export it's [validate] function :/
if peerScoreParams != nil && peerScoreParams.AppSpecificScore != nil {
......
......@@ -30,7 +30,7 @@ type PeerScoresTestSuite struct {
mockGater *p2pMocks.ConnectionGater
mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer
bandScorer p2p.BandScorer
bandScorer p2p.BandScoreThresholds
logger log.Logger
}
......@@ -41,7 +41,7 @@ func (testSuite *PeerScoresTestSuite) SetupTest() {
testSuite.mockMetricer = &p2pMocks.GossipMetricer{}
bandScorer, err := p2p.NewBandScorer("0:graylist;")
testSuite.NoError(err)
testSuite.bandScorer = bandScorer
testSuite.bandScorer = *bandScorer
testSuite.logger = testlog.Logger(testSuite.T(), log.LvlError)
}
......
......@@ -68,7 +68,7 @@ func (p *Prepared) PeerScoringParams() *pubsub.PeerScoreParams {
return nil
}
func (p *Prepared) PeerBandScorer() BandScorer {
func (p *Prepared) PeerBandScorer() *BandScoreThresholds {
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