]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Try to count IPv6 connections
authorMatt Joiner <anacrolix@gmail.com>
Mon, 12 Feb 2018 13:48:21 +0000 (00:48 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 12 Feb 2018 13:48:21 +0000 (00:48 +1100)
client.go
global.go
misc.go

index deb09a3f4649302876d3955d92c3e52f77d21fed..6e8a7c20653bcb1a9cb2598bd6ec910ed0683be3 100644 (file)
--- a/client.go
+++ b/client.go
@@ -441,9 +441,18 @@ func (cl *Client) acceptConnections(l net.Listener, utp bool) {
                        return
                }
                if utp {
-                       acceptUTP.Add(1)
+                       torrent.Add("accepted utp connections", 1)
                } else {
-                       acceptTCP.Add(1)
+                       torrent.Add("accepted tcp connections", 1)
+               }
+               torrent.Add(fmt.Sprintf("accepted conn with network %q", conn.RemoteAddr().Network()), 1)
+               remoteIP := missinggo.AddrIP(conn.RemoteAddr())
+               if remoteIP.To4() != nil {
+                       torrent.Add("accepted conn from ipv4 address", 1)
+               } else if remoteIP.To16() != nil {
+                       torrent.Add("accepted conn from ipv6 address", 1)
+               } else {
+                       torrent.Add("accepted conn from unknown ip address type", 1)
                }
                if cl.config.Debug {
                        log.Printf("accepted connection from %s", conn.RemoteAddr())
@@ -455,7 +464,7 @@ func (cl *Client) acceptConnections(l net.Listener, utp bool) {
                        if cl.config.Debug {
                                log.Printf("rejecting connection from %s", conn.RemoteAddr())
                        }
-                       acceptReject.Add(1)
+                       torrent.Add("rejected accepted connection", 1)
                        conn.Close()
                        continue
                }
@@ -831,6 +840,9 @@ func (cl *Client) runHandshookConn(c *connection, t *Torrent, outgoing bool) {
        c.conn.SetWriteDeadline(time.Time{})
        c.r = deadlineReader{c.conn, c.r}
        completedHandshakeConnectionFlags.Add(c.connectionFlags(), 1)
+       if connIsIpv6(c.conn) {
+               torrent.Add("completed handshake over ipv6", 1)
+       }
        if !t.addConnection(c, outgoing) {
                return
        }
index cab312080c08063156bdc8914916c7a6504103c8..cdd0351386673f7c6790c7df038c5760ebcd8485 100644 (file)
--- a/global.go
+++ b/global.go
@@ -37,10 +37,6 @@ var (
        unsuccessfulDials = expvar.NewInt("dialSuccessful")
        successfulDials   = expvar.NewInt("dialUnsuccessful")
 
-       acceptUTP    = expvar.NewInt("acceptUTP")
-       acceptTCP    = expvar.NewInt("acceptTCP")
-       acceptReject = expvar.NewInt("acceptReject")
-
        peerExtensions                    = expvar.NewMap("peerExtensions")
        completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
        // Count of connections to peer with same client ID.
diff --git a/misc.go b/misc.go
index f3b38bf3666440ce3124d69b033829caf7df85c0..9c618d9ac1c391fd49344ba00798da05596c3750 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -2,8 +2,10 @@ package torrent
 
 import (
        "errors"
+       "log"
        "net"
 
+       "github.com/anacrolix/missinggo"
        "github.com/anacrolix/torrent/metainfo"
        pp "github.com/anacrolix/torrent/peer_protocol"
 )
@@ -123,3 +125,10 @@ func addrCompactIP(addr net.Addr) (string, error) {
        }
        return string(ip.To16()), nil
 }
+
+func connIsIpv6(nc net.Conn) bool {
+       ra := nc.RemoteAddr()
+       log.Printf("network: %q, string: %q", ra.Network(), ra.String())
+       rip := missinggo.AddrIP(ra)
+       return rip.To4() == nil && rip.To16() != nil
+}