explicit Start for peer scoring to inject the router
so that we can unit test without a router.
This commit is contained in:
parent
a02c4136b1
commit
8d82c2bdec
12
gossipsub.go
12
gossipsub.go
|
@ -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()
|
||||
}
|
||||
|
|
6
score.go
6
score.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue