NAME

Net::BitTorrent::Protocol::BEP09 - Metadata Exchange (Magnet Links)

SYNOPSIS

# Inherits from Net::BitTorrent::Protocol::BEP10 (Extension Protocol)
use Net::BitTorrent::Protocol::BEP09;

my $proto = Net::BitTorrent::Protocol::BEP09->new(...);

# Request segment 0 of the info dictionary
$proto->send_metadata_request(0);

# Handle incoming metadata pieces
$proto->on('metadata_data', sub ($piece, $total, $data) {
    say "Received metadata piece $piece of $total";
});

DESCRIPTION

Net::BitTorrent::Protocol::BEP09 implements the Extension for Peers to Send Metadata Files (BEP 09). This is the protocol that makes Magnet Links work by allowing a client to download the torrent's info dictionary directly from other peers when the local .torrent file is missing.

It works as a sub-protocol of the Extension Protocol (BEP 10), using the ut_metadata message name.

METHODS

send_metadata_request( $piece_index )

Sends a request for a 16KiB segment of the info dictionary.

send_metadata_data( $piece_index, $total_size, $data )

Sends a metadata segment to a peer.

Parameters:

  • $piece_index: The segment index being sent.

  • $total_size: The full length of the info dictionary.

  • $data: The raw binary bencoded data for this segment.

send_metadata_reject( $piece_index )

Informs the peer that the metadata request cannot be fulfilled.

CALLBACKS

on_metadata_request( $piece_index ) / on_metadata_data( $piece, $total, $data ) / on_metadata_reject( $piece )

Overridable handlers for incoming metadata messages.

Specifications

  • BEP 09: Extension for Peers to Send Metadata Files

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.