2014-08-07 18:06:50 -07:00
|
|
|
package dht
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
peer "github.com/jbenet/go-ipfs/peer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type connDiagInfo struct {
|
|
|
|
Latency time.Duration
|
2014-08-16 23:03:36 -07:00
|
|
|
ID peer.ID
|
2014-08-07 18:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type diagInfo struct {
|
2014-08-16 23:03:36 -07:00
|
|
|
ID peer.ID
|
2014-08-07 18:06:50 -07:00
|
|
|
Connections []connDiagInfo
|
2014-08-09 22:28:46 -07:00
|
|
|
Keys []string
|
|
|
|
LifeSpan time.Duration
|
2014-08-07 18:06:50 -07:00
|
|
|
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/jbenet/go-ipfs"
|
2014-12-19 12:19:56 -08:00
|
|
|
di.ID = dht.self
|
2014-08-07 18:06:50 -07:00
|
|
|
di.LifeSpan = time.Since(dht.birth)
|
|
|
|
di.Keys = nil // Currently no way to query datastore
|
|
|
|
|
2014-12-11 06:08:53 +00:00
|
|
|
for _, p := range dht.routingTable.ListPeers() {
|
2014-12-19 12:19:56 -08:00
|
|
|
d := connDiagInfo{dht.peerstore.LatencyEWMA(p), p}
|
2014-10-20 03:26:44 -07:00
|
|
|
di.Connections = append(di.Connections, d)
|
2014-08-07 18:06:50 -07:00
|
|
|
}
|
|
|
|
return di
|
|
|
|
}
|