}
}
-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())
}
tc.SetLinger(0)
}
c := cl.newConnection(nc, false, nc.RemoteAddr(), nc.RemoteAddr().Network(),
- regularConnString(nc))
+ regularNetConnPeerConnConnString(nc))
c.Discovery = PeerSourceIncoming
cl.runReceivedConn(c)
}
}
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()
}
RemoteAddr: remoteAddr,
network: network,
- connString: connString,
},
+ connString: connString,
conn: nc,
writeBuffer: new(bytes.Buffer),
}
peerImpl
- connString string
outgoing bool
network string
RemoteAddr net.Addr
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.
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,
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() {
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),