@cryptotaxi247 / kubo / commits / 4da261001

mocknet printer for printing

Juan Batiz-Benet committed Dec 17, 2014 at 22:27 UTC 4da261001f54e2535069a73ceffafef4b5007913
1 file changed +36
net/mock/mock_printer.go new
+36
@@ -0,0 +1,36 @@
1 +package mocknet
2 +
3 +import (
4 + "fmt"
5 + "io"
6 +
7 + inet "github.com/jbenet/go-ipfs/net"
8 + peer "github.com/jbenet/go-ipfs/peer"
9 +)
10 +
11 +// separate object so our interfaces are separate :)
12 +type printer struct {
13 + w io.Writer
14 +}
15 +
16 +func (p *printer) MocknetLinks(mn Mocknet) {
17 + links := mn.Links()
18 +
19 + fmt.Fprintf(p.w, "Mocknet link map:\n")
20 + for p1, lm := range links {
21 + fmt.Fprintf(p.w, "\t%s linked to:\n", peer.ID(p1))
22 + for p2, l := range lm {
23 + fmt.Fprintf(p.w, "\t\t%s (%d links)\n", peer.ID(p2), len(l))
24 + }
25 + }
26 + fmt.Fprintf(p.w, "\n")
27 +}
28 +
29 +func (p *printer) NetworkConns(ni inet.Network) {
30 +
31 + fmt.Fprintf(p.w, "%s connected to:\n", ni.LocalPeer())
32 + for _, c := range ni.Conns() {
33 + fmt.Fprintf(p.w, "\t%s (addr: %s)\n", c.RemotePeer(), c.RemoteMultiaddr())
34 + }
35 + fmt.Fprintf(p.w, "\n")
36 +}