mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
Merge pull request #2819 from ipfs/cleanup/dht
clean up some dead code in the dht
This commit is contained in:
@ -96,16 +96,6 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.Datastore) *IpfsDHT {
|
|||||||
return dht
|
return dht
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalPeer returns the peer.Peer of the dht.
|
|
||||||
func (dht *IpfsDHT) LocalPeer() peer.ID {
|
|
||||||
return dht.self
|
|
||||||
}
|
|
||||||
|
|
||||||
// log returns the dht's logger
|
|
||||||
func (dht *IpfsDHT) log() logging.EventLogger {
|
|
||||||
return log // TODO rm
|
|
||||||
}
|
|
||||||
|
|
||||||
// putValueToPeer stores the given key/value pair at the peer 'p'
|
// putValueToPeer stores the given key/value pair at the peer 'p'
|
||||||
func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID,
|
func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID,
|
||||||
key key.Key, rec *pb.Record) error {
|
key key.Key, rec *pb.Record) error {
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package dht
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type logDhtRPC struct {
|
|
||||||
Type string
|
|
||||||
Start time.Time
|
|
||||||
End time.Time
|
|
||||||
Duration time.Duration
|
|
||||||
RPCCount int
|
|
||||||
Success bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func startNewRPC(name string) *logDhtRPC {
|
|
||||||
r := new(logDhtRPC)
|
|
||||||
r.Type = name
|
|
||||||
r.Start = time.Now()
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logDhtRPC) EndLog() {
|
|
||||||
l.End = time.Now()
|
|
||||||
l.Duration = l.End.Sub(l.Start)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logDhtRPC) Print() {
|
|
||||||
b, err := json.Marshal(l)
|
|
||||||
if err != nil {
|
|
||||||
log.Debugf("Error marshaling logDhtRPC object: %s", err)
|
|
||||||
} else {
|
|
||||||
log.Debug(string(b))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logDhtRPC) String() string {
|
|
||||||
return fmt.Sprintf("DHT RPC: %s took %s, success = %v", l.Type, l.Duration, l.Success)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logDhtRPC) EndAndPrint() {
|
|
||||||
l.EndLog()
|
|
||||||
l.Print()
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package dht
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
peer "gx/ipfs/QmQGwpJy9P4yXZySmqkZEXCmbBpJUb8xntCv8Ca4taZwDC/go-libp2p-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
|
|
||||||
}
|
|
Reference in New Issue
Block a user