NAME

Net::BitTorrent::Protocol::BEP10 - Extension Protocol

SYNOPSIS

# Inherits from Net::BitTorrent::Protocol::BEP52 (BitTorrent v2)
use Net::BitTorrent::Protocol::BEP10;

my $proto = Net::BitTorrent::Protocol::BEP10->new(
    local_extensions => { ut_metadata => 1, ut_pex => 2 }
);

# Once core handshake is done, send extension handshake
$proto->send_ext_handshake();

# Send an extension message by name
$proto->send_ext_message( 'ut_pex', $bencoded_pex_data );

DESCRIPTION

Net::BitTorrent::Protocol::BEP10 implements the Extension Protocol (BEP 10). This is the standard mechanism modern BitTorrent clients use to negotiate support for additional features (like PEX, Magnet links, and DHT security) without needing to allocate new reserved bits in the foundational BitTorrent handshake.

METHODS

send_ext_handshake( )

Sends the ID 20 (EXTENDED) message with a sub-ID of 0. This message contains a bencoded dictionary of supported extensions and their local IDs.

send_ext_message( $name, $payload )

Sends a message for the extension identified by $name. The module automatically looks up the remote peer's assigned ID for that extension.

remote_extensions( )

Returns a hashref of extensions supported by the remote peer and their assigned message IDs.

remote_version( ) / remote_ip( )

Returns the client version string and external IP address reported by the remote peer during the extended handshake.

Callbacks

on_ext_handshake( $data )

Triggered when the remote peer's extended handshake is received.

on_extended_message( $name, $payload )

Triggered when a message for a registered extension is received.

Specifications

  • BEP 10: Extension Protocol

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.