addPeer

fun addPeer(host: String, port: Int, source: Int, pexFlags: Int = PexFlags.NONE, state: TorrentState = TorrentState()): TorrentPeer?

Add (or merge) a peer learned for (host, port) from source. This is the port of the IP path of peer_list::add_peer. Returns the stored TorrentPeer (existing or freshly created), or null if the endpoint is rejected.

Faithful behaviours:

  • invalid endpoints are ignored: port 0 or 1, and IPv6 link-local addresses (which need a scope to be usable);

  • dedupe: if we already know this endpoint we update the existing record (updatePeer) instead of inserting a duplicate, and set TorrentState.firstTimeSeen to false; a brand-new peer sets it true;

  • the new peer is created connectable (we have a port for it) with the given source and any pexFlags hints folded in.

Parameters

host

literal IP or hostname. A literal IP enables address-keyed dedupe; a non-literal host is deduped by exact host:port.

port

the peer's port in [0, 65535].

source

one of the PeerSource flags.

pexFlags

optional PexFlags hints (seed/utp/holepunch/…).

state

torrent context; TorrentState.firstTimeSeen is written.