Add lots of new expvars and perf timers
This commit is contained in:
parent
81dcb9b779
commit
ad5e44eaf5
23
client.go
23
client.go
|
@ -14,6 +14,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/missinggo/perf"
|
||||
|
||||
"github.com/anacrolix/dht"
|
||||
"github.com/anacrolix/dht/krpc"
|
||||
"github.com/anacrolix/log"
|
||||
|
@ -541,9 +543,12 @@ func (cl *Client) dialFirst(ctx context.Context, addr string) net.Conn {
|
|||
}()
|
||||
var res dialResult
|
||||
// Wait for a successful connection.
|
||||
for ; left > 0 && res.Conn == nil; left-- {
|
||||
res = <-resCh
|
||||
}
|
||||
func() {
|
||||
defer perf.ScopeTimer()()
|
||||
for ; left > 0 && res.Conn == nil; left-- {
|
||||
res = <-resCh
|
||||
}
|
||||
}()
|
||||
// There are still incompleted dials.
|
||||
go func() {
|
||||
for ; left > 0; left-- {
|
||||
|
@ -709,6 +714,7 @@ func (cl *Client) forSkeys(f func([]byte) bool) {
|
|||
|
||||
// Do encryption and bittorrent handshakes as receiver.
|
||||
func (cl *Client) receiveHandshakes(c *connection) (t *Torrent, err error) {
|
||||
defer perf.ScopeTimerErr(&err)()
|
||||
var rw io.ReadWriter
|
||||
rw, c.headerEncrypted, c.cryptoMethod, err = handleEncryption(c.rw(), cl.forSkeys, cl.config.EncryptionPolicy)
|
||||
c.setRW(rw)
|
||||
|
@ -756,18 +762,27 @@ func (cl *Client) runReceivedConn(c *connection) {
|
|||
}
|
||||
t, err := cl.receiveHandshakes(c)
|
||||
if err != nil {
|
||||
log.Fmsg("error receiving handshakes: %s", err).AddValue(debugLogValue).Add("network", c.remoteAddr().Network()).Log(cl.logger)
|
||||
log.Fmsg(
|
||||
"error receiving handshakes: %s", err,
|
||||
).AddValue(
|
||||
debugLogValue,
|
||||
).Add(
|
||||
"network", c.remoteAddr().Network(),
|
||||
).Log(cl.logger)
|
||||
torrent.Add("error receiving handshake", 1)
|
||||
cl.mu.Lock()
|
||||
cl.onBadAccept(c.remoteAddr())
|
||||
cl.mu.Unlock()
|
||||
return
|
||||
}
|
||||
if t == nil {
|
||||
torrent.Add("received handshake for unloaded torrent", 1)
|
||||
cl.mu.Lock()
|
||||
cl.onBadAccept(c.remoteAddr())
|
||||
cl.mu.Unlock()
|
||||
return
|
||||
}
|
||||
torrent.Add("received handshake for loaded torrent", 1)
|
||||
cl.mu.Lock()
|
||||
defer cl.mu.Unlock()
|
||||
cl.runHandshookConn(c, t)
|
||||
|
|
|
@ -18,6 +18,8 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/anacrolix/missinggo/perf"
|
||||
|
||||
"github.com/bradfitz/iter"
|
||||
)
|
||||
|
||||
|
@ -537,6 +539,7 @@ func InitiateHandshake(rw io.ReadWriter, skey []byte, initialPayload []byte, cry
|
|||
ia: initialPayload,
|
||||
cryptoProvides: cryptoProvides,
|
||||
}
|
||||
defer perf.ScopeTimerErr(&err)()
|
||||
return h.Do()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"golang.org/x/net/proxy"
|
||||
|
||||
"github.com/anacrolix/missinggo"
|
||||
"github.com/anacrolix/missinggo/perf"
|
||||
)
|
||||
|
||||
type dialer interface {
|
||||
|
@ -169,7 +170,8 @@ type utpSocketSocket struct {
|
|||
d proxy.Dialer
|
||||
}
|
||||
|
||||
func (me utpSocketSocket) dial(ctx context.Context, addr string) (net.Conn, error) {
|
||||
func (me utpSocketSocket) dial(ctx context.Context, addr string) (conn net.Conn, err error) {
|
||||
defer perf.ScopeTimerErr(&err)()
|
||||
if me.d != nil {
|
||||
return me.d.Dial(me.network, addr)
|
||||
}
|
||||
|
|
|
@ -1222,6 +1222,7 @@ func (t *Torrent) deleteConnection(c *connection) (ret bool) {
|
|||
}
|
||||
_, ret = t.conns[c]
|
||||
delete(t.conns, c)
|
||||
torrent.Add("deleted connections", 1)
|
||||
c.deleteAllRequests()
|
||||
if len(t.conns) == 0 {
|
||||
t.assertNoPendingRequests()
|
||||
|
@ -1493,7 +1494,12 @@ func (t *Torrent) reconcileHandshakeStats(c *connection) {
|
|||
}
|
||||
|
||||
// Returns true if the connection is added.
|
||||
func (t *Torrent) addConnection(c *connection) error {
|
||||
func (t *Torrent) addConnection(c *connection) (err error) {
|
||||
defer func() {
|
||||
if err == nil {
|
||||
torrent.Add("added connections", 1)
|
||||
}
|
||||
}()
|
||||
if t.closed.IsSet() {
|
||||
return errors.New("torrent closed")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue