| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::BitTorrent::Protocol::BEP23; |
|
2
|
2
|
|
|
2
|
|
492
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
46
|
|
|
3
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
44
|
|
|
4
|
2
|
|
|
2
|
|
5
|
use Carp qw[carp]; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
110
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "1.5.2"; |
|
6
|
2
|
|
|
2
|
|
8
|
use vars qw[@EXPORT_OK %EXPORT_TAGS]; |
|
|
2
|
|
|
|
|
28
|
|
|
|
2
|
|
|
|
|
93
|
|
|
7
|
2
|
|
|
2
|
|
8
|
use Exporter qw[]; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
581
|
|
|
8
|
|
|
|
|
|
|
*import = *import = *Exporter::import; |
|
9
|
|
|
|
|
|
|
@EXPORT_OK = qw[compact_ipv4 uncompact_ipv4]; |
|
10
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => [@EXPORT_OK], bencode => [@EXPORT_OK]); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub compact_ipv4 { |
|
13
|
2
|
|
|
2
|
1
|
390
|
my (@peers) = @_; |
|
14
|
2
|
|
|
|
|
2
|
my $return; |
|
15
|
|
|
|
|
|
|
my %seen; |
|
16
|
2
|
|
|
|
|
3
|
PEER: for my $peer (@peers) { |
|
17
|
4
|
50
|
|
|
|
7
|
next if not $peer; |
|
18
|
4
|
|
|
|
|
5
|
my ($ip, $port) = @$peer; |
|
19
|
4
|
100
|
|
|
|
13
|
next if $seen{$ip . ':' . $port}++; |
|
20
|
3
|
50
|
|
|
|
16
|
if ($ip |
|
|
|
50
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
!~ m[^(?:(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.]?){4})$]) |
|
22
|
0
|
|
|
|
|
0
|
{ carp 'Invalid IPv4 address: ' . $ip; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
elsif ($port > 2**16) { |
|
25
|
0
|
|
|
|
|
0
|
carp 'Port number beyond ephemeral range: ' . $port; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
else { |
|
28
|
3
|
|
|
|
|
21
|
$return .= pack 'C4n', |
|
29
|
|
|
|
|
|
|
($ip =~ m[^([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)$]), |
|
30
|
|
|
|
|
|
|
int $port; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
2
|
|
|
|
|
8
|
return $return; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub uncompact_ipv4 { |
|
37
|
|
|
|
|
|
|
return $_[0] ? |
|
38
|
|
|
|
|
|
|
map { |
|
39
|
2
|
50
|
|
2
|
1
|
11
|
my (@h) = unpack 'C4n', $_; |
|
|
3
|
|
|
|
|
10
|
|
|
40
|
3
|
|
|
|
|
34
|
[sprintf('%s.%s.%s.%s', @h), $h[-1]] |
|
41
|
|
|
|
|
|
|
} $_[0] =~ m[(.{6})]g |
|
42
|
|
|
|
|
|
|
: (); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
1; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=pod |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Net::BitTorrent::Protocol::BEP23 - Utility functions for BEP23: Tracker Returns Compact Peer Lists |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 Importing From Net::BitTorrent::Protocol::BEP23 |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
By default, nothing is exported. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
You may import any of the following or use one or more of these tag: |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item C<:all> |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Imports the tracker response-related functions |
|
63
|
|
|
|
|
|
|
L and |
|
64
|
|
|
|
|
|
|
L. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 Functions |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Compacts a list of IPv4:port strings into a single string. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
A compact peer is 6 bytes; the first four bytes are the host (in network byte |
|
77
|
|
|
|
|
|
|
order), the last two bytes are the port (again, in network byte order). |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Inflates a compacted string of peers and returns a list of IPv4:port strings. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 See Also |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item BEP 23: Tracker Returns Compact Peer Lists |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
http://bittorrent.org/beps/bep_0023.html |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 Author |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Sanko Robinson - http://sankorobinson.com/ |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
CPAN ID: SANKO |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 License and Legal |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright (C) 2008-2012 by Sanko Robinson |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
|
106
|
|
|
|
|
|
|
the terms of |
|
107
|
|
|
|
|
|
|
L. |
|
108
|
|
|
|
|
|
|
See the F file included with this distribution or |
|
109
|
|
|
|
|
|
|
L |
|
110
|
|
|
|
|
|
|
for clarification. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
When separated from the distribution, all original POD documentation is |
|
113
|
|
|
|
|
|
|
covered by the |
|
114
|
|
|
|
|
|
|
L. |
|
115
|
|
|
|
|
|
|
See the |
|
116
|
|
|
|
|
|
|
L. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Neither this module nor the L is affiliated with BitTorrent, |
|
119
|
|
|
|
|
|
|
Inc. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |