@cryptotaxi247 / kubo / commits / 1cddf67a3

remove 'ipfs diag net' from codebase

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed May 11, 2017 at 00:05 UTC 1cddf67a35b1434ab5856a8d510b5b9ec8cdd57f
11 files changed +1 -819
Rules.mk
-3
@@ -53,9 +53,6 @@ include $(dir)/Rules.mk
53 dir := exchange/bitswap/message/pb
54 include $(dir)/Rules.mk
55
56 -dir := diagnostics/pb
57 -include $(dir)/Rules.mk
58 -
56 dir := pin/internal/pb
57 include $(dir)/Rules.mk
58
core/commands/diag.go
+1 -197
@@ -1,44 +1,6 @@
1 package commands
2
3 -import (
4 - "bytes"
5 - "errors"
6 - "io"
7 - "strings"
8 - "text/template"
9 - "time"
10 -
11 - cmds "github.com/ipfs/go-ipfs/commands"
12 - diag "github.com/ipfs/go-ipfs/diagnostics"
13 -)
14 -
15 -type DiagnosticConnection struct {
16 - ID string
17 - // TODO use milliseconds or microseconds for human readability
18 - NanosecondsLatency uint64
19 - Count int
20 -}
21 -
22 -var (
23 - visD3 = "d3"
24 - visDot = "dot"
25 - visText = "text"
26 - visFmts = []string{visD3, visDot, visText}
27 -)
28 -
29 -type DiagnosticPeer struct {
30 - ID string
31 - UptimeSeconds uint64
32 - BandwidthBytesIn uint64
33 - BandwidthBytesOut uint64
34 - Connections []DiagnosticConnection
35 -}
36 -
37 -type DiagnosticOutput struct {
38 - Peers []DiagnosticPeer
39 -}
40 -
41 -var DefaultDiagnosticTimeout = time.Second * 20
3 +import cmds "github.com/ipfs/go-ipfs/commands"
4
5 var DiagCmd = &cmds.Command{
6 Helptext: cmds.HelpText{
@@ -46,165 +8,7 @@ var DiagCmd = &cmds.Command{
8 },
9
10 Subcommands: map[string]*cmds.Command{
49 - "net": diagNetCmd,
11 "sys": sysDiagCmd,
12 "cmds": ActiveReqsCmd,
13 },
14 }
54 -
55 -var diagNetCmd = &cmds.Command{
56 - Helptext: cmds.HelpText{
57 - Tagline: "Generate a network diagnostics report.",
58 - ShortDescription: `
59 -Sends out a message to each node in the network recursively
60 -requesting a listing of data about them including number of
61 -connected peers and latencies between them.
62 -
63 -The given timeout will be decremented 2s at every network hop,
64 -ensuring peers try to return their diagnostics before the initiator's
65 -timeout. If the timeout is too small, some peers may not be reached.
66 -30s and 60s are reasonable timeout values, though networks vary.
67 -The default timeout is 20 seconds.
68 -
69 -The 'vis' option may be used to change the output format.
70 -Three formats are supported:
71 - * text - Easy to read. Default.
72 - * d3 - json ready to be fed into d3view
73 - * dot - graphviz format
74 -
75 -The 'd3' format will output a json object ready to be consumed by
76 -the chord network viewer, available at the following hash:
77 -
78 - /ipfs/QmbesKpGyQGd5jtJFUGEB1ByPjNFpukhnKZDnkfxUiKn38
79 -
80 -To view your diag output, 'ipfs add' the d3 vis output, and
81 -open the following link:
82 -
83 - http://gateway.ipfs.io/ipfs/QmbesKpGyQGd5jtJFUGEB1ByPjNFpukhnKZDnkfxUiKn38/chord#<your hash>
84 -
85 -The 'dot' format can be fed into graphviz and other programs
86 -that consume the dot format to generate graphs of the network.
87 -`,
88 - },
89 -
90 - Options: []cmds.Option{
91 - cmds.StringOption("vis", "Output format. One of: "+strings.Join(visFmts, ", ")).Default(visText),
92 - },
93 -
94 - Run: func(req cmds.Request, res cmds.Response) {
95 - n, err := req.InvocContext().GetNode()
96 - if err != nil {
97 - res.SetError(err, cmds.ErrNormal)
98 - return
99 - }
100 -
101 - if !n.OnlineMode() {
102 - res.SetError(errNotOnline, cmds.ErrClient)
103 - return
104 - }
105 -
106 - vis, _, err := req.Option("vis").String()
107 - if err != nil {
108 - res.SetError(err, cmds.ErrNormal)
109 - return
110 - }
111 -
112 - timeoutS, _, err := req.Option("timeout").String()
113 - if err != nil {
114 - res.SetError(err, cmds.ErrNormal)
115 - return
116 - }
117 - timeout := DefaultDiagnosticTimeout
118 - if timeoutS != "" {
119 - t, err := time.ParseDuration(timeoutS)
120 - if err != nil {
121 - res.SetError(errors.New("error parsing timeout"), cmds.ErrNormal)
122 - return
123 - }
124 - timeout = t
125 - }
126 -
127 - info, err := n.Diagnostics.GetDiagnostic(req.Context(), timeout)
128 - if err != nil {
129 - res.SetError(err, cmds.ErrNormal)
130 - return
131 - }
132 -
133 - switch vis {
134 - case visD3:
135 - res.SetOutput(bytes.NewReader(diag.GetGraphJson(info)))
136 - case visDot:
137 - buf := new(bytes.Buffer)
138 - w := diag.DotWriter{W: buf}
139 - err := w.WriteGraph(info)
140 - if err != nil {
141 - res.SetError(err, cmds.ErrNormal)
142 - return
143 - }
144 - res.SetOutput(io.Reader(buf))
145 - case visText:
146 - output, err := stdDiagOutputMarshal(standardDiagOutput(info))
147 - if err != nil {
148 - res.SetError(err, cmds.ErrNormal)
149 - return
150 - }
151 - res.SetOutput(output)
152 - default:
153 - res.SetError(err, cmds.ErrNormal)
154 - return
155 - }
156 - },
157 -}
158 -
159 -func stdDiagOutputMarshal(output *DiagnosticOutput) (io.Reader, error) {
160 - buf := new(bytes.Buffer)
161 - err := printDiagnostics(buf, output)
162 - if err != nil {
163 - return nil, err
164 - }
165 - return buf, nil
166 -}
167 -
168 -func standardDiagOutput(info []*diag.DiagInfo) *DiagnosticOutput {
169 - output := make([]DiagnosticPeer, len(info))
170 - for i, peer := range info {
171 - connections := make([]DiagnosticConnection, len(peer.Connections))
172 - for j, conn := range peer.Connections {
173 - connections[j] = DiagnosticConnection{
174 - ID: conn.ID,
175 - NanosecondsLatency: uint64(conn.Latency.Nanoseconds()),
176 - Count: conn.Count,
177 - }
178 - }
179 -
180 - output[i] = DiagnosticPeer{
181 - ID: peer.ID,
182 - UptimeSeconds: uint64(peer.LifeSpan.Seconds()),
183 - BandwidthBytesIn: peer.BwIn,
184 - BandwidthBytesOut: peer.BwOut,
185 - Connections: connections,
186 - }
187 - }
188 - return &DiagnosticOutput{output}
189 -}
190 -
191 -func printDiagnostics(out io.Writer, info *DiagnosticOutput) error {
192 - diagTmpl := `
193 -{{ range $peer := .Peers }}
194 -ID {{ $peer.ID }} up {{ $peer.UptimeSeconds }} seconds connected to {{ len .Connections }}:{{ range $connection := .Connections }}
195 - ID {{ $connection.ID }} connections: {{ $connection.Count }} latency: {{ $connection.NanosecondsLatency }} ns{{ end }}
196 -{{end}}
197 -`
198 -
199 - templ, err := template.New("DiagnosticOutput").Parse(diagTmpl)
200 - if err != nil {
201 - return err
202 - }
203 -
204 - err = templ.Execute(out, info)
205 - if err != nil {
206 - return err
207 - }
208 -
209 - return nil
210 -}
core/commands/diag_test.go deleted
-29
@@ -1,29 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "bytes"
5 - "testing"
6 -)
7 -
8 -func TestPrintDiagnostics(t *testing.T) {
9 - output := DiagnosticOutput{
10 - Peers: []DiagnosticPeer{
11 - {ID: "QmNrjRuUtBNZAigzLRdZGN1YCNUxdF2WY2HnKyEFJqoTeg",
12 - UptimeSeconds: 14,
13 - Connections: []DiagnosticConnection{
14 - {ID: "QmNrjRuUtBNZAigzLRdZGN1YCNUxdF2WY2HnKyEFJqoTeg",
15 - NanosecondsLatency: 1347899,
16 - },
17 - },
18 - },
19 - {ID: "QmUaUZDp6QWJabBYSKfiNmXLAXD8HNKnWZh9Zoz6Zri9Ti",
20 - UptimeSeconds: 14,
21 - },
22 - },
23 - }
24 - buf := new(bytes.Buffer)
25 - if err := printDiagnostics(buf, &output); err != nil {
26 - t.Fatal(err)
27 - }
28 - t.Log(buf.String())
29 -}
core/core.go
-3
@@ -23,7 +23,6 @@ import (
23
24 bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
25 bserv "github.com/ipfs/go-ipfs/blockservice"
26 - diag "github.com/ipfs/go-ipfs/diagnostics"
26 exchange "github.com/ipfs/go-ipfs/exchange"
27 bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
28 bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
@@ -127,7 +126,6 @@ type IpfsNode struct {
126 Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
127 Exchange exchange.Interface // the block exchange + strategy (bitswap)
128 Namesys namesys.NameSystem // the name system, resolves paths to hashes
130 - Diagnostics *diag.Diagnostics // the diagnostics service
129 Ping *ping.PingService
130 Reprovider *rp.Reprovider // the value reprovider system
131 IpnsRepub *ipnsrp.Republisher
@@ -317,7 +315,6 @@ func (n *IpfsNode) HandlePeerFound(p pstore.PeerInfo) {
315 // initialized with the host and _before_ we start listening.
316 func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost.Host, routingOption RoutingOption) error {
317 // setup diagnostics service
320 - n.Diagnostics = diag.NewDiagnostics(n.Identity, host)
318 n.Ping = ping.NewPingService(host)
319
320 // setup routing service
diagnostics/README.md deleted
-16
@@ -1,16 +0,0 @@
1 -# ipfs diagnostics
2 -
3 -Usage:
4 -```sh
5 -ipfs diag net [--vis=<vis>]
6 -```
7 -
8 -
9 -## view in d3
10 -
11 -Install https://github.com/jbenet/ipfs-diag-net-d3-vis then:
12 -
13 -```
14 -> ipfs diag net --vis=d3 | d3view
15 -http://ipfs.benet.ai:8080/ipfs/QmX8PuUyhSet8fppZHuRNxG7vk949z7XDxnsAz3zN77MGx#QmdhRqGea2QEzyKHG9Zhkc12d2994iah1h47tfHJifuzhT
16 -```
diagnostics/diag.go deleted
-343
@@ -1,343 +0,0 @@
1 -// package diagnostics implements a network diagnostics service that
2 -// allows a request to traverse the network and gather information
3 -// on every node connected to it.
4 -package diagnostics
5 -
6 -import (
7 - "crypto/rand"
8 - "encoding/json"
9 - "errors"
10 - "fmt"
11 - "sync"
12 - "time"
13 -
14 - context "context"
15 - pb "github.com/ipfs/go-ipfs/diagnostics/pb"
16 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
17 - ctxio "gx/ipfs/QmTKsRYeY4simJyf37K93juSq75Lo8MVCDJ7owjmf46u8W/go-context/io"
18 - inet "gx/ipfs/QmVHSBsn8LEeay8m5ERebgUVuhzw838PsyTttCmP6GMJkg/go-libp2p-net"
19 - ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
20 - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
21 - protocol "gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
22 - host "gx/ipfs/QmcyNeWPsoFGxThGpV8JnJdfUNankKhWCTrbrcFRQda4xR/go-libp2p-host"
23 - peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
24 -)
25 -
26 -var log = logging.Logger("diagnostics")
27 -
28 -// ProtocolDiag is the diagnostics protocol.ID
29 -var ProtocolDiag protocol.ID = "/ipfs/diag/net/1.0.0"
30 -var ProtocolDiagOld protocol.ID = "/ipfs/diagnostics"
31 -
32 -var ErrAlreadyRunning = errors.New("diagnostic with that ID already running")
33 -
34 -const ResponseTimeout = time.Second * 10
35 -const HopTimeoutDecrement = time.Second * 2
36 -
37 -// Diagnostics is a net service that manages requesting and responding to diagnostic
38 -// requests
39 -type Diagnostics struct {
40 - host host.Host
41 - self peer.ID
42 -
43 - diagLock sync.Mutex
44 - diagMap map[string]time.Time
45 - birth time.Time
46 -}
47 -
48 -// NewDiagnostics instantiates a new diagnostics service running on the given network
49 -func NewDiagnostics(self peer.ID, h host.Host) *Diagnostics {
50 - d := &Diagnostics{
51 - host: h,
52 - self: self,
53 - birth: time.Now(),
54 - diagMap: make(map[string]time.Time),
55 - }
56 -
57 - h.SetStreamHandler(ProtocolDiag, d.handleNewStream)
58 - h.SetStreamHandler(ProtocolDiagOld, d.handleNewStream)
59 - return d
60 -}
61 -
62 -type connDiagInfo struct {
63 - Latency time.Duration
64 - ID string
65 - Count int
66 -}
67 -
68 -type DiagInfo struct {
69 - // This nodes ID
70 - ID string
71 -
72 - // A list of peers this node currently has open connections to
73 - Connections []connDiagInfo
74 -
75 - // A list of keys provided by this node
76 - // (currently not filled)
77 - Keys []string
78 -
79 - // How long this node has been running for
80 - // TODO rename Uptime
81 - LifeSpan time.Duration
82 -
83 - // Incoming Bandwidth Usage
84 - BwIn uint64
85 -
86 - // Outgoing Bandwidth Usage
87 - BwOut uint64
88 -
89 - // Information about the version of code this node is running
90 - CodeVersion string
91 -}
92 -
93 -// Marshal to json
94 -func (di *DiagInfo) Marshal() []byte {
95 - b, err := json.Marshal(di)
96 - if err != nil {
97 - panic(err)
98 - }
99 - //TODO: also consider compressing this. There will be a lot of these
100 - return b
101 -}
102 -
103 -func (d *Diagnostics) getPeers() map[peer.ID]int {
104 - counts := make(map[peer.ID]int)
105 - for _, p := range d.host.Network().Peers() {
106 - counts[p]++
107 - }
108 -
109 - return counts
110 -}
111 -
112 -func (d *Diagnostics) getDiagInfo() *DiagInfo {
113 - di := new(DiagInfo)
114 - di.CodeVersion = "github.com/ipfs/go-ipfs"
115 - di.ID = d.self.Pretty()
116 - di.LifeSpan = time.Since(d.birth)
117 - di.Keys = nil // Currently no way to query datastore
118 -
119 - // di.BwIn, di.BwOut = d.host.BandwidthTotals() //TODO fix this.
120 -
121 - for p, n := range d.getPeers() {
122 - d := connDiagInfo{
123 - Latency: d.host.Peerstore().LatencyEWMA(p),
124 - ID: p.Pretty(),
125 - Count: n,
126 - }
127 - di.Connections = append(di.Connections, d)
128 - }
129 - return di
130 -}
131 -
132 -func newID() string {
133 - id := make([]byte, 16)
134 - rand.Read(id)
135 - return string(id)
136 -}
137 -
138 -// GetDiagnostic runs a diagnostics request across the entire network
139 -func (d *Diagnostics) GetDiagnostic(ctx context.Context, timeout time.Duration) ([]*DiagInfo, error) {
140 - log.Debug("getting diagnostic")
141 - ctx, cancel := context.WithTimeout(ctx, timeout)
142 - defer cancel()
143 -
144 - diagID := newID()
145 - d.diagLock.Lock()
146 - d.diagMap[diagID] = time.Now()
147 - d.diagLock.Unlock()
148 -
149 - log.Debug("begin diagnostic")
150 -
151 - peers := d.getPeers()
152 - log.Debugf("Sending diagnostic request to %d peers.", len(peers))
153 -
154 - pmes := newMessage(diagID)
155 -
156 - pmes.SetTimeoutDuration(timeout - HopTimeoutDecrement) // decrease timeout per hop
157 - dpeers, err := d.getDiagnosticFromPeers(ctx, d.getPeers(), pmes)
158 - if err != nil {
159 - return nil, fmt.Errorf("diagnostic from peers err: %s", err)
160 - }
161 -
162 - di := d.getDiagInfo()
163 - out := []*DiagInfo{di}
164 - for dpi := range dpeers {
165 - out = append(out, dpi)
166 - }
167 - return out, nil
168 -}
169 -
170 -func decodeDiagJson(data []byte) (*DiagInfo, error) {
171 - di := new(DiagInfo)
172 - err := json.Unmarshal(data, di)
173 - if err != nil {
174 - return nil, err
175 - }
176 -
177 - return di, nil
178 -}
179 -
180 -func (d *Diagnostics) getDiagnosticFromPeers(ctx context.Context, peers map[peer.ID]int, pmes *pb.Message) (<-chan *DiagInfo, error) {
181 - respdata := make(chan *DiagInfo)
182 - wg := sync.WaitGroup{}
183 - for p := range peers {
184 - wg.Add(1)
185 - log.Debugf("Sending diagnostic request to peer: %s", p)
186 - go func(p peer.ID) {
187 - defer wg.Done()
188 - out, err := d.getDiagnosticFromPeer(ctx, p, pmes)
189 - if err != nil {
190 - log.Debugf("Error getting diagnostic from %s: %s", p, err)
191 - return
192 - }
193 - for d := range out {
194 - select {
195 - case respdata <- d:
196 - case <-ctx.Done():
197 - return
198 - }
199 - }
200 - }(p)
201 - }
202 -
203 - go func() {
204 - wg.Wait()
205 - close(respdata)
206 - }()
207 -
208 - return respdata, nil
209 -}
210 -
211 -func (d *Diagnostics) getDiagnosticFromPeer(ctx context.Context, p peer.ID, pmes *pb.Message) (<-chan *DiagInfo, error) {
212 - s, err := d.host.NewStream(ctx, p, ProtocolDiag, ProtocolDiagOld)
213 - if err != nil {
214 - return nil, err
215 - }
216 -
217 - cr := ctxio.NewReader(ctx, s) // ok to use. we defer close stream in this func
218 - cw := ctxio.NewWriter(ctx, s) // ok to use. we defer close stream in this func
219 - r := ggio.NewDelimitedReader(cr, inet.MessageSizeMax)
220 - w := ggio.NewDelimitedWriter(cw)
221 -
222 - start := time.Now()
223 -
224 - if err := w.WriteMsg(pmes); err != nil {
225 - return nil, err
226 - }
227 -
228 - out := make(chan *DiagInfo)
229 - go func() {
230 -
231 - defer func() {
232 - close(out)
233 - s.Close()
234 - rtt := time.Since(start)
235 - log.Infof("diagnostic request took: %s", rtt.String())
236 - }()
237 -
238 - for {
239 - rpmes := new(pb.Message)
240 - if err := r.ReadMsg(rpmes); err != nil {
241 - log.Debugf("Error reading diagnostic from stream: %s", err)
242 - return
243 - }
244 - if rpmes == nil {
245 - log.Debug("got no response back from diag request")
246 - return
247 - }
248 -
249 - di, err := decodeDiagJson(rpmes.GetData())
250 - if err != nil {
251 - log.Debug(err)
252 - return
253 - }
254 -
255 - select {
256 - case out <- di:
257 - case <-ctx.Done():
258 - return
259 - }
260 - }
261 -
262 - }()
263 -
264 - return out, nil
265 -}
266 -
267 -func newMessage(diagID string) *pb.Message {
268 - pmes := new(pb.Message)
269 - pmes.DiagID = proto.String(diagID)
270 - return pmes
271 -}
272 -
273 -func (d *Diagnostics) HandleMessage(ctx context.Context, s inet.Stream) error {
274 -
275 - cr := ctxio.NewReader(ctx, s)
276 - cw := ctxio.NewWriter(ctx, s)
277 - r := ggio.NewDelimitedReader(cr, inet.MessageSizeMax) // maxsize
278 - w := ggio.NewDelimitedWriter(cw)
279 -
280 - // deserialize msg
281 - pmes := new(pb.Message)
282 - if err := r.ReadMsg(pmes); err != nil {
283 - log.Debugf("Failed to decode protobuf message: %v", err)
284 - return nil
285 - }
286 -
287 - // Print out diagnostic
288 - log.Infof("[peer: %s] Got message from [%s]\n",
289 - d.self.Pretty(), s.Conn().RemotePeer())
290 -
291 - // Make sure we havent already handled this request to prevent loops
292 - if err := d.startDiag(pmes.GetDiagID()); err != nil {
293 - return nil
294 - }
295 -
296 - resp := newMessage(pmes.GetDiagID())
297 - resp.Data = d.getDiagInfo().Marshal()
298 - if err := w.WriteMsg(resp); err != nil {
299 - log.Debugf("Failed to write protobuf message over stream: %s", err)
300 - return err
301 - }
302 -
303 - timeout := pmes.GetTimeoutDuration()
304 - if timeout < HopTimeoutDecrement {
305 - return fmt.Errorf("timeout too short: %s", timeout)
306 - }
307 - ctx, cancel := context.WithTimeout(ctx, timeout)
308 - defer cancel()
309 - pmes.SetTimeoutDuration(timeout - HopTimeoutDecrement)
310 -
311 - dpeers, err := d.getDiagnosticFromPeers(ctx, d.getPeers(), pmes)
312 - if err != nil {
313 - log.Debugf("diagnostic from peers err: %s", err)
314 - return err
315 - }
316 - for b := range dpeers {
317 - resp := newMessage(pmes.GetDiagID())
318 - resp.Data = b.Marshal()
319 - if err := w.WriteMsg(resp); err != nil {
320 - log.Debugf("Failed to write protobuf message over stream: %s", err)
321 - return err
322 - }
323 - }
324 -
325 - return nil
326 -}
327 -
328 -func (d *Diagnostics) startDiag(id string) error {
329 - d.diagLock.Lock()
330 - _, found := d.diagMap[id]
331 - if found {
332 - d.diagLock.Unlock()
333 - return ErrAlreadyRunning
334 - }
335 - d.diagMap[id] = time.Now()
336 - d.diagLock.Unlock()
337 - return nil
338 -}
339 -
340 -func (d *Diagnostics) handleNewStream(s inet.Stream) {
341 - d.HandleMessage(context.Background(), s)
342 - s.Close()
343 -}
diagnostics/pb/Rules.mk deleted
-8
@@ -1,8 +0,0 @@
1 -include mk/header.mk
2 -
3 -PB_$(d) = $(wildcard $(d)/*.proto)
4 -TGTS_$(d) = $(PB_$(d):.proto=.pb.go)
5 -
6 -#DEPS_GO += $(TGTS_$(d))
7 -
8 -include mk/footer.mk
diagnostics/pb/diagnostics.pb.go deleted
-56
@@ -1,56 +0,0 @@
1 -// Code generated by protoc-gen-gogo.
2 -// source: diagnostics.proto
3 -// DO NOT EDIT!
4 -
5 -/*
6 -Package diagnostics_pb is a generated protocol buffer package.
7 -
8 -It is generated from these files:
9 - diagnostics.proto
10 -
11 -It has these top-level messages:
12 - Message
13 -*/
14 -package diagnostics_pb
15 -
16 -import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
17 -import math "math"
18 -
19 -// Reference imports to suppress errors if they are not otherwise used.
20 -var _ = proto.Marshal
21 -var _ = math.Inf
22 -
23 -type Message struct {
24 - DiagID *string `protobuf:"bytes,1,req" json:"DiagID,omitempty"`
25 - Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"`
26 - Timeout *int64 `protobuf:"varint,3,opt" json:"Timeout,omitempty"`
27 - XXX_unrecognized []byte `json:"-"`
28 -}
29 -
30 -func (m *Message) Reset() { *m = Message{} }
31 -func (m *Message) String() string { return proto.CompactTextString(m) }
32 -func (*Message) ProtoMessage() {}
33 -
34 -func (m *Message) GetDiagID() string {
35 - if m != nil && m.DiagID != nil {
36 - return *m.DiagID
37 - }
38 - return ""
39 -}
40 -
41 -func (m *Message) GetData() []byte {
42 - if m != nil {
43 - return m.Data
44 - }
45 - return nil
46 -}
47 -
48 -func (m *Message) GetTimeout() int64 {
49 - if m != nil && m.Timeout != nil {
50 - return *m.Timeout
51 - }
52 - return 0
53 -}
54 -
55 -func init() {
56 -}
diagnostics/pb/diagnostics.proto deleted
-7
@@ -1,7 +0,0 @@
1 -package diagnostics.pb;
2 -
3 -message Message {
4 - required string DiagID = 1;
5 - optional bytes Data = 2;
6 - optional int64 Timeout = 3; // in nanoseconds
7 -}
diagnostics/pb/timeout.go deleted
-14
@@ -1,14 +0,0 @@
1 -package diagnostics_pb
2 -
3 -import (
4 - "time"
5 -)
6 -
7 -func (m *Message) GetTimeoutDuration() time.Duration {
8 - return time.Duration(m.GetTimeout())
9 -}
10 -
11 -func (m *Message) SetTimeoutDuration(t time.Duration) {
12 - it := int64(t)
13 - m.Timeout = &it
14 -}
diagnostics/vis.go deleted
-143
@@ -1,143 +0,0 @@
1 -package diagnostics
2 -
3 -import (
4 - "encoding/json"
5 - "fmt"
6 - "io"
7 -
8 - rtable "gx/ipfs/QmXKSwZVoHCTne4jTLzDtMc2K6paEZ2QaUMQfJ4ogYd28n/go-libp2p-kbucket"
9 - peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
10 -)
11 -
12 -type node struct {
13 - Name string `json:"name"`
14 - Value uint64 `json:"value"`
15 - RtKey string `json:"rtkey"`
16 -}
17 -
18 -type link struct {
19 - Source int `json:"source"`
20 - Target int `json:"target"`
21 - Value int `json:"value"`
22 -}
23 -
24 -func GetGraphJson(dinfo []*DiagInfo) []byte {
25 - out := make(map[string]interface{})
26 - names := make(map[string]int)
27 - var nodes []*node
28 - for _, di := range dinfo {
29 - names[di.ID] = len(nodes)
30 - val := di.BwIn + di.BwOut + 10
31 - // include the routing table key, for proper routing table display
32 - rtk := peer.ID(rtable.ConvertPeerID(peer.ID(di.ID))).Pretty()
33 - nodes = append(nodes, &node{Name: di.ID, Value: val, RtKey: rtk})
34 - }
35 -
36 - var links []*link
37 - linkexists := make([][]bool, len(nodes))
38 - for i := range linkexists {
39 - linkexists[i] = make([]bool, len(nodes))
40 - }
41 -
42 - for _, di := range dinfo {
43 - myid := names[di.ID]
44 - for _, con := range di.Connections {
45 - thisid := names[con.ID]
46 - if !linkexists[thisid][myid] {
47 - links = append(links, &link{
48 - Source: myid,
49 - Target: thisid,
50 - Value: 3,
51 - })
52 - linkexists[myid][thisid] = true
53 - }
54 - }
55 - }
56 -
57 - out["nodes"] = nodes
58 - out["links"] = links
59 -
60 - b, err := json.Marshal(out)
61 - if err != nil {
62 - panic(err)
63 - }
64 -
65 - return b
66 -}
67 -
68 -type DotWriter struct {
69 - W io.Writer
70 - err error
71 -}
72 -
73 -// Write writes a buffer to the internal writer.
74 -// It handles errors as in: http://blog.golang.org/errors-are-values
75 -func (w *DotWriter) Write(buf []byte) (n int, err error) {
76 - if w.err == nil {
77 - n, w.err = w.W.Write(buf)
78 - }
79 - return n, w.err
80 -}
81 -
82 -// WriteS writes a string
83 -func (w *DotWriter) WriteS(s string) (n int, err error) {
84 - return w.Write([]byte(s))
85 -}
86 -
87 -func (w *DotWriter) WriteNetHeader(dinfo []*DiagInfo) error {
88 - label := fmt.Sprintf("Nodes: %d\\l", len(dinfo))
89 -
90 - w.WriteS("subgraph cluster_L { ")
91 - w.WriteS("L [shape=box fontsize=32 label=\"" + label + "\"] ")
92 - w.WriteS("}\n")
93 - return w.err
94 -}
95 -
96 -func (w *DotWriter) WriteNode(i int, di *DiagInfo) error {
97 - box := "[label=\"%s\n%d conns\" fontsize=8 shape=box tooltip=\"%s (%d conns)\"]"
98 - box = fmt.Sprintf(box, di.ID, len(di.Connections), di.ID, len(di.Connections))
99 -
100 - w.WriteS(fmt.Sprintf("N%d %s\n", i, box))
101 - return w.err
102 -}
103 -
104 -func (w *DotWriter) WriteEdge(i, j int, di *DiagInfo, conn connDiagInfo) error {
105 -
106 - n := fmt.Sprintf("%s ... %s (%d)", di.ID, conn.ID, conn.Latency)
107 - s := "[label=\" %d\" weight=%d tooltip=\"%s\" labeltooltip=\"%s\" style=\"dotted\"]"
108 - s = fmt.Sprintf(s, conn.Latency, conn.Count, n, n)
109 -
110 - w.WriteS(fmt.Sprintf("N%d -> N%d %s\n", i, j, s))
111 - return w.err
112 -}
113 -
114 -func (w *DotWriter) WriteGraph(dinfo []*DiagInfo) error {
115 - w.WriteS("digraph \"diag-net\" {\n")
116 - w.WriteNetHeader(dinfo)
117 -
118 - idx := make(map[string]int)
119 - for i, di := range dinfo {
120 - if _, found := idx[di.ID]; found {
121 - log.Debugf("DotWriter skipped duplicate %s", di.ID)
122 - continue
123 - }
124 -
125 - idx[di.ID] = i
126 - w.WriteNode(i, di)
127 - }
128 -
129 - for i, di := range dinfo {
130 - for _, conn := range di.Connections {
131 - j, found := idx[conn.ID]
132 - if !found { // if we didnt get it earlier...
133 - j = len(idx)
134 - idx[conn.ID] = j
135 - }
136 -
137 - w.WriteEdge(i, j, di, conn)
138 - }
139 - }
140 -
141 - w.WriteS("}")
142 - return w.err
143 -}