]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix conn status string for WebRTC connections
authorMatt Joiner <anacrolix@gmail.com>
Tue, 29 Sep 2020 06:21:54 +0000 (16:21 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 29 Sep 2020 06:21:54 +0000 (16:21 +1000)
client.go
peer-impl.go
peerconn.go
torrent.go
webseed-peer.go

index dff94a1d27a0689a7580292d93be1758688ba5c4..fafb6e2d72d7f94d96cc2d4f5eb67f29b6595622 100644 (file)
--- a/client.go
+++ b/client.go
@@ -495,7 +495,8 @@ func (cl *Client) acceptConnections(l net.Listener) {
        }
 }
 
-func regularConnString(nc net.Conn) string {
+// Creates the PeerConn.connString for a regular net.Conn PeerConn.
+func regularNetConnPeerConnConnString(nc net.Conn) string {
        return fmt.Sprintf("%s-%s", nc.LocalAddr(), nc.RemoteAddr())
 }
 
@@ -505,7 +506,7 @@ func (cl *Client) incomingConnection(nc net.Conn) {
                tc.SetLinger(0)
        }
        c := cl.newConnection(nc, false, nc.RemoteAddr(), nc.RemoteAddr().Network(),
-               regularConnString(nc))
+               regularNetConnPeerConnConnString(nc))
        c.Discovery = PeerSourceIncoming
        cl.runReceivedConn(c)
 }
@@ -704,7 +705,7 @@ func (cl *Client) establishOutgoingConnEx(t *Torrent, addr net.Addr, obfuscatedH
                }
                return nil, errors.New("dial failed")
        }
-       c, err := cl.initiateProtocolHandshakes(context.Background(), nc, t, true, obfuscatedHeader, addr, dr.Network, regularConnString(nc))
+       c, err := cl.initiateProtocolHandshakes(context.Background(), nc, t, true, obfuscatedHeader, addr, dr.Network, regularNetConnPeerConnConnString(nc))
        if err != nil {
                nc.Close()
        }
@@ -1338,8 +1339,8 @@ func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr net.Addr,
 
                        RemoteAddr: remoteAddr,
                        network:    network,
-                       connString: connString,
                },
+               connString:  connString,
                conn:        nc,
                writeBuffer: new(bytes.Buffer),
        }
index 2b65d1ad94c757334d2f7e4d25898d19e4e9c3f2..10a6d249f74bb9dbd7faf455f2cd15ee262135f5 100644 (file)
@@ -19,4 +19,5 @@ type peerImpl interface {
        onGotInfo(*metainfo.Info)
        drop()
        String() string
+       connStatusString() string
 }
index adb60319a6c6110f6dadfac3d686cabcdcc977b9..a54f6fb5d551c58d4cf9a5a701e7e620bb8291df 100644 (file)
@@ -44,7 +44,6 @@ type peer struct {
 
        peerImpl
 
-       connString string
        outgoing   bool
        network    string
        RemoteAddr net.Addr
@@ -86,11 +85,9 @@ type peer struct {
        pex              pexConnState
 
        // Stuff controlled by the remote peer.
-       PeerID                PeerID
        peerInterested        bool
        peerChoking           bool
        peerRequests          map[request]struct{}
-       PeerExtensionBytes    pp.PeerExtensionBits
        PeerPrefersEncryption bool // as indicated by 'e' field in extension handshake
        PeerListenPort        int
        // The pieces the peer has claimed to have.
@@ -116,10 +113,18 @@ type peer struct {
        logger log.Logger
 }
 
-// Maintains the state of a connection with a peer.
+// Maintains the state of a BitTorrent-protocol based connection with a peer.
 type PeerConn struct {
        peer
 
+       // A string that should identify the PeerConn's net.Conn endpoints. The net.Conn could
+       // be wrapping WebRTC, uTP, or TCP etc. Used in writing the conn status for peers.
+       connString string
+
+       // See BEP 3 etc.
+       PeerID             PeerID
+       PeerExtensionBytes pp.PeerExtensionBits
+
        // The actual Conn, used for closing, and setting socket options.
        conn net.Conn
        // The Reader and Writer for this Conn, with hooks installed for stats,
@@ -132,6 +137,10 @@ type PeerConn struct {
        writerCond  sync.Cond
 }
 
+func (cn *PeerConn) connStatusString() string {
+       return fmt.Sprintf("%+-55q %s %s\n", cn.PeerID, cn.PeerExtensionBytes, cn.connString)
+}
+
 func (cn *peer) updateExpectingChunks() {
        if cn.expectingChunks() {
                if cn.lastStartedExpectingToReceiveChunks.IsZero() {
@@ -295,7 +304,7 @@ func (cn *peer) downloadRate() float64 {
 
 func (cn *peer) writeStatus(w io.Writer, t *Torrent) {
        // \t isn't preserved in <pre> blocks?
-       fmt.Fprintf(w, "%+-55q %s %s\n", cn.PeerID, cn.PeerExtensionBytes, cn.connString)
+       fmt.Fprintln(w, cn.connStatusString())
        fmt.Fprintf(w, "    last msg: %s, connected: %s, last helpful: %s, itime: %s, etime: %s\n",
                eventAgeString(cn.lastMessageReceived),
                eventAgeString(cn.completedHandshake),
index 493d7e7fa3567ede209834ea6716f83bc3ac503e..639e330e21ad61f2cbeb2ea778c7b4554e9e3846 100644 (file)
@@ -2036,7 +2036,6 @@ func (t *Torrent) addWebSeed(url string) {
        ws := webseedPeer{
                peer: peer{
                        t:                        t,
-                       connString:               url,
                        outgoing:                 true,
                        network:                  "http",
                        reconciledHandshakeStats: true,
index e5ba748e5df9fc4f71873368fed9a23b6b0f6b43..064a197cf8e7c79b50c1ad3ecfbdf1dea01521c8 100644 (file)
@@ -20,6 +20,10 @@ type webseedPeer struct {
 
 var _ peerImpl = (*webseedPeer)(nil)
 
+func (me *webseedPeer) connStatusString() string {
+       return me.client.Url
+}
+
 func (ws *webseedPeer) String() string {
        return fmt.Sprintf("webseed peer for %q", ws.client.Url)
 }