-
Notifications
You must be signed in to change notification settings - Fork 0
/
diag.go
44 lines (37 loc) · 874 Bytes
/
diag.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
41
42
43
44
package dht
import (
"encoding/json"
"time"
peer "github.com/ipfs/go-ipfs/p2p/peer"
)
type connDiagInfo struct {
Latency time.Duration
ID peer.ID
}
type diagInfo struct {
ID peer.ID
Connections []connDiagInfo
Keys []string
LifeSpan time.Duration
CodeVersion string
}
func (di *diagInfo) Marshal() []byte {
b, err := json.Marshal(di)
if err != nil {
panic(err)
}
//TODO: also consider compressing this. There will be a lot of these
return b
}
func (dht *IpfsDHT) getDiagInfo() *diagInfo {
di := new(diagInfo)
di.CodeVersion = "github.com/ipfs/go-ipfs"
di.ID = dht.self
di.LifeSpan = time.Since(dht.birth)
di.Keys = nil // Currently no way to query datastore
for _, p := range dht.routingTable.ListPeers() {
d := connDiagInfo{dht.peerstore.LatencyEWMA(p), p}
di.Connections = append(di.Connections, d)
}
return di
}