TorrentState
State the owning torrent passes into PeerList operations. This is the port of struct torrent_state (include/libtorrent/peer_list.hpp).
libtorrent deliberately routes the small amount of torrent/session context the peer list needs through this struct rather than giving the peer list a pointer to the torrent, so the data structure stays decoupled and unit-testable. We keep that design exactly: every mutating PeerList call that needs to know "are we finished", "how big may the list grow", "what's our external IP" takes a TorrentState.
A couple of fields are outputs written back by the peer list:
firstTimeSeen is set by PeerList.addPeer to report whether the peer was brand new;
erased collects every TorrentPeer removed during the call, so the caller can drop any dangling references (in libtorrent, e.g. the piece picker).
Properties
Whether multiple connections to the same IP (different ports) are allowed.
Output: every TorrentPeer removed from the list during the call. The caller should clear references to these and then clearErased.
Output: set by PeerList.addPeer. True iff the peer was newly added.
Our external IP, for BEP 40 peer ranking.
True if the torrent has finished downloading (affects seed handling).
Diagnostic counter: how many peer-list slots were scanned this call.
Failcount at or above which a peer is no longer a connect candidate.
Maximum number of peers to keep in the list before weeding. 0 = unlimited.
Minimum seconds between reconnect attempts to the same peer.
Functions
Clear the erased output list before reusing this state.