Files
go-libp2p-kad-dht/diag.go
Juan Batiz-Benet 2b086634b2 introducing p2p pkg
I think it's time to move a lot of the peer-to-peer networking
but-not-ipfs-specific things into its own package: p2p.
This could in the future be split off into its own library.
The first thing to go is the peer.
2015-01-02 08:46:45 -08:00

45 lines
878 B
Go

package dht
import (
"encoding/json"
"time"
peer "github.com/jbenet/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/jbenet/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
}