prettify things

This commit is contained in:
vyzo 2020-09-09 15:15:41 +03:00
parent 73880606b5
commit c82d664e8f
3 changed files with 17 additions and 12 deletions

View File

@ -182,9 +182,11 @@ func newPeerScore(params *PeerScoreParams) *peerScore {
}
}
// update interface
// SetTopicScoreParams sets new score parameters for a topic.
// If the topic previously had parameters and the parameters are lowering delivery caps,
// then the score counters are recapped appropriately.
// Note: assumes that the topic score parameters have already been validated
func (ps *peerScore) SetTopicScoreParams(topic string, p *TopicScoreParams) error {
// Note: assumes that the topic score parameters have already been validated
ps.Lock()
defer ps.Unlock()

View File

@ -842,7 +842,7 @@ func TestScoreRetention(t *testing.T) {
}
}
func TestScoreResetTopicParams(t *testing.T) {
func TestScoreRecapTopicParams(t *testing.T) {
// Create parameters with reasonable default values
mytopic := "mytopic"
params := &PeerScoreParams{

View File

@ -34,6 +34,11 @@ func (t *Topic) String() string {
// SetScoreParams sets the topic score parameters if the pubsub router supports peer
// scoring
func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
err := p.validate()
if err != nil {
return fmt.Errorf("invalid topic score parameters: %w", err)
}
t.mux.Lock()
defer t.mux.Unlock()
@ -41,14 +46,8 @@ func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
return ErrTopicClosed
}
err := p.validate()
if err != nil {
return fmt.Errorf("invalid topic score parameters: %w", err)
}
result := make(chan error, 1)
select {
case t.p.eval <- func() {
update := func() {
gs, ok := t.p.rt.(*GossipSubRouter)
if !ok {
result <- fmt.Errorf("pubsub router is not gossipsub")
@ -60,8 +59,12 @@ func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
return
}
result <- gs.score.SetTopicScoreParams(t.topic, p)
}:
err := gs.score.SetTopicScoreParams(t.topic, p)
result <- err
}
select {
case t.p.eval <- update:
err = <-result
return err