Builder

class Builder(val maxAdded: Int = MAX_ADDED_ENTRIES)

Stateful per-connection PEX differ, the port of ut_pex_plugin's m_old_peers bookkeeping. The session holds one Builder per peer connection (the peer we gossip to) and calls tick roughly once a minute with the current swarm membership; the builder emits only the delta versus what it sent last time:

  • peers in the current set but not previously sent → added (with flags);

  • peers previously sent but no longer in the current set → dropped.

This mirrors ut_pex_plugin::tick, which inserts every still-connected peer into the fresh m_old_peers, treats those absent from the previous m_old_peers as added, and treats the leftover previous entries as dropped.

The added list is capped at maxAdded (MAX_ADDED_ENTRIES by default); peers that don't fit this tick stay un-sent and will be picked up next tick (they remain absent from the recorded "old" set). dropped is never capped.

Identity is the (ip,port) endpoint only. Flags are not part of the key, so a peer that only changes its seed bit is not re-advertised.

Not thread-safe; call tick from the single coroutine that owns the connection.

Constructors

Link copied to clipboard
constructor(maxAdded: Int = MAX_ADDED_ENTRIES)

Properties

Link copied to clipboard

Endpoints previously advertised, for inspection/testing.

Link copied to clipboard

Functions

Link copied to clipboard
fun reset()

Forget all previously-sent peers (e.g. after a reconnect).

Link copied to clipboard

Compute and record the next PEX delta against current, which is the peers we should be advertising right now (already filtered by the caller to "proper bittorrent peers we're willing to share", as send_peer does in libtorrent). Flags on each current peer should be built via PexFlags.build.

Link copied to clipboard

Encode the next delta directly to wire bytes: tick then encode.