stat.go 541 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
)

type Stat struct {
9 10 11 12 13
	ProvideBufLen   int
	Wantlist        []u.Key
	Peers           []string
	BlocksReceived  int
	DupBlksReceived int
14 15 16 17 18 19
}

func (bs *Bitswap) Stat() (*Stat, error) {
	st := new(Stat)
	st.ProvideBufLen = len(bs.newBlocks)
	st.Wantlist = bs.GetWantlist()
20 21
	st.BlocksReceived = bs.blocksRecvd
	st.DupBlksReceived = bs.dupBlocksRecvd
22

Jeromy's avatar
Jeromy committed
23 24 25 26
	for _, p := range bs.engine.Peers() {
		st.Peers = append(st.Peers, p.Pretty())
	}
	sort.Strings(st.Peers)
27 28 29

	return st, nil
}