-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
40 lines (34 loc) · 845 Bytes
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package bitswap
import (
"sort"
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
)
type Stat struct {
ProvideBufLen int
Wantlist []*cid.Cid
Peers []string
BlocksReceived int
DataReceived uint64
BlocksSent int
DataSent uint64
DupBlksReceived int
DupDataReceived uint64
}
func (bs *Bitswap) Stat() (*Stat, error) {
st := new(Stat)
st.ProvideBufLen = len(bs.newBlocks)
st.Wantlist = bs.GetWantlist()
bs.counterLk.Lock()
st.BlocksReceived = bs.blocksRecvd
st.DupBlksReceived = bs.dupBlocksRecvd
st.DupDataReceived = bs.dupDataRecvd
st.BlocksSent = bs.blocksSent
st.DataSent = bs.dataSent
st.DataReceived = bs.dataRecvd
bs.counterLk.Unlock()
for _, p := range bs.engine.Peers() {
st.Peers = append(st.Peers, p.Pretty())
}
sort.Strings(st.Peers)
return st, nil
}