"crypto/rand"
"encoding/hex"
"errors"
+ "expvar"
"fmt"
"io"
"log"
return
}
+var (
+ dialledFirstUtp = expvar.NewInt("dialledFirstUtp")
+ dialledFirstNotUtp = expvar.NewInt("dialledFirstNotUtp")
+)
+
// Returns a connection over UTP or TCP, whichever is first to connect.
func (cl *Client) dialFirst(ctx context.Context, addr string) (conn net.Conn, utp bool) {
ctx, cancel := context.WithCancel(ctx)
}
conn = res.Conn
utp = res.UTP
+ if conn != nil {
+ if utp {
+ dialledFirstUtp.Add(1)
+ } else {
+ dialledFirstNotUtp.Add(1)
+ }
+ }
return
}
return
}
+var (
+ initiatedConnWithPreferredHeaderEncryption = expvar.NewInt("initiatedConnWithPreferredHeaderEncryption")
+ initiatedConnWithFallbackHeaderEncryption = expvar.NewInt("initiatedConnWithFallbackHeaderEncryption")
+)
+
// Returns nil connection and nil error if no connection could be established
// for valid reasons.
func (cl *Client) establishOutgoingConn(t *Torrent, addr string) (c *connection, err error) {
nc.Close()
return
} else if c != nil {
+ initiatedConnWithPreferredHeaderEncryption.Add(1)
return
}
nc.Close()
if err != nil || c == nil {
nc.Close()
}
+ if err == nil && c != nil {
+ initiatedConnWithFallbackHeaderEncryption.Add(1)
+ }
return
}