ConnectionBudget

class ConnectionBudget(limit: Int)

The session-wide connection cap, the enforcement half of libtorrent's connections_limit setting (session_impl::m_settings, default 200).

Every torrent shares one budget: an outbound dial or inbound accept first takes a slot (tryAcquire); when none is free the dial is skipped / the accepted socket is closed, which is libtorrent's too_many_connections disconnect. The slot is returned on disconnect (release).

Constructors

Link copied to clipboard
constructor(limit: Int)

Properties

Link copied to clipboard
var limit: Int

The cap, mutable so a live connections_limit change (apply_settings) takes effect on the running session rather than only future torrents. Updated under lock via setLimit.

Functions

Link copied to clipboard
suspend fun inUse(): Int

Currently held slots (observability/tests).

Link copied to clipboard
suspend fun release()

Return a slot taken by tryAcquire.

Link copied to clipboard
suspend fun setLimit(newLimit: Int)

Apply a new connections_limit live; excess in-use slots drain as peers disconnect.

Link copied to clipboard
suspend fun tryAcquire(): Boolean

Take a connection slot; false (and no slot) when the session is full.