github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/exchange/bitswap/stat.go (about)

     1  package bitswap
     2  
     3  import (
     4  	key "github.com/ipfs/go-ipfs/blocks/key"
     5  	"sort"
     6  )
     7  
     8  type Stat struct {
     9  	ProvideBufLen   int
    10  	Wantlist        []key.Key
    11  	Peers           []string
    12  	BlocksReceived  int
    13  	DupBlksReceived int
    14  }
    15  
    16  func (bs *Bitswap) Stat() (*Stat, error) {
    17  	st := new(Stat)
    18  	st.ProvideBufLen = len(bs.newBlocks)
    19  	st.Wantlist = bs.GetWantlist()
    20  	bs.counterLk.Lock()
    21  	st.BlocksReceived = bs.blocksRecvd
    22  	st.DupBlksReceived = bs.dupBlocksRecvd
    23  	bs.counterLk.Unlock()
    24  
    25  	for _, p := range bs.engine.Peers() {
    26  		st.Peers = append(st.Peers, p.Pretty())
    27  	}
    28  	sort.Strings(st.Peers)
    29  
    30  	return st, nil
    31  }