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

import (
4
	key "github.com/ipfs/go-ipfs/blocks/key"
Jeromy's avatar
Jeromy committed
5
	"sort"
6 7 8
)

type Stat struct {
9
	ProvideBufLen   int
10
	Wantlist        []key.Key
11 12 13
	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()
Jeromy's avatar
Jeromy committed
20
	bs.counterLk.Lock()
21 22
	st.BlocksReceived = bs.blocksRecvd
	st.DupBlksReceived = bs.dupBlocksRecvd
Jeromy's avatar
Jeromy committed
23
	bs.counterLk.Unlock()
24

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

	return st, nil
}