"strings"
"time"
+ "github.com/anacrolix/missinggo/perf"
+
"github.com/anacrolix/dht"
"github.com/anacrolix/dht/krpc"
"github.com/anacrolix/log"
}()
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-- {
// 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)
}
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)
"golang.org/x/net/proxy"
"github.com/anacrolix/missinggo"
+ "github.com/anacrolix/missinggo/perf"
)
type dialer interface {
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)
}
}
_, ret = t.conns[c]
delete(t.conns, c)
+ torrent.Add("deleted connections", 1)
c.deleteAllRequests()
if len(t.conns) == 0 {
t.assertNoPendingRequests()
}
// 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")
}