Add lotus net scores for pubsub score visibility

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera
2020-06-03 03:13:49 +02:00
parent 4a983995a8
commit 186fd4da74
8 changed files with 85 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
package dtypes
import (
"sync"
peer "github.com/libp2p/go-libp2p-peer"
)
type ScoreKeeper struct {
lk sync.Mutex
scores map[peer.ID]float64
}
func (sk *ScoreKeeper) Update(scores map[peer.ID]float64) {
sk.lk.Lock()
sk.scores = scores
sk.lk.Unlock()
}
func (sk *ScoreKeeper) Get() map[peer.ID]float64 {
sk.lk.Lock()
defer sk.lk.Unlock()
return sk.scores
}
+6 -1
View File
@@ -28,7 +28,11 @@ func init() {
pubsub.GossipSubDirectConnectInitialDelay = 30 * time.Second
}
func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers, cfg *config.Pubsub) (service *pubsub.PubSub, err error) {
func ScoreKeeper() *dtypes.ScoreKeeper {
return new(dtypes.ScoreKeeper)
}
func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers, cfg *config.Pubsub, sk *dtypes.ScoreKeeper) (service *pubsub.PubSub, err error) {
bootstrappers := make(map[peer.ID]struct{})
for _, pi := range bp {
bootstrappers[pi.ID] = struct{}{}
@@ -161,6 +165,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
OpportunisticGraftThreshold: 5,
},
),
pubsub.WithPeerScoreInspect(sk.Update, 10*time.Second),
}
// enable Peer eXchange on bootstrappers