}
}
+func regularConnString(nc net.Conn) string {
+ return fmt.Sprintf("%s-%s", nc.LocalAddr(), nc.RemoteAddr())
+}
+
func (cl *Client) incomingConnection(nc net.Conn) {
defer nc.Close()
if tc, ok := nc.(*net.TCPConn); ok {
tc.SetLinger(0)
}
- c := cl.newConnection(nc, false, nc.RemoteAddr(), nc.RemoteAddr().Network())
+ c := cl.newConnection(nc, false, nc.RemoteAddr(), nc.RemoteAddr().Network(),
+ regularConnString(nc))
c.Discovery = PeerSourceIncoming
cl.runReceivedConn(c)
}
// Performs initiator handshakes and returns a connection. Returns nil *connection if no connection
// for valid reasons.
-func (cl *Client) handshakesConnection(ctx context.Context, nc net.Conn, t *Torrent, encryptHeader bool, remoteAddr net.Addr, network string) (c *PeerConn, err error) {
- c = cl.newConnection(nc, true, remoteAddr, network)
+func (cl *Client) handshakesConnection(ctx context.Context, nc net.Conn, t *Torrent, encryptHeader bool, remoteAddr net.Addr,
+ network, connString string,
+) (c *PeerConn, err error) {
+ c = cl.newConnection(nc, true, remoteAddr, network, connString)
c.headerEncrypted = encryptHeader
ctx, cancel := context.WithTimeout(ctx, cl.config.HandshakesTimeout)
defer cancel()
return
}
-// Returns nil connection and nil error if no connection could be established
-// for valid reasons.
+// Returns nil connection and nil error if no connection could be established for valid reasons.
func (cl *Client) establishOutgoingConnEx(t *Torrent, addr net.Addr, obfuscatedHeader bool) (*PeerConn, error) {
dialCtx, cancel := context.WithTimeout(context.Background(), func() time.Duration {
cl.rLock()
}
return nil, errors.New("dial failed")
}
- c, err := cl.handshakesConnection(context.Background(), nc, t, obfuscatedHeader, addr, dr.Network)
+ c, err := cl.handshakesConnection(context.Background(), nc, t, obfuscatedHeader, addr, dr.Network, regularConnString(nc))
if err != nil {
nc.Close()
}
cl.badPeerIPs[ip.String()] = struct{}{}
}
-func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr net.Addr, network string) (c *PeerConn) {
+func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr net.Addr, network, connString string) (c *PeerConn) {
c = &PeerConn{
conn: nc,
outgoing: outgoing,
writeBuffer: new(bytes.Buffer),
remoteAddr: remoteAddr,
network: network,
+ connString: connString,
}
c.logger = cl.logger.WithValues(c,
log.Debug, // I want messages to default to debug, and can set it here as it's only used by new code