=pod

=encoding utf-8

=head1 NAME

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

=head1 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
    );

=head1 DESCRIPTION

C<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 C<ut_pex>.

=head1 METHODS

=head2 C<send_pex( $added, $dropped, $added6, $dropped6 )>

Sends a PEX update message.

Params:

=over

=item * C<$added> / C<$dropped>: Arrayrefs of IPv4 peer hashrefs (C<{ip, port}>).

=item * C<$added6> / C<$dropped6>: Arrayrefs of IPv6 peer hashrefs.

=back

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

=head1 Callbacks

=head2 C<on_pex( $added, $dropped, $added6, $dropped6 )>

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

=head1 Specifications

=over

=item * BEP 11: Peer Exchange (PEX)

=back

=head1 AUTHOR

Sanko Robinson E<lt>sanko@cpan.orgE<gt>

=head1 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.

=cut
