prettify things
This commit is contained in:
parent
73880606b5
commit
c82d664e8f
6
score.go
6
score.go
|
@ -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 {
|
func (ps *peerScore) SetTopicScoreParams(topic string, p *TopicScoreParams) error {
|
||||||
// Note: assumes that the topic score parameters have already been validated
|
|
||||||
ps.Lock()
|
ps.Lock()
|
||||||
defer ps.Unlock()
|
defer ps.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -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
|
// Create parameters with reasonable default values
|
||||||
mytopic := "mytopic"
|
mytopic := "mytopic"
|
||||||
params := &PeerScoreParams{
|
params := &PeerScoreParams{
|
||||||
|
|
21
topic.go
21
topic.go
|
@ -34,6 +34,11 @@ func (t *Topic) String() string {
|
||||||
// SetScoreParams sets the topic score parameters if the pubsub router supports peer
|
// SetScoreParams sets the topic score parameters if the pubsub router supports peer
|
||||||
// scoring
|
// scoring
|
||||||
func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
|
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()
|
t.mux.Lock()
|
||||||
defer t.mux.Unlock()
|
defer t.mux.Unlock()
|
||||||
|
|
||||||
|
@ -41,14 +46,8 @@ func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
|
||||||
return ErrTopicClosed
|
return ErrTopicClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
err := p.validate()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid topic score parameters: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make(chan error, 1)
|
result := make(chan error, 1)
|
||||||
select {
|
update := func() {
|
||||||
case t.p.eval <- func() {
|
|
||||||
gs, ok := t.p.rt.(*GossipSubRouter)
|
gs, ok := t.p.rt.(*GossipSubRouter)
|
||||||
if !ok {
|
if !ok {
|
||||||
result <- fmt.Errorf("pubsub router is not gossipsub")
|
result <- fmt.Errorf("pubsub router is not gossipsub")
|
||||||
|
@ -60,8 +59,12 @@ func (t *Topic) SetScoreParams(p *TopicScoreParams) error {
|
||||||
return
|
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
|
err = <-result
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue