mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
added debug printing to peerstream
This commit is contained in:
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -144,7 +144,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-peerstream",
|
"ImportPath": "github.com/jbenet/go-peerstream",
|
||||||
"Rev": "cddf450fca891e45aa471d882dae2c28ac642fb4"
|
"Rev": "ccc044c2a5999f36743881ff73568660a581f2f2"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-random",
|
"ImportPath": "github.com/jbenet/go-random",
|
||||||
|
10
Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go
generated
vendored
10
Godeps/_workspace/src/github.com/jbenet/go-peerstream/conn.go
generated
vendored
@ -2,6 +2,7 @@ package peerstream
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"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 := "<peerstream.Conn %d streams %s <--> %s>"
|
||||||
|
return fmt.Sprintf(f, ls, c.netConn.LocalAddr(), c.netConn.RemoteAddr())
|
||||||
|
}
|
||||||
|
|
||||||
// Swarm returns the Swarm associated with this Conn
|
// Swarm returns the Swarm associated with this Conn
|
||||||
func (c *Conn) Swarm() *Swarm {
|
func (c *Conn) Swarm() *Swarm {
|
||||||
return c.swarm
|
return c.swarm
|
||||||
|
6
Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go
generated
vendored
6
Godeps/_workspace/src/github.com/jbenet/go-peerstream/listener.go
generated
vendored
@ -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 := "<peerstream.Listener %s>"
|
||||||
|
return fmt.Sprintf(f, l.netList.Addr())
|
||||||
|
}
|
||||||
|
|
||||||
// NetListener is the underlying net.Listener
|
// NetListener is the underlying net.Listener
|
||||||
func (l *Listener) NetListener() net.Listener {
|
func (l *Listener) NetListener() net.Listener {
|
||||||
return l.netList
|
return l.netList
|
||||||
|
8
Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go
generated
vendored
8
Godeps/_workspace/src/github.com/jbenet/go-peerstream/stream.go
generated
vendored
@ -1,6 +1,8 @@
|
|||||||
package peerstream
|
package peerstream
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
pst "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
|
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
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a string representation of the Stream
|
||||||
|
func (s *Stream) String() string {
|
||||||
|
f := "<peerstream.Stream %s <--> %s>"
|
||||||
|
return fmt.Sprintf(f, s.conn.NetConn().LocalAddr(), s.conn.NetConn().RemoteAddr())
|
||||||
|
}
|
||||||
|
|
||||||
// SPDYStream returns the underlying *spdystream.Stream
|
// SPDYStream returns the underlying *spdystream.Stream
|
||||||
func (s *Stream) Stream() pst.Stream {
|
func (s *Stream) Stream() pst.Stream {
|
||||||
return s.pstStream
|
return s.pstStream
|
||||||
|
44
Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go
generated
vendored
44
Godeps/_workspace/src/github.com/jbenet/go-peerstream/swarm.go
generated
vendored
@ -2,6 +2,7 @@ package peerstream
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -56,6 +57,49 @@ func NewSwarm(t pst.Transport) *Swarm {
|
|||||||
return s
|
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 := "<peerstream.Swarm %d listeners %d conns %d streams>"
|
||||||
|
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.
|
// SetStreamHandler assigns the stream handler in the swarm.
|
||||||
// The handler assumes responsibility for closing the stream.
|
// The handler assumes responsibility for closing the stream.
|
||||||
// This need not happen at the end of the handler, leaving the
|
// This need not happen at the end of the handler, leaving the
|
||||||
|
Reference in New Issue
Block a user