diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b078a8d6e..ae9934e3d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -144,7 +144,7 @@ }, { "ImportPath": "github.com/jbenet/go-peerstream", - "Rev": "cddf450fca891e45aa471d882dae2c28ac642fb4" + "Rev": "ccc044c2a5999f36743881ff73568660a581f2f2" }, { "ImportPath": "github.com/jbenet/go-random", diff --git a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go index 183ab4e71..378218e84 100644 --- a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go @@ -2,6 +2,7 @@ package peerstream import ( "errors" + "fmt" "net" "sync" @@ -55,6 +56,15 @@ func newConn(nconn net.Conn, tconn pst.Conn, s *Swarm) *Conn { } } +// String returns a string representation of the Conn +func (c *Conn) String() string { + c.streamLock.RLock() + ls := len(c.streams) + c.streamLock.RUnlock() + f := " %s>" + return fmt.Sprintf(f, ls, c.netConn.LocalAddr(), c.netConn.RemoteAddr()) +} + // Swarm returns the Swarm associated with this Conn func (c *Conn) Swarm() *Swarm { return c.swarm diff --git a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go index 3fad44559..6926c94f0 100644 --- a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go @@ -24,6 +24,12 @@ func newListener(nl net.Listener, s *Swarm) *Listener { } } +// String returns a string representation of the Listener +func (l *Listener) String() string { + f := "" + return fmt.Sprintf(f, l.netList.Addr()) +} + // NetListener is the underlying net.Listener func (l *Listener) NetListener() net.Listener { return l.netList diff --git a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go index 4f4b59dda..de7d540ba 100644 --- a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go @@ -1,6 +1,8 @@ package peerstream import ( + "fmt" + pst "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport" ) @@ -31,6 +33,12 @@ func newStream(ss pst.Stream, c *Conn) *Stream { return s } +// String returns a string representation of the Stream +func (s *Stream) String() string { + f := " %s>" + return fmt.Sprintf(f, s.conn.NetConn().LocalAddr(), s.conn.NetConn().RemoteAddr()) +} + // SPDYStream returns the underlying *spdystream.Stream func (s *Stream) Stream() pst.Stream { return s.pstStream diff --git a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go index 4138043bb..e829e79f1 100644 --- a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go @@ -2,6 +2,7 @@ package peerstream import ( "errors" + "fmt" "net" "sync" "time" @@ -56,6 +57,49 @@ func NewSwarm(t pst.Transport) *Swarm { return s } +// String returns a string with various internal stats +func (s *Swarm) String() string { + s.listenerLock.Lock() + ls := len(s.listeners) + s.listenerLock.Unlock() + + s.connLock.Lock() + cs := len(s.conns) + s.connLock.Unlock() + + s.streamLock.Lock() + ss := len(s.streams) + s.streamLock.Unlock() + + str := "" + return fmt.Sprintf(str, ls, cs, ss) +} + +// Dump returns a string with all the internal state +func (s *Swarm) Dump() string { + str := s.String() + "\n" + + s.listenerLock.Lock() + for l, _ := range s.listeners { + str += fmt.Sprintf("\t%s %v\n", l, l.Groups()) + } + s.listenerLock.Unlock() + + s.connLock.Lock() + for c, _ := range s.conns { + str += fmt.Sprintf("\t%s %v\n", c, c.Groups()) + } + s.connLock.Unlock() + + s.streamLock.Lock() + for ss, _ := range s.streams { + str += fmt.Sprintf("\t%s %v\n", ss, ss.Groups()) + } + s.streamLock.Unlock() + + return str +} + // SetStreamHandler assigns the stream handler in the swarm. // The handler assumes responsibility for closing the stream. // This need not happen at the end of the handler, leaving the