@cryptotaxi247 / kubo / commits / ab824a51f

added debug printing to peerstream

Juan Batiz-Benet committed Jan 12, 2015 at 10:53 UTC ab824a51ffc385382ca29f536b6fa355929dd6f3
5 files changed +69 -1
Godeps/Godeps.json
+1 -1
@@ -144,7 +144,7 @@
144 },
145 {
146 "ImportPath": "github.com/jbenet/go-peerstream",
147 - "Rev": "cddf450fca891e45aa471d882dae2c28ac642fb4"
147 + "Rev": "ccc044c2a5999f36743881ff73568660a581f2f2"
148 },
149 {
150 "ImportPath": "github.com/jbenet/go-random",
Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go
+10
@@ -2,6 +2,7 @@ package peerstream
2
3 import (
4 "errors"
5 + "fmt"
6 "net"
7 "sync"
8
@@ -55,6 +56,15 @@ func newConn(nconn net.Conn, tconn pst.Conn, s *Swarm) *Conn {
56 }
57 }
58
59 +// String returns a string representation of the Conn
60 +func (c *Conn) String() string {
61 + c.streamLock.RLock()
62 + ls := len(c.streams)
63 + c.streamLock.RUnlock()
64 + f := "<peerstream.Conn %d streams %s <--> %s>"
65 + return fmt.Sprintf(f, ls, c.netConn.LocalAddr(), c.netConn.RemoteAddr())
66 +}
67 +
68 // Swarm returns the Swarm associated with this Conn
69 func (c *Conn) Swarm() *Swarm {
70 return c.swarm
Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go
+6
@@ -24,6 +24,12 @@ func newListener(nl net.Listener, s *Swarm) *Listener {
24 }
25 }
26
27 +// String returns a string representation of the Listener
28 +func (l *Listener) String() string {
29 + f := "<peerstream.Listener %s>"
30 + return fmt.Sprintf(f, l.netList.Addr())
31 +}
32 +
33 // NetListener is the underlying net.Listener
34 func (l *Listener) NetListener() net.Listener {
35 return l.netList
Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go
+8
@@ -1,6 +1,8 @@
1 package peerstream
2
3 import (
4 + "fmt"
5 +
6 pst "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
7 )
8
@@ -31,6 +33,12 @@ func newStream(ss pst.Stream, c *Conn) *Stream {
33 return s
34 }
35
36 +// String returns a string representation of the Stream
37 +func (s *Stream) String() string {
38 + f := "<peerstream.Stream %s <--> %s>"
39 + return fmt.Sprintf(f, s.conn.NetConn().LocalAddr(), s.conn.NetConn().RemoteAddr())
40 +}
41 +
42 // SPDYStream returns the underlying *spdystream.Stream
43 func (s *Stream) Stream() pst.Stream {
44 return s.pstStream
Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go
+44
@@ -2,6 +2,7 @@ package peerstream
2
3 import (
4 "errors"
5 + "fmt"
6 "net"
7 "sync"
8 "time"
@@ -56,6 +57,49 @@ func NewSwarm(t pst.Transport) *Swarm {
57 return s
58 }
59
60 +// String returns a string with various internal stats
61 +func (s *Swarm) String() string {
62 + s.listenerLock.Lock()
63 + ls := len(s.listeners)
64 + s.listenerLock.Unlock()
65 +
66 + s.connLock.Lock()
67 + cs := len(s.conns)
68 + s.connLock.Unlock()
69 +
70 + s.streamLock.Lock()
71 + ss := len(s.streams)
72 + s.streamLock.Unlock()
73 +
74 + str := "<peerstream.Swarm %d listeners %d conns %d streams>"
75 + return fmt.Sprintf(str, ls, cs, ss)
76 +}
77 +
78 +// Dump returns a string with all the internal state
79 +func (s *Swarm) Dump() string {
80 + str := s.String() + "\n"
81 +
82 + s.listenerLock.Lock()
83 + for l, _ := range s.listeners {
84 + str += fmt.Sprintf("\t%s %v\n", l, l.Groups())
85 + }
86 + s.listenerLock.Unlock()
87 +
88 + s.connLock.Lock()
89 + for c, _ := range s.conns {
90 + str += fmt.Sprintf("\t%s %v\n", c, c.Groups())
91 + }
92 + s.connLock.Unlock()
93 +
94 + s.streamLock.Lock()
95 + for ss, _ := range s.streams {
96 + str += fmt.Sprintf("\t%s %v\n", ss, ss.Groups())
97 + }
98 + s.streamLock.Unlock()
99 +
100 + return str
101 +}
102 +
103 // SetStreamHandler assigns the stream handler in the swarm.
104 // The handler assumes responsibility for closing the stream.
105 // This need not happen at the end of the handler, leaving the