]> Sergey Matveev's repositories - btrtrc.git/blobdiff - peer.go
Relax TestTcpSimultaneousOpen
[btrtrc.git] / peer.go
diff --git a/peer.go b/peer.go
index dbff1ba155efda1a59312c234c312bad57f61509..d59c5c4c336ac594b871a48dafd489f9e114a382 100644 (file)
--- a/peer.go
+++ b/peer.go
@@ -21,7 +21,7 @@ import (
        "github.com/anacrolix/torrent/mse"
        pp "github.com/anacrolix/torrent/peer_protocol"
        request_strategy "github.com/anacrolix/torrent/request-strategy"
-       "github.com/anacrolix/torrent/typed-roaring"
+       typedRoaring "github.com/anacrolix/torrent/typed-roaring"
 )
 
 type (
@@ -86,7 +86,6 @@ type (
                peerChoking           bool
                peerRequests          map[Request]*peerRequestState
                PeerPrefersEncryption bool // as indicated by 'e' field in extension handshake
-               PeerListenPort        int
                // The highest possible number of pieces the torrent could have based on
                // communication with the peer. Generally only useful until we have the
                // torrent info.
@@ -117,6 +116,7 @@ type (
 )
 
 const (
+       PeerSourceUtHolepunch     = "C"
        PeerSourceTracker         = "Tr"
        PeerSourceIncoming        = "I"
        PeerSourceDhtGetPeers     = "Hg" // Peers we found by searching a DHT.
@@ -126,6 +126,13 @@ const (
        PeerSourceDirect = "M"
 )
 
+// Returns the Torrent a Peer belongs to. Shouldn't change for the lifetime of the Peer. May be nil
+// if we are the receiving end of a connection and the handshake hasn't been received or accepted
+// yet.
+func (p *Peer) Torrent() *Torrent {
+       return p.t
+}
+
 func (p *Peer) initRequestState() {
        p.requestState.Requests = &peerRequests{}
 }
@@ -268,7 +275,7 @@ func (cn *Peer) iterContiguousPieceRequests(f func(piece pieceIndex, count int))
        next(None[pieceIndex]())
 }
 
-func (cn *Peer) writeStatus(w io.Writer, t *Torrent) {
+func (cn *Peer) writeStatus(w io.Writer) {
        // \t isn't preserved in <pre> blocks?
        if cn.closed.IsSet() {
                fmt.Fprint(w, "CLOSED: ")
@@ -317,6 +324,9 @@ func (p *Peer) close() {
        if p.updateRequestsTimer != nil {
                p.updateRequestsTimer.Stop()
        }
+       for _, prs := range p.peerRequests {
+               prs.allocReservation.Drop()
+       }
        p.peerImpl.onClose()
        if p.t != nil {
                p.t.decPeerPieceAvailability(p)
@@ -512,7 +522,7 @@ func (cn *Peer) peerPiecesChanged() {
 func (cn *Peer) postHandshakeStats(f func(*ConnStats)) {
        t := cn.t
        f(&t.stats)
-       f(&t.cl.stats)
+       f(&t.cl.connStats)
 }
 
 // All ConnStats that include this connection. Some objects are not known