github.com/anacrolix/torrent@v1.61.0/peer-impl.go (about) 1 package torrent 2 3 import ( 4 "io" 5 6 "github.com/RoaringBitmap/roaring" 7 8 "github.com/anacrolix/torrent/metainfo" 9 pp "github.com/anacrolix/torrent/peer_protocol" 10 ) 11 12 // Contains implementation details that differ between peer types, like WebSeeds and regular 13 // BitTorrent protocol connections. These methods are embedded in the child types of Peer for legacy 14 // expectations that they exist on the child type. Some methods are underlined to avoid collisions 15 // with legacy PeerConn methods. New methods and calls that are fixed up should be migrated over to 16 // newHotPeerImpl. 17 type legacyPeerImpl interface { 18 // Whether the peer should be told to update requests. Sometimes this is skipped if it's high 19 // priority adjustments to requests. This is kind of only relevant to PeerConn but hasn't been 20 // fully migrated over yet. 21 isLowOnRequests() bool 22 // Notify that the peers requests should be updated for the provided reason. 23 onNeedUpdateRequests(reason updateRequestReason) 24 25 // handleCancel initiates cancellation of a request 26 handleCancel(ri RequestIndex) 27 cancelAllRequests() 28 connectionFlags() string 29 onClose() 30 onGotInfo(info *metainfo.Info) 31 // Drop connection. This may be a no-op if there is no connection. 32 drop() 33 // Rebuke the peer 34 providedBadData() 35 String() string 36 // Per peer-impl lines for WriteStatus. 37 peerImplStatusLines() []string 38 peerImplWriteStatus(w io.Writer) 39 40 // All if the peer should have everything, known if we know that for a fact. For example, we can 41 // guess at how many pieces are in a torrent, and assume they have all pieces based on them 42 // having sent haves for everything, but we don't know for sure. But if they send a have-all 43 // message, then it's clear that they do. 44 peerHasAllPieces() (all, known bool) 45 peerPieces() *roaring.Bitmap 46 } 47 48 // Abstract methods implemented by subclasses of Peer. 49 type newHotPeerImpl interface { 50 lastWriteUploadRate() float64 51 // Bookkeeping for a chunk being received and any specific checks. 52 checkReceivedChunk(ri RequestIndex, msg *pp.Message, req Request) (intended bool, err error) 53 // Whether we're expecting to receive chunks because we have outstanding requests. Used for 54 // example to calculate download rate. 55 expectingChunks() bool 56 allConnStatsImplField(*AllConnStats) *ConnStats 57 }