"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 (
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.
)
const (
+ PeerSourceUtHolepunch = "C"
PeerSourceTracker = "Tr"
PeerSourceIncoming = "I"
PeerSourceDhtGetPeers = "Hg" // Peers we found by searching a DHT.
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{}
}
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: ")
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)
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