File Coverage

blib/lib/Net/BitTorrent/Protocol/BEP09.pm
Criterion Covered Total %
statement 15 21 71.4
branch n/a
condition n/a
subroutine 5 8 62.5
pod 3 3 100.0
total 23 32 71.8


line stmt bran cond sub pod time code
1             package Net::BitTorrent::Protocol::BEP09;
2 1     1   3 use strict;
  1         1  
  1         21  
3 1     1   3 use warnings;
  1         1  
  1         31  
4             our $VERSION = "1.5.1";
5 1     1   2 use Net::BitTorrent::Protocol::BEP03::Bencode qw[bencode];
  1         1  
  1         37  
6 1     1   2 use vars qw[@EXPORT_OK %EXPORT_TAGS];
  1         1  
  1         30  
7 1     1   3 use Exporter qw[];
  1         1  
  1         174  
8             *import = *import = *Exporter::import;
9             %EXPORT_TAGS = (
10             build => [
11             qw[build_metadata_request build_metadata_data build_metadata_reject]
12             ],
13             parse => [qw[ ]] # XXX - None required
14             );
15             @EXPORT_OK = sort map { @$_ = sort @$_; @$_ } values %EXPORT_TAGS;
16             $EXPORT_TAGS{'all'} = \@EXPORT_OK;
17              
18             #
19             sub build_metadata_request ($) {
20 0     0 1   my ($index) = @_;
21             return
22 0           bencode({piece => $index,
23             msg_type => 0
24             }
25             );
26             }
27              
28             sub build_metadata_data ($$) {
29 0     0 1   my ($index, $data) = @_;
30             return
31 0           bencode({piece => $index,
32             total_size=> length($data),
33             msg_type => 1
34             }
35             ) . $data;
36             }
37              
38             sub build_metadata_reject ($) {
39 0     0 1   my ($index) = @_;
40             return
41 0           bencode({piece => $index,
42             msg_type => 2
43             }
44             );
45             }
46              
47             1;
48              
49             =pod
50              
51             =head1 NAME
52              
53             Net::BitTorrent::Protocol::BEP09 - Packet Utilities for BEP09: The Extention for Peers to Send Metadata Files
54              
55             =head1 Description
56              
57             The purpose of this extension is to allow clients to join a swarm and complete
58             a download without the need of downloading a .torrent file first. This
59             extension instead allows clients to download the metadata from peers. It makes
60             it possible to support I, a link on a web page only containing
61             enough information to join the swarm (the info hash).
62              
63             This metadata extiontion uses the
64             L to advertise its
65             existence. It adds the C entry to the C dictionary in the
66             extention header handshake message. It also adds C to the
67             handshake message (not the C dictionary) specifiying an integer value of
68             the number of bytes of the metadata.
69              
70             =head1 Importing From Net::BitTorrent::Protocol::BEP09
71              
72             By default, nothing is exported.
73              
74             You may import any of the following or use one or more of these tag:
75              
76             =over
77              
78             =item C<:all>
79              
80             Imports everything. If you're importing anything, this is probably what you
81             want.
82              
83             =item C<:build>
84              
85             Imports the functions which generate messages.
86              
87             =back
88              
89             Note that there are no parser functions as the packets generated for BEP09 are
90             simple bencoded hashes. Use the
91             L.
92              
93             =head1 Functions
94              
95             This extention is very simple; there's a single request packet type and only
96             two possible reply packet types:
97              
98             =over
99              
100             =item C
101              
102             Generates an appropriate request for a subpiece of the torrent's metadata.
103              
104             =item C
105              
106             Generates an appropriate reply to a
107             L.
108              
109             =item C
110              
111             Generates an appropriate reply to a
112             L if the requested piece
113             is not available.
114              
115             =back
116              
117             =head1 Magnet URI Format
118              
119             The magnet URI format is:
120              
121             magnet:?xt=urn:btih:&dn=&tr=
122              
123             Where C is the infohash, hex encoded, for a total of C<40>
124             characters. For compatability with existing links in the wild, clients should
125             also support the C<32> character base32 encoded infohash.
126              
127             =head1 See Also
128              
129             =over
130              
131             =item BEP 09: Extention for Peers to Send Metadata Files
132              
133             http://bittorrent.org/beps/bep_0009.html
134              
135             =back
136              
137             =head1 Author
138              
139             Sanko Robinson - http://sankorobinson.com/
140              
141             CPAN ID: SANKO
142              
143             =head1 License and Legal
144              
145             Copyright (C) 2010-2014 by Sanko Robinson
146              
147             This program is free software; you can redistribute it and/or modify it under
148             the terms of
149             L.
150             See the F file included with this distribution or
151             L
152             for clarification.
153              
154             When separated from the distribution, all original POD documentation is
155             covered by the
156             L.
157             See the
158             L.
159              
160             Neither this module nor the L is affiliated with BitTorrent,
161             Inc.
162              
163             =cut