NAME

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

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 Peer Exchange update.

$proto->send_pex(
    [{ ip => '1.2.3.4', port => 6881 }],
    [{ ip => '5.6.7.8', port => 6881 }]
);

This method sends a ut_pex message containing lists of newly discovered and recently disconnected peers.

Expected parameters:

$added - optional

Array reference of newly discovered IPv4 peers. Each must be a hash reference with ip and port.

$dropped - optional

Array reference of IPv4 peers that have disconnected.

$added6 - optional

Array reference of newly discovered IPv6 peers.

$dropped6 - optional

Array reference of IPv6 peers that have disconnected.

pex event

Emitted when a PEX message is received.

$proto->on( pex => sub ( $self, $added, $dropped, $added6, $dropped6 ) { ... } );

Expected parameters:

$added

Array reference of added IPv4 peers.

$dropped

Array reference of dropped IPv4 peers.

$added6

Array reference of added IPv6 peers.

$dropped6

Array reference of dropped IPv6 peers.

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.