File Coverage

blib/lib/Net/BitTorrent/Version.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 22 22 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             package Net::BitTorrent::Version;
3             {
4 12     12   527039 use strict;
  12         25  
  12         529  
5 12     12   67 use warnings;
  12         22  
  12         435  
6 12     12   67 use version qw[qv];
  12         28  
  12         100  
7             our $VERSION_BASE = 52; our $UNSTABLE_RELEASE = 0; our $VERSION = sprintf(($UNSTABLE_RELEASE ? q[%.3f_%03d] : q[%.3f]), (version->new(($VERSION_BASE))->numify / 1000), $UNSTABLE_RELEASE);
8             our $PRODUCT_TOKEN = qq[Net::BitTorrent $VERSION];
9              
10             sub gen_peerid {
11 408         7937 return pack(
12             q[a20],
13             (sprintf(
14             q[NB%03d%1s-%8s%5s],
15             $VERSION_BASE,
16             ($UNSTABLE_RELEASE ? q[U] : q[S]),
17             (join q[],
18             map {
19 51 100   51 1 93139 [q[A] .. q[Z], q[a] .. q[z], 0 .. 9, qw[- . _ ~]]
20             ->[rand(66)]
21             } 1 .. 8
22             ),
23             q[Riana]
24             )
25             )
26             );
27             }
28              
29             sub gen_node_id {
30 48     48 1 193 return pack(q[H40], join(q[], map { rand(12) } 1 .. 40));
  1920         7944  
31             }
32             1;
33             }
34              
35             =pod
36              
37             =head1 NAME
38              
39             Net::BitTorrent::Version - Net::BitTorrent's project-wide version numbers
40              
41             =head1 DESCRIPTION
42              
43             Because of the problems coordinating revision numbers in a distributed
44             version control system and across a directory full of Perl modules, this
45             module provides a central location for the project's overall release
46             number, the version string provided in Extended Protocol handshakes,
47             and the Peer ID generator.
48              
49             =head1 Methods
50              
51             =head2 C
52              
53             Returns a random 20-byte string that can be used to identify ourself in a
54             DHT swarm.
55              
56             =head2 C
57              
58             Generates a unique Peer ID based on Net::BitTorrent's
59             L.
60              
61             =head1 Peer ID Specification
62              
63             This section describes and provides examples of the Peer ID format used
64             by this release of the C module.
65              
66             =head2 Overview
67              
68             This non-standard format was developed to be URL-safe, unique to the
69             implementation, and "human parsable."
70              
71             There are two distinct sections to the Peer IDs generated: the
72             L which may be used to identify the software and its
73             version, and the L which is... well, it's junk.
74             Consider this example:
75              
76             NB004S-rogzGB1v--git
77              
78             Here, C is the header and C<-rogzGB1v--git> is the trailing
79             signature.
80              
81             =head3 Header
82              
83             The header consists of two uppercase characters ('C') followed by
84             three digits (with leading zeros) representing the distribution version
85             and a single character used to (potentially) indicate stability:
86             Ctable or Cnstable. Any deviation from this indicates a bad
87             client. Recent stable builds will be found on CPAN.
88              
89             =head3 Signature
90              
91             The remainder of the Peer ID is a hyphen followed by 13 random characters
92             in the following range:
93              
94             ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~
95              
96             That is, all uppercase and lowercase letters, decimal digits, as well as
97             the hyphen, period, underscore, and tilde (66 total). These are all
98             characters allowed in a URL without being encoded (referred to as
99             "Unreserved Characters" in L).
100              
101             =head2 Version Numbers and Stability
102              
103             Distribution version numbers will be some value less than one (C<1>) with
104             the revision number in the three significant decimal places.
105              
106             Recent stable builds will be found on CPAN. Unstable builds will most
107             likely be private builds or temporary uploads to CPAN where the package
108             name matches C. See the PAUSE FAQ section entitled
109             "Developer Releases" (L).
110              
111             =head2 Examples
112              
113             =over
114              
115             =item C
116              
117             This would be the stable CPAN-ready release C. The C<--git>
118             signature does not imply an unstable build.
119              
120             =item C3BT>
121              
122             Improper Peer ID; the sixth char is neither 'C' nor 'C' and E
123             is a reserved character according to L.
124              
125             =item C
126              
127             Completely legal Peer ID generated by unstable build around C.
128              
129             =back
130              
131             =head1 See Also
132              
133             XRFC 3986 (URI: Generic Syntax)
134             Section 2.3. "Unreserved Characters"
135             (http://tools.ietf.org/html/rfc3986#section-2.3)
136              
137             PAUSE FAQ sub-section entitled "Developer Releases"
138             (http://www.cpan.org/modules/04pause.html)
139              
140             http://slashdot.org/comments.pl?sid=997033&cid=25390887
141              
142             =head1 Disclaimer
143              
144             This document and the specification behind it are subject to change.
145             All modifications will be documented in the Changes file included with
146             this distribution. All versions of this file can be found in the
147             project's git repository.
148              
149             =head1 Author
150              
151             Sanko Robinson - http://sankorobinson.com/
152              
153             CPAN ID: SANKO
154              
155             =head1 License and Legal
156              
157             Copyright (C) 2008-2009 by Sanko Robinson Esanko@cpan.orgE
158              
159             This program is free software; you can redistribute it and/or modify
160             it under the terms of The Artistic License 2.0. See the F
161             file included with this distribution or
162             http://www.perlfoundation.org/artistic_license_2_0. For
163             clarification, see http://www.perlfoundation.org/artistic_2_0_notes.
164              
165             When separated from the distribution, all POD documentation is covered
166             by the Creative Commons Attribution-Share Alike 3.0 License. See
167             http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For
168             clarification, see http://creativecommons.org/licenses/by-sa/3.0/us/.
169              
170             Neither this module nor the L is affiliated with
171             BitTorrent, Inc.
172              
173             =for svn $Id: Version.pm 07f0c35 2010-04-02 18:31:29Z sanko@cpan.org $
174              
175             =cut