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
+18
View File
@@ -2,6 +2,8 @@ package common
import (
"context"
"sort"
"strings"
logging "github.com/ipfs/go-log/v2"
@@ -28,6 +30,7 @@ type CommonAPI struct {
APISecret *dtypes.APIAlg
Host host.Host
Router lp2p.BaseIpfsRouting
Sk *dtypes.ScoreKeeper
}
type jwtPayload struct {
@@ -54,6 +57,21 @@ func (a *CommonAPI) AuthNew(ctx context.Context, perms []auth.Permission) ([]byt
func (a *CommonAPI) NetConnectedness(ctx context.Context, pid peer.ID) (network.Connectedness, error) {
return a.Host.Network().Connectedness(pid), nil
}
func (a *CommonAPI) NetPubsubScores(context.Context) ([]api.PubsubScore, error) {
scores := a.Sk.Get()
out := make([]api.PubsubScore, len(scores))
i := 0
for k, v := range scores {
out[i] = api.PubsubScore{k, v}
i++
}
sort.Slice(out, func(i, j int) bool {
return strings.Compare(string(out[i].ID), string(out[j].ID)) > 0
})
return out, nil
}
func (a *CommonAPI) NetPeers(context.Context) ([]peer.AddrInfo, error) {
conns := a.Host.Network().Conns()