NAME

Net::BitTorrent::Protocol::BEP53 - Magnet URI extension

SYNOPSIS

use Net::BitTorrent::Protocol::BEP53;

# Parse an incoming URI
my $m = Net::BitTorrent::Protocol::BEP53->parse( $uri_string );

say 'Name: ' . $m->name;
say 'V2 Hash: ' . unpack('H*', $m->infohash_v2) if $m->infohash_v2;

# Generate a new URI
my $new_uri = Net::BitTorrent::Protocol::BEP53->new(
    inf_hash_v2  => $ih2,
    name         => 'Special Linux Distro',
    trackers     => ['udp://tracker.example.com:80']
)->to_string();

DESCRIPTION

Net::BitTorrent::Protocol::BEP53 implements the magnet URI extension (BEP 53). It provides a robust parser and generator for magnet links, specifically updated to support the multihash SHA-256 identifiers required for BitTorrent v2.

Multihash Support

This module correctly identifies and extracts:

v1 (legacy): urn:btih:... (SHA-1)
v2 (modern): urn:btmh:1220... (SHA-256 multihash)

METHODS

parse( $class, $uri )

Class method. Deconstructs a magnet string into an object. Supports both & and ; separators.

to_string( )

Generates a URI-encoded magnet string based on the object's current state.

infohash_v1( ) / infohash_v2( )

Returns the binary infohash strings. infohash_v2 is returned without the 4-byte multihash prefix (0x12 0x20).

trackers( )

Returns an arrayref of tr (tracker) URLs found in the URI.

nodes( )

Returns an arrayref of x.pe (peer exchange) nodes. These allow a client to connect directly to initial peers without waiting for DHT or tracker responses.

Specifications

  • BEP 09: Magnet URI format (Foundational)

  • BEP 53: Magnet URI extension (v2 and multihash)

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.