stat.go 417 Bytes
Newer Older
1 2 3
package bitswap

import (
4
	u "github.com/ipfs/go-ipfs/util"
Jeromy's avatar
Jeromy committed
5
	"sort"
6 7 8 9 10
)

type Stat struct {
	ProvideBufLen int
	Wantlist      []u.Key
Jeromy's avatar
Jeromy committed
11
	Peers         []string
12 13 14 15 16 17 18
}

func (bs *Bitswap) Stat() (*Stat, error) {
	st := new(Stat)
	st.ProvideBufLen = len(bs.newBlocks)
	st.Wantlist = bs.GetWantlist()

Jeromy's avatar
Jeromy committed
19 20 21 22
	for _, p := range bs.engine.Peers() {
		st.Peers = append(st.Peers, p.Pretty())
	}
	sort.Strings(st.Peers)
23 24 25

	return st, nil
}