NAME

Net::BitTorrent::Protocol::BEP11 - Peer Exchange (PEX)

SYNOPSIS

# Inherits from Net::BitTorrent::Protocol::BEP09
use Net::BitTorrent::Protocol::BEP11;

# Notify peer about new and dropped neighbors
$proto->send_pex(
    [{ ip => '1.2.3.4', port => 6881 }], # added
    [{ ip => '5.6.7.8', port => 6881 }]  # dropped
);

DESCRIPTION

Net::BitTorrent::Protocol::BEP11 implements the Peer Exchange (PEX, BEP 11) protocol. PEX allows peers to directly share the addresses of other peers they are connected to, dramatically reducing the time it takes to find a healthy swarm and reducing load on trackers and DHT nodes.

It runs as a sub-protocol of the Extension Protocol (BEP 10) under the name ut_pex.

METHODS

send_pex( $added, $dropped, $added6, $dropped6 )

Sends a PEX update message.

Params:

  • $added / $dropped: Arrayrefs of IPv4 peer hashrefs ({ip, port}).

  • $added6 / $dropped6: Arrayrefs of IPv6 peer hashrefs.

Peer addresses are automatically compacted into the 6-byte (v4) or 18-byte (v6) binary formats defined in BEP 23.

Callbacks

on_pex( $added, $dropped, $added6, $dropped6 )

Triggered when a PEX message is received from a remote peer. The arguments are arrayrefs of hashrefs containing ip and port.

Specifications

  • BEP 11: Peer Exchange (PEX)

AUTHOR

Sanko Robinson <sanko@cpan.org>

COPYRIGHT

Copyright (C) 2008-2026 by Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.