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
|
|
|
|
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/jbenet/go-ipfs"
|
|
|
|
di.Id = dht.self.ID
|
|
|
|
di.LifeSpan = time.Since(dht.birth)
|
|
|
|
di.Keys = nil // Currently no way to query datastore
|
|
|
|
|
|
|
|
for _,p := range dht.routes[0].listpeers() {
|
2014-08-08 18:09:21 -07:00
|
|
|
di.Connections = append(di.Connections, connDiagInfo{p.GetLatency(), p.ID})
|
2014-08-07 18:06:50 -07:00
|
|
|
}
|
|
|
|
return di
|
|
|
|
}
|