Add lotus net scores for pubsub score visibility
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user