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

import (
Jeromy's avatar
Jeromy committed
4
	"sort"
5

6
	cid "gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
7 8 9
)

type Stat struct {
10
	ProvideBufLen   int
11
	Wantlist        []*cid.Cid
12 13 14
	Peers           []string
	BlocksReceived  int
	DupBlksReceived int
15
	DupDataReceived uint64
16 17 18 19 20 21
}

func (bs *Bitswap) Stat() (*Stat, error) {
	st := new(Stat)
	st.ProvideBufLen = len(bs.newBlocks)
	st.Wantlist = bs.GetWantlist()
Jeromy's avatar
Jeromy committed
22
	bs.counterLk.Lock()
23 24
	st.BlocksReceived = bs.blocksRecvd
	st.DupBlksReceived = bs.dupBlocksRecvd
25
	st.DupDataReceived = bs.dupDataRecvd
Jeromy's avatar
Jeromy committed
26
	bs.counterLk.Unlock()
27

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

	return st, nil
}