explicit Start for peer scoring to inject the router

so that we can unit test without a router.
This commit is contained in:
vyzo 2020-03-07 17:59:22 +02:00
parent a02c4136b1
commit 8d82c2bdec
2 changed files with 16 additions and 2 deletions

View File

@ -97,7 +97,7 @@ func WithPeerScore(params *PeerScoreParams, gossipThreshold, publishThreshold, g
return fmt.Errorf("pubsub router is not gossipsub")
}
gs.score = newPeerScore(gs, params)
gs.score = newPeerScore(params)
gs.gossipThreshold = gossipThreshold
gs.publishThreshold = publishThreshold
gs.graylistThreshold = graylistThreshold
@ -178,9 +178,19 @@ func (gs *GossipSubRouter) Protocols() []protocol.ID {
func (gs *GossipSubRouter) Attach(p *PubSub) {
gs.p = p
gs.tracer = p.tracer
// start the scoring, if any
if gs.score != nil {
gs.score.Start(gs)
}
// start using the same msg ID function as PubSub for caching messages.
gs.mcache.SetMsgIdFn(p.msgID)
// start the heartbeat
go gs.heartbeatTimer()
// start the PX connectors
for i := 0; i < GossipSubConnectors; i++ {
go gs.connector()
}

View File

@ -79,11 +79,15 @@ type TopicScoreParams struct {
type peerScore struct {
}
func newPeerScore(gs *GossipSubRouter, params *PeerScoreParams) *peerScore {
func newPeerScore(params *PeerScoreParams) *peerScore {
return nil
}
// router interface
func (ps *peerScore) Start(gs *GossipSubRouter) {
}
func (ps *peerScore) Score(p peer.ID) float64 {
return 0
}