sourceRank

fun sourceRank(source: Int): Int

Compute the source rank of a peer's source bitmap: the port of int source_rank(peer_source_flags_t) from src/request_blocks.cpp.

This collapses the (multi-bit) source bitmap into a small priority number used as a tie-breaker when choosing which known peer to connect to next: peers we heard about from "more trustworthy" channels are preferred. The ordering, highest-first, is tracker > LSD > DHT > PEX; the incoming and resume_data sources contribute nothing (rank 0).

The exact bit layout (1<<5 for tracker down to 1<<2 for PEX) is reproduced verbatim so that the relative magnitudes (and therefore the connect ordering) match libtorrent precisely.