comparePeer

fun comparePeer(lhs: TorrentPeer, rhs: TorrentPeer, external: ExternalIp, externalPort: Int, finished: Boolean): Boolean

True if lhs is a better connect candidate than rhs. This is the port of the file-local compare_peer in src/peer_list.cpp. The ordering, in priority order:

  1. lower failcount wins;

  2. a PeerAddress.isLocal peer wins (try LAN peers first);

  3. smaller lastConnected wins (least-recently-tried first; 0 = never);

  4. when finished, a peer that is not maybeUploadOnly wins (de-prioritise suspected seeds);

  5. higher sourceRank wins (tracker > LSD > DHT > PEX);

  6. higher BEP 40 TorrentPeer.rank wins (compared unsigned).