line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
package Net::BitTorrent; |
3
|
|
|
|
|
|
|
{ |
4
|
11
|
|
|
11
|
|
418357
|
use strict; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
425
|
|
5
|
11
|
|
|
11
|
|
67
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
391
|
|
6
|
11
|
|
|
11
|
|
60
|
use Scalar::Util qw[blessed weaken refaddr]; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
755
|
|
7
|
11
|
|
|
11
|
|
59
|
use List::Util qw[max]; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
715
|
|
8
|
11
|
|
|
11
|
|
83
|
use Time::HiRes; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
100
|
|
9
|
11
|
|
|
|
|
11556
|
use Socket qw[/inet_/ SOCK_STREAM SOCK_DGRAM SOL_SOCKET PF_INET SOMAXCONN |
10
|
11
|
|
|
11
|
|
2125
|
/pack_sockaddr_in/ SO_REUSEADDR]; |
|
11
|
|
|
|
|
4451
|
|
11
|
11
|
|
|
11
|
|
109
|
use Carp qw[carp]; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
565
|
|
12
|
11
|
|
|
11
|
|
6747
|
use Digest::SHA qw[sha1_hex]; |
|
11
|
|
|
|
|
30166
|
|
|
11
|
|
|
|
|
842
|
|
13
|
11
|
|
|
11
|
|
10541
|
use POSIX qw[]; |
|
11
|
|
|
|
|
85957
|
|
|
11
|
|
|
|
|
973
|
|
14
|
0
|
0
|
|
0
|
|
0
|
sub _EWOULDBLOCK { $^O eq q[MSWin32] ? 10035 : POSIX::EWOULDBLOCK() } |
15
|
0
|
0
|
|
0
|
|
0
|
sub _EINPROGRESS { $^O eq q[MSWin32] ? 10036 : POSIX::EINPROGRESS() } |
16
|
11
|
|
|
11
|
|
1052
|
use lib q[../../lib]; |
|
11
|
|
|
|
|
743
|
|
|
11
|
|
|
|
|
107
|
|
17
|
11
|
|
|
11
|
|
2749
|
use Net::BitTorrent::Util qw[:bencode :compact]; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
1847
|
|
18
|
11
|
|
|
11
|
|
7128
|
use Net::BitTorrent::Torrent; |
|
11
|
|
|
|
|
48
|
|
|
11
|
|
|
|
|
979
|
|
19
|
11
|
|
|
11
|
|
140
|
use Net::BitTorrent::Peer; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
544
|
|
20
|
11
|
|
|
11
|
|
9035
|
use Net::BitTorrent::DHT; |
|
11
|
|
|
|
|
57
|
|
|
11
|
|
|
|
|
494
|
|
21
|
11
|
|
|
11
|
|
124
|
use Net::BitTorrent::Version; |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
293
|
|
22
|
11
|
|
|
11
|
|
67
|
use version qw[qv]; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
89
|
|
23
|
|
|
|
|
|
|
our $VERSION_BASE = 50; our $UNSTABLE_RELEASE = 0; our $VERSION = sprintf(($UNSTABLE_RELEASE ? q[%.3f_%03d] : q[%.3f]), (version->new(($VERSION_BASE))->numify / 1000), $UNSTABLE_RELEASE); |
24
|
|
|
|
|
|
|
my (@CONTENTS) = \my ( |
25
|
|
|
|
|
|
|
%_tcp, %_udp, |
26
|
|
|
|
|
|
|
%_schedule, %_tid, |
27
|
|
|
|
|
|
|
%_event, %torrents, |
28
|
|
|
|
|
|
|
%_connections, %peerid, |
29
|
|
|
|
|
|
|
%_max_ul_rate, %_k_ul, |
30
|
|
|
|
|
|
|
%_max_dl_rate, %_k_dl, |
31
|
|
|
|
|
|
|
%_dht, %_use_dht, |
32
|
|
|
|
|
|
|
%__UDP_OBJECT_CACHE, %_peers_per_torrent, |
33
|
|
|
|
|
|
|
%_connections_per_host, %_half_open, |
34
|
|
|
|
|
|
|
############################################################# |
35
|
|
|
|
|
|
|
%_encryption_mode |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
my %REGISTRY; |
38
|
6
|
|
|
6
|
|
30
|
sub _MSE_DISABLED {0} |
39
|
53
|
|
|
53
|
|
283
|
sub _MSE_ENABLED {1} |
40
|
0
|
|
|
0
|
|
0
|
sub _MSE_FORCED {2} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
47
|
|
|
47
|
1
|
1022109
|
my ($class, $args) = @_; |
44
|
47
|
|
|
|
|
344
|
my $self = bless \$class, $class; |
45
|
47
|
|
|
|
|
238
|
my ($host, @ports) = (q[0.0.0.0], (0)); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Defaults |
48
|
47
|
|
|
|
|
452
|
$_max_ul_rate{refaddr $self} = 0; |
49
|
47
|
|
|
|
|
315
|
$_k_ul{refaddr $self} = 0; |
50
|
47
|
|
|
|
|
265
|
$_max_dl_rate{refaddr $self} = 0; |
51
|
47
|
|
|
|
|
271
|
$_k_dl{refaddr $self} = 0; |
52
|
47
|
|
|
|
|
241
|
$_peers_per_torrent{refaddr $self} = 100; |
53
|
47
|
|
|
|
|
229
|
$_half_open{refaddr $self} = 8; |
54
|
47
|
|
|
|
|
221
|
$_connections_per_host{refaddr $self} = 1; |
55
|
47
|
|
|
|
|
264
|
$torrents{refaddr $self} = {}; |
56
|
47
|
|
|
|
|
253
|
$_tid{refaddr $self} = qq[\0] x 5; |
57
|
47
|
|
|
|
|
241
|
$_use_dht{refaddr $self} = 1; |
58
|
47
|
|
|
|
|
211
|
$_encryption_mode{refaddr $self} = _MSE_ENABLED; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Internals |
61
|
47
|
|
|
|
|
242
|
$_connections{refaddr $self} = {}; |
62
|
47
|
|
|
|
|
299
|
$_schedule{refaddr $self} = {}; |
63
|
47
|
|
|
|
|
796
|
$_dht{refaddr $self} = Net::BitTorrent::DHT->new({Client => $self}); |
64
|
47
|
|
|
|
|
316
|
$peerid{refaddr $self} = Net::BitTorrent::Version::gen_peerid(); |
65
|
47
|
100
|
|
|
|
231
|
if (defined $args) { |
66
|
42
|
100
|
|
|
|
222
|
if (ref($args) ne q[HASH]) { |
67
|
3
|
|
|
|
|
472
|
carp q[Net::BitTorrent->new({}) requires ] |
68
|
|
|
|
|
|
|
. q[parameters to be passed as a hashref]; |
69
|
3
|
|
|
|
|
210
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
39
|
100
|
|
|
|
190
|
$host = $args->{q[LocalHost]} |
72
|
|
|
|
|
|
|
if defined $args->{q[LocalHost]}; |
73
|
|
|
|
|
|
|
@ports |
74
|
2
|
|
|
|
|
7
|
= defined $args->{q[LocalPort]} |
75
|
|
|
|
|
|
|
? (ref($args->{q[LocalPort]}) eq q[ARRAY] |
76
|
39
|
100
|
|
|
|
264
|
? @{$args->{q[LocalPort]}} |
|
|
100
|
|
|
|
|
|
77
|
|
|
|
|
|
|
: $args->{q[LocalPort]} |
78
|
|
|
|
|
|
|
) |
79
|
|
|
|
|
|
|
: @ports; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Try opening a matching set of ports |
83
|
44
|
|
|
|
|
152
|
for my $port (@ports) { |
84
|
|
|
|
|
|
|
last |
85
|
46
|
100
|
66
|
|
|
336
|
if $self->_socket_open_tcp($host, $port) |
86
|
|
|
|
|
|
|
&& $self->_socket_open_udp($host, $port); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Clear everything just in case |
90
|
44
|
|
|
|
|
263
|
$self->_reset_bandwidth; |
91
|
44
|
|
|
|
|
241
|
weaken($REGISTRY{refaddr $self} = $self); |
92
|
44
|
|
|
|
|
146
|
$$self = $peerid{refaddr $self}; |
93
|
44
|
|
|
|
|
256
|
return $self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Accessors | Private |
97
|
8
|
|
|
8
|
|
836
|
sub _tcp { return $_tcp{refaddr +shift} } |
98
|
280
|
|
|
280
|
|
8110
|
sub _udp { return $_udp{refaddr +shift} } |
99
|
929
|
|
|
929
|
|
4877
|
sub _connections { return $_connections{refaddr +shift} } |
100
|
2
|
|
|
2
|
|
33
|
sub _max_ul_rate { return $_max_ul_rate{refaddr +shift} } |
101
|
2
|
|
|
2
|
|
22
|
sub _max_dl_rate { return $_max_dl_rate{refaddr +shift} } |
102
|
290
|
|
|
290
|
|
2271
|
sub _peers_per_torrent { return $_peers_per_torrent{refaddr +shift} } |
103
|
134
|
|
|
134
|
|
1033
|
sub _half_open { return $_half_open{refaddr +shift} } |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _connections_per_host { |
106
|
173
|
|
|
173
|
|
1207
|
return $_connections_per_host{refaddr +shift}; |
107
|
|
|
|
|
|
|
} |
108
|
235
|
|
|
235
|
|
2608
|
sub _dht { return $_dht{refaddr +shift} } |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _use_dht { |
111
|
1512
|
|
|
1512
|
|
5381
|
my ($s) = @_; |
112
|
1512
|
|
66
|
|
|
15891
|
return $_udp{refaddr $s} && $_use_dht{refaddr $s}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _tcp_port { |
116
|
44
|
|
|
44
|
|
83
|
my ($self) = @_; |
117
|
44
|
100
|
|
|
|
199
|
return if not defined $_tcp{refaddr $self}; |
118
|
43
|
|
|
|
|
460
|
my ($port, undef) |
119
|
|
|
|
|
|
|
= unpack_sockaddr_in(getsockname($_tcp{refaddr $self})); |
120
|
43
|
|
|
|
|
327
|
return $port; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _tcp_host { |
124
|
3
|
|
|
3
|
|
10
|
my ($self) = @_; |
125
|
3
|
50
|
|
|
|
19
|
return if not defined $_tcp{refaddr $self}; |
126
|
3
|
|
|
|
|
43
|
my (undef, $packed_ip) |
127
|
|
|
|
|
|
|
= unpack_sockaddr_in(getsockname($_tcp{refaddr $self})); |
128
|
3
|
|
|
|
|
27
|
return inet_ntoa($packed_ip); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _udp_port { |
132
|
25
|
|
|
25
|
|
5277
|
my ($self) = @_; |
133
|
25
|
50
|
|
|
|
115
|
return if not defined $_udp{refaddr $self}; |
134
|
25
|
|
|
|
|
268
|
my ($port, undef) |
135
|
|
|
|
|
|
|
= unpack_sockaddr_in(getsockname($_udp{refaddr $self})); |
136
|
25
|
|
|
|
|
240
|
return $port; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _udp_host { |
140
|
3
|
|
|
3
|
|
8
|
my ($self) = @_; |
141
|
3
|
50
|
|
|
|
16
|
return if not defined $_udp{refaddr $self}; |
142
|
3
|
|
|
|
|
27
|
my (undef, $packed_ip) |
143
|
|
|
|
|
|
|
= unpack_sockaddr_in(getsockname($_udp{refaddr $self})); |
144
|
3
|
|
|
|
|
25
|
return inet_ntoa($packed_ip); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _encryption_mode { |
148
|
134
|
|
|
134
|
|
277
|
my ($self) = @_; |
149
|
134
|
|
|
|
|
1493
|
return $_encryption_mode{refaddr $self}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Setters | Private |
153
|
|
|
|
|
|
|
sub _set_encryption_mode { |
154
|
6
|
|
|
6
|
|
44
|
my ($self, $value) = @_; |
155
|
6
|
50
|
33
|
|
|
40
|
if (not defined $value |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
156
|
|
|
|
|
|
|
or ( ($value != _MSE_DISABLED) |
157
|
|
|
|
|
|
|
and ($value != _MSE_ENABLED) |
158
|
|
|
|
|
|
|
and ($value != _MSE_FORCED)) |
159
|
|
|
|
|
|
|
) |
160
|
0
|
|
|
|
|
0
|
{ carp |
161
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_encryption_mode( VALUE ) requires an integer value]; |
162
|
0
|
|
|
|
|
0
|
return; |
163
|
|
|
|
|
|
|
} |
164
|
6
|
|
|
|
|
28
|
return $_encryption_mode{refaddr $self} = $value; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _set_max_ul_rate { # BYTES per second |
168
|
1
|
|
|
1
|
|
3
|
my ($self, $value) = @_; |
169
|
1
|
50
|
33
|
|
|
40
|
if (not defined $value or $value !~ m[^\d+$] or !$value) { |
|
|
|
33
|
|
|
|
|
170
|
0
|
|
|
|
|
0
|
carp |
171
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_max_ul_rate( VALUE ) requires an integer value]; |
172
|
0
|
|
|
|
|
0
|
return; |
173
|
|
|
|
|
|
|
} |
174
|
1
|
|
|
|
|
14
|
return $_max_ul_rate{refaddr $self} = $value; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub _set_max_dl_rate { # BYTES per second |
178
|
1
|
|
|
1
|
|
5
|
my ($self, $value) = @_; |
179
|
1
|
50
|
33
|
|
|
25
|
if (not defined $value or $value !~ m[^\d+$]) { |
180
|
0
|
|
|
|
|
0
|
carp |
181
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_max_dl_rate( VALUE ) requires an integer value]; |
182
|
0
|
|
|
|
|
0
|
return; |
183
|
|
|
|
|
|
|
} |
184
|
1
|
|
|
|
|
11
|
return $_max_dl_rate{refaddr $self} = $value; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _set_peers_per_torrent { |
188
|
0
|
|
|
0
|
|
0
|
my ($self, $value) = @_; |
189
|
0
|
0
|
0
|
|
|
0
|
if (not defined $value or $value !~ m[^\d+$] or $value < 1) { |
|
|
|
0
|
|
|
|
|
190
|
0
|
|
|
|
|
0
|
carp |
191
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_peers_per_torrent( VALUE ) requires an integer value]; |
192
|
0
|
|
|
|
|
0
|
return; |
193
|
|
|
|
|
|
|
} |
194
|
0
|
|
|
|
|
0
|
return $_peers_per_torrent{refaddr $self} = $value; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _set_half_open { |
198
|
0
|
|
|
0
|
|
0
|
my ($self, $value) = @_; |
199
|
0
|
0
|
0
|
|
|
0
|
if (not defined $value or $value !~ m[^\d+$] or $value < 1) { |
|
|
|
0
|
|
|
|
|
200
|
0
|
|
|
|
|
0
|
carp |
201
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_half_open( VALUE ) requires an integer value]; |
202
|
0
|
|
|
|
|
0
|
return; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
0
|
return $_half_open{refaddr $self} = $value; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _set_connections_per_host { |
208
|
6
|
|
|
6
|
|
41
|
my ($self, $value) = @_; |
209
|
6
|
50
|
33
|
|
|
77
|
if (not defined $value or $value !~ m[^\d+$] or $value < 1) { |
|
|
|
33
|
|
|
|
|
210
|
0
|
|
|
|
|
0
|
carp |
211
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_connections_per_host( VALUE ) requires an integer value]; |
212
|
0
|
|
|
|
|
0
|
return; |
213
|
|
|
|
|
|
|
} |
214
|
6
|
|
|
|
|
36
|
return $_connections_per_host{refaddr $self} = $value; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub _set_use_dht { |
218
|
15
|
|
|
15
|
|
129
|
my ($self, $value) = @_; |
219
|
15
|
50
|
33
|
|
|
139
|
if (not defined $value or $value !~ m[^[10]$]) { |
220
|
0
|
|
|
|
|
0
|
carp |
221
|
|
|
|
|
|
|
q[Net::BitTorrent->_set_use_dht( VALUE ) requires a bool value]; |
222
|
0
|
|
|
|
|
0
|
return; |
223
|
|
|
|
|
|
|
} |
224
|
15
|
|
|
|
|
72
|
return $_use_dht{refaddr $self} = $value; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Accessors | Public |
228
|
240
|
|
|
240
|
1
|
810
|
sub peerid { my ($self) = @_; return $peerid{refaddr $self} } |
|
240
|
|
|
|
|
4101
|
|
229
|
67
|
|
|
67
|
1
|
611618
|
sub torrents { my ($self) = @_; return $torrents{refaddr $self} } |
|
67
|
|
|
|
|
523
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# Methods | Public |
232
|
|
|
|
|
|
|
sub do_one_loop { |
233
|
1383
|
|
|
1383
|
1
|
35304413
|
my ($self, $timeout) = @_; |
234
|
1383
|
|
|
|
|
6279
|
$self->_process_schedule; |
235
|
1383
|
50
|
66
|
|
|
42597
|
$timeout |
|
|
100
|
|
|
|
|
|
236
|
|
|
|
|
|
|
= defined $timeout && $timeout =~ m[^(\-1|\d+)\.?\d*$] |
237
|
|
|
|
|
|
|
? $timeout < 0 |
238
|
|
|
|
|
|
|
? undef |
239
|
|
|
|
|
|
|
: $timeout |
240
|
|
|
|
|
|
|
: 1; |
241
|
1383
|
|
|
|
|
4636
|
my ($rin, $win, $ein) = (q[], q[], q[]); |
242
|
1383
|
|
|
|
|
2271
|
PUSHSOCK: for my $fileno (keys %{$_connections{refaddr $self}}) { |
|
1383
|
|
|
|
|
13460
|
|
243
|
7494
|
100
|
|
|
|
53207
|
vec($rin, $fileno, 1) = 1 |
244
|
|
|
|
|
|
|
if $_connections{refaddr $self}{$fileno}{q[Mode]} =~ m[r]; |
245
|
7494
|
100
|
|
|
|
44042
|
vec($win, $fileno, 1) = 1 |
246
|
|
|
|
|
|
|
if $_connections{refaddr $self}{$fileno}{q[Mode]} =~ m[w]; |
247
|
7494
|
|
|
|
|
20877
|
vec($ein, $fileno, 1) = 1; |
248
|
|
|
|
|
|
|
} |
249
|
1383
|
|
|
|
|
102180694
|
my ($nfound, $timeleft) = select($rin, $win, $ein, $timeout); |
250
|
1383
|
100
|
66
|
|
|
14242
|
$self->_process_connections(\$rin, \$win, \$ein) |
251
|
|
|
|
|
|
|
if $nfound and $nfound != -1; |
252
|
1383
|
|
|
|
|
12772
|
return 1; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# Methods | Private |
256
|
|
|
|
|
|
|
sub _reset_bandwidth { |
257
|
851
|
|
|
851
|
|
2899
|
my ($self) = @_; |
258
|
851
|
|
|
|
|
10523
|
$self->_schedule({Time => time + 1, |
259
|
|
|
|
|
|
|
Code => \&_reset_bandwidth, |
260
|
|
|
|
|
|
|
Object => $self |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
); |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
#warn sprintf q[Speed report: Up: %5dB/s | Down: %5dB/s], |
265
|
|
|
|
|
|
|
# $_k_ul{refaddr $_[0]}, |
266
|
|
|
|
|
|
|
# $_k_dl{refaddr $_[0]}; |
267
|
851
|
|
|
|
|
8103
|
return $_k_dl{refaddr $_[0]} = $_k_ul{refaddr $_[0]} = 0; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub _add_connection { |
271
|
2403
|
|
|
2403
|
|
5453
|
my ($self, $connection, $mode) = @_; |
272
|
2403
|
100
|
|
|
|
5713
|
if (not defined $connection) { |
273
|
3
|
|
|
|
|
400
|
carp q[Net::BitTorrent->_add_connection() requires an object]; |
274
|
3
|
|
|
|
|
108
|
return; |
275
|
|
|
|
|
|
|
} |
276
|
2400
|
100
|
|
|
|
9123
|
if (not blessed $connection) { |
277
|
1
|
|
|
|
|
117
|
carp |
278
|
|
|
|
|
|
|
q[Net::BitTorrent->_add_connection() requires a blessed object]; |
279
|
1
|
|
|
|
|
39
|
return; |
280
|
|
|
|
|
|
|
} |
281
|
2399
|
|
|
|
|
8699
|
my $_sock = $connection->_socket; |
282
|
2399
|
100
|
66
|
|
|
14019
|
if ((not $_sock) or (ref($_sock) ne q[GLOB])) { return; } |
|
105
|
|
|
|
|
332
|
|
283
|
2294
|
50
|
33
|
|
|
13208
|
if ((!$mode) || ($mode !~ m[^(?:ro|rw|wo)$])) { |
284
|
0
|
|
|
|
|
0
|
carp |
285
|
|
|
|
|
|
|
q[Net::BitTorrent->_add_connection(SOCKET, MODE) requires a mode parameter]; |
286
|
0
|
|
|
|
|
0
|
return; |
287
|
|
|
|
|
|
|
} |
288
|
2294
|
|
|
|
|
28012
|
return $_connections{refaddr $self}{fileno $_sock} = { |
289
|
|
|
|
|
|
|
Object => $connection, |
290
|
|
|
|
|
|
|
Mode => $mode |
291
|
|
|
|
|
|
|
}; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub _remove_connection { |
295
|
98
|
|
|
98
|
|
278
|
my ($self, $connection) = @_; |
296
|
98
|
50
|
|
|
|
340
|
if (not defined $connection) { |
297
|
0
|
|
|
|
|
0
|
carp q[Net::BitTorrent->_remove_connection() requires an object]; |
298
|
0
|
|
|
|
|
0
|
return; |
299
|
|
|
|
|
|
|
} |
300
|
98
|
50
|
|
|
|
1026
|
if (not blessed $connection) { |
301
|
0
|
|
|
|
|
0
|
carp |
302
|
|
|
|
|
|
|
q[Net::BitTorrent->_remove_connection() requires a blessed object]; |
303
|
0
|
|
|
|
|
0
|
return; |
304
|
|
|
|
|
|
|
} |
305
|
98
|
|
|
|
|
529
|
my $socket = $connection->_socket; |
306
|
98
|
100
|
|
|
|
443
|
return if not defined $socket; |
307
|
67
|
|
|
|
|
532
|
return delete $_connections{refaddr $self}{fileno $socket}; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub _socket_open_tcp { |
311
|
55
|
|
|
55
|
|
2062
|
my ($self, $host, $port) = @_; |
312
|
55
|
50
|
0
|
|
|
437
|
if ( not $self |
|
|
|
33
|
|
|
|
|
313
|
|
|
|
|
|
|
|| not blessed $self |
314
|
|
|
|
|
|
|
|| not $self->isa(q[Net::BitTorrent])) |
315
|
0
|
|
|
|
|
0
|
{ carp |
316
|
|
|
|
|
|
|
q[Net::BitTorrent->_socket_open_tcp(HOST, PORT) requires a blessed object]; |
317
|
0
|
|
|
|
|
0
|
return; |
318
|
|
|
|
|
|
|
} |
319
|
55
|
50
|
66
|
|
|
438
|
if ((!$_tcp{refaddr $self}) && (!$host)) { |
320
|
0
|
|
|
|
|
0
|
carp q[Net::BitTorrent::_socket_open_tcp( ) ] |
321
|
|
|
|
|
|
|
. q[requires a hostname]; |
322
|
0
|
|
|
|
|
0
|
return; |
323
|
|
|
|
|
|
|
} |
324
|
55
|
100
|
100
|
|
|
549
|
if (defined $port and $port !~ m[^\d+$]) { |
325
|
1
|
|
|
|
|
1129
|
carp q[Net::BitTorrent::_socket_open_tcp( ) ] |
326
|
|
|
|
|
|
|
. q[requires an integer port number]; |
327
|
1
|
|
|
|
|
106
|
return; |
328
|
|
|
|
|
|
|
} |
329
|
54
|
|
|
|
|
101
|
my $_packed_host = undef; |
330
|
54
|
|
100
|
|
|
177
|
$host ||= q[0.0.0.0]; |
331
|
54
|
|
100
|
|
|
292
|
$port ||= 0; |
332
|
54
|
|
|
|
|
284
|
$port =~ m[^(\d+)$]; |
333
|
54
|
|
|
|
|
224
|
$port = $1; |
334
|
54
|
100
|
66
|
|
|
730
|
if ( $host |
335
|
|
|
|
|
|
|
and $host |
336
|
|
|
|
|
|
|
!~ m[^(?:(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.]?){4})$]) |
337
|
3
|
100
|
|
|
|
28067
|
{ my ($name, $aliases, $addrtype, $length, @addrs) |
338
|
|
|
|
|
|
|
= gethostbyname($host) |
339
|
|
|
|
|
|
|
or return; |
340
|
1
|
|
|
|
|
5
|
$_packed_host = $addrs[0]; |
341
|
|
|
|
|
|
|
} |
342
|
51
|
|
|
|
|
456
|
else { $_packed_host = inet_aton($host) } |
343
|
52
|
50
|
|
|
|
22569
|
socket(my ($_tcp), PF_INET, SOCK_STREAM, getprotobyname(q[tcp])) |
344
|
|
|
|
|
|
|
or return; |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# - What is the difference between SO_REUSEADDR and SO_REUSEPORT? |
347
|
|
|
|
|
|
|
# [http://www.unixguide.net/network/socketfaq/4.11.shtml] |
348
|
|
|
|
|
|
|
# - setsockopt - what are the options for ActivePerl under Windows NT? |
349
|
|
|
|
|
|
|
# [http://perlmonks.org/?node_id=63280] |
350
|
|
|
|
|
|
|
# setsockopt($_tcp, SOL_SOCKET, SO_REUSEADDR, pack(q[l], 1)) |
351
|
|
|
|
|
|
|
# or return; |
352
|
|
|
|
|
|
|
# SO_REUSEPORT is undefined on Win32... Boo... |
353
|
|
|
|
|
|
|
#if ($reuse_port and defined SO_REUSEPORT) { # XXX - undocumented |
354
|
|
|
|
|
|
|
# setsockopt($_udp, SOL_SOCKET, SO_REUSEPORT, pack(q[l], 1)) |
355
|
|
|
|
|
|
|
# or return; |
356
|
|
|
|
|
|
|
#} |
357
|
52
|
100
|
|
|
|
1183
|
bind($_tcp, pack_sockaddr_in($port, $_packed_host)) |
358
|
|
|
|
|
|
|
or return; |
359
|
47
|
50
|
|
|
|
706
|
listen($_tcp, 1) or return; |
360
|
47
|
50
|
|
|
|
686
|
$_connections{refaddr $self}{fileno $_tcp} = {Object => $self, |
361
|
|
|
|
|
|
|
Mode => q[ro], |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
or return; |
364
|
47
|
50
|
66
|
|
|
394
|
if ( defined $_tcp{refaddr $self} |
|
|
|
66
|
|
|
|
|
365
|
|
|
|
|
|
|
&& fileno $_tcp{refaddr $self} |
366
|
|
|
|
|
|
|
&& defined $_connections{refaddr $self} |
367
|
|
|
|
|
|
|
{fileno $_tcp{refaddr $self}}) |
368
|
6
|
|
|
|
|
41
|
{ delete $_connections{refaddr $self}{fileno $_tcp{refaddr $self}}; |
369
|
6
|
|
|
|
|
134
|
close $_tcp{refaddr $self}; |
370
|
|
|
|
|
|
|
} |
371
|
47
|
|
|
|
|
583
|
return $_tcp{refaddr $self} = $_tcp; |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub _socket_open_udp { |
375
|
50
|
|
|
50
|
|
2250
|
my ($self, $host, $port) = @_; |
376
|
50
|
50
|
0
|
|
|
199
|
if ( not $self |
|
|
|
33
|
|
|
|
|
377
|
|
|
|
|
|
|
|| not blessed $self |
378
|
|
|
|
|
|
|
|| not $self->isa(q[Net::BitTorrent])) |
379
|
0
|
|
|
|
|
0
|
{ carp |
380
|
|
|
|
|
|
|
q[Net::BitTorrent->_socket_open_udp(HOST, PORT) requires a blessed object]; |
381
|
0
|
|
|
|
|
0
|
return; |
382
|
|
|
|
|
|
|
} |
383
|
50
|
0
|
33
|
|
|
273
|
if ((!$_tcp{refaddr $self}) && (!$host)) { |
384
|
0
|
|
|
|
|
0
|
carp q[Net::BitTorrent::_socket_open_udp( ) ] |
385
|
|
|
|
|
|
|
. q[requires a hostname]; |
386
|
0
|
|
|
|
|
0
|
return; |
387
|
|
|
|
|
|
|
} |
388
|
50
|
100
|
100
|
|
|
572
|
if (defined $port and $port !~ m[^\d+$]) { |
389
|
1
|
|
|
|
|
195
|
carp q[Net::BitTorrent::_socket_open_udp( ) ] |
390
|
|
|
|
|
|
|
. q[requires an integer port number]; |
391
|
1
|
|
|
|
|
97
|
return; |
392
|
|
|
|
|
|
|
} |
393
|
49
|
|
|
|
|
114
|
my $_packed_host = undef; |
394
|
49
|
|
100
|
|
|
155
|
$host ||= q[0.0.0.0]; |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
#$port = $port ? $port : $_udp{refaddr $self} ? $self->_udp_port : 0; |
397
|
49
|
|
100
|
|
|
251
|
$port ||= 0; |
398
|
49
|
|
|
|
|
230
|
$port =~ m[^(\d+)$]; |
399
|
49
|
|
|
|
|
160
|
$port = $1; |
400
|
49
|
100
|
66
|
|
|
572
|
if ( $host |
401
|
|
|
|
|
|
|
and $host |
402
|
|
|
|
|
|
|
!~ m[^(?:(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.]?){4})$]) |
403
|
3
|
100
|
|
|
|
9847
|
{ my ($name, $aliases, $addrtype, $length, @addrs) |
404
|
|
|
|
|
|
|
= gethostbyname($host) |
405
|
|
|
|
|
|
|
or return; |
406
|
1
|
|
|
|
|
5
|
$_packed_host = $addrs[0]; |
407
|
|
|
|
|
|
|
} |
408
|
46
|
|
|
|
|
210
|
else { $_packed_host = inet_aton($host) } |
409
|
47
|
50
|
|
|
|
5411
|
socket(my ($_udp), PF_INET, SOCK_DGRAM, getprotobyname(q[udp])) |
410
|
|
|
|
|
|
|
or return; |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
# - What is the difference between SO_REUSEADDR and SO_REUSEPORT? |
413
|
|
|
|
|
|
|
# [http://www.unixguide.net/network/socketfaq/4.11.shtml] |
414
|
|
|
|
|
|
|
# - setsockopt - what are the options for ActivePerl under Windows NT? |
415
|
|
|
|
|
|
|
# [http://perlmonks.org/?node_id=63280] |
416
|
|
|
|
|
|
|
# setsockopt($_udp, SOL_SOCKET, SO_REUSEADDR, pack(q[l], 1)) |
417
|
|
|
|
|
|
|
# or return; |
418
|
|
|
|
|
|
|
# SO_REUSEPORT is undefined on Win32... Boo... |
419
|
|
|
|
|
|
|
#if ($reuse_port and defined SO_REUSEPORT) { # XXX - undocumented |
420
|
|
|
|
|
|
|
# setsockopt($_udp, SOL_SOCKET, SO_REUSEPORT, pack(q[l], 1)) |
421
|
|
|
|
|
|
|
# or return; |
422
|
|
|
|
|
|
|
#} |
423
|
47
|
50
|
|
|
|
637
|
bind($_udp, pack_sockaddr_in($port, $_packed_host)) |
424
|
|
|
|
|
|
|
or return; |
425
|
47
|
50
|
|
|
|
937
|
$_connections{refaddr $self}{fileno $_udp} = {Object => $self, |
426
|
|
|
|
|
|
|
Mode => q[ro], |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
or return; |
429
|
47
|
50
|
66
|
|
|
355
|
if ( $_udp{refaddr $self} |
|
|
|
66
|
|
|
|
|
430
|
|
|
|
|
|
|
&& fileno $_udp{refaddr $self} |
431
|
|
|
|
|
|
|
&& defined $_connections{refaddr $self} |
432
|
|
|
|
|
|
|
{fileno $_udp{refaddr $self}}) |
433
|
6
|
|
|
|
|
36
|
{ delete $_connections{refaddr $self}{fileno $_udp{refaddr $self}}; |
434
|
6
|
|
|
|
|
82
|
close $_udp{refaddr $self}; |
435
|
|
|
|
|
|
|
} |
436
|
47
|
|
|
|
|
410
|
return $_udp{refaddr $self} = $_udp; |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
sub _process_connections { |
440
|
812
|
|
|
812
|
|
3171
|
my ($self, $rin, $win, $ein) = @_; |
441
|
812
|
50
|
33
|
|
|
21069
|
if (!( ($rin and ref $rin and ref $rin eq q[SCALAR]) |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
442
|
|
|
|
|
|
|
and ($win and ref $win and ref $win eq q[SCALAR]) |
443
|
|
|
|
|
|
|
and ($ein and ref $ein and ref $ein eq q[SCALAR]) |
444
|
|
|
|
|
|
|
) |
445
|
|
|
|
|
|
|
) |
446
|
0
|
|
|
|
|
0
|
{ carp |
447
|
|
|
|
|
|
|
q[Malformed parameters to Net::BitTorrent::_process_connections(RIN, WIN, EIN)]; |
448
|
0
|
|
|
|
|
0
|
return; |
449
|
|
|
|
|
|
|
} |
450
|
812
|
|
|
|
|
1406
|
POPSOCK: foreach my $fileno (keys %{$_connections{refaddr $self}}) { |
|
812
|
|
|
|
|
4944
|
|
451
|
6346
|
50
|
|
|
|
25029
|
next POPSOCK unless defined $_connections{refaddr $self}{$fileno}; |
452
|
6346
|
100
|
66
|
|
|
97667
|
if ( $_tcp{refaddr $self} |
|
|
100
|
66
|
|
|
|
|
453
|
|
|
|
|
|
|
&& $fileno == fileno $_tcp{refaddr $self}) |
454
|
812
|
100
|
|
|
|
3397
|
{ if (vec($$rin, $fileno, 1) == 1) { |
455
|
67
|
|
|
|
|
190
|
vec($$rin, $fileno, 1) = 0; |
456
|
67
|
50
|
|
|
|
178
|
if (scalar( |
457
|
540
|
100
|
|
|
|
4417
|
grep { |
458
|
67
|
|
|
|
|
400
|
$_->{q[Object]}->isa(q[Net::BitTorrent::Peer]) |
459
|
|
|
|
|
|
|
&& !$_->{q[Object]}->torrent |
460
|
|
|
|
|
|
|
} values %{$_connections{refaddr $self}} |
461
|
|
|
|
|
|
|
) < $_half_open{refaddr $self} |
462
|
|
|
|
|
|
|
) |
463
|
67
|
50
|
|
|
|
3572
|
{ accept(my ($new_socket), $_tcp{refaddr $self}) |
464
|
|
|
|
|
|
|
or next POPSOCK; |
465
|
67
|
|
|
|
|
977
|
Net::BitTorrent::Peer->new({Socket => $new_socket, |
466
|
|
|
|
|
|
|
Client => $self |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
); |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
elsif ( $_udp{refaddr $self} |
473
|
|
|
|
|
|
|
&& $fileno == fileno $_udp{refaddr $self}) |
474
|
812
|
100
|
|
|
|
3120
|
{ if (vec($$rin, $fileno, 1) == 1) { |
475
|
198
|
|
|
|
|
532
|
vec($$rin, $fileno, 1) = 0; |
476
|
198
|
50
|
|
|
|
5141
|
my $paddr |
477
|
|
|
|
|
|
|
= recv($_udp{refaddr $self}, my ($data), 1024, 0) |
478
|
|
|
|
|
|
|
or next POPSOCK; |
479
|
198
|
100
|
|
|
|
1683
|
if ($__UDP_OBJECT_CACHE{refaddr $self}{$paddr}{q[Object]}) |
480
|
75
|
100
|
|
|
|
797
|
{ $__UDP_OBJECT_CACHE{refaddr $self}{$paddr}{q[Object]} |
481
|
|
|
|
|
|
|
->_on_data($paddr, $data) |
482
|
|
|
|
|
|
|
or |
483
|
|
|
|
|
|
|
delete $__UDP_OBJECT_CACHE{refaddr $self}{$paddr} |
484
|
|
|
|
|
|
|
{q[Object]}; |
485
|
75
|
|
|
|
|
428
|
next POPSOCK; |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
else { |
488
|
123
|
|
|
|
|
213
|
for my $_tor (values %{$torrents{refaddr $self}}) { |
|
123
|
|
|
|
|
632
|
|
489
|
107
|
|
|
|
|
324
|
for my $_tier (@{$_tor->trackers}) { |
|
107
|
|
|
|
|
774
|
|
490
|
0
|
0
|
|
|
|
0
|
my ($tracker) = grep { |
491
|
0
|
|
|
|
|
0
|
$_->isa( |
492
|
|
|
|
|
|
|
q[Net::BitTorrent::Torrent::Tracker::UDP] |
493
|
|
|
|
|
|
|
) |
494
|
|
|
|
|
|
|
and $_->_packed_host eq $paddr |
495
|
0
|
|
|
|
|
0
|
} @{$_tier->urls}; |
496
|
0
|
0
|
0
|
|
|
0
|
if ( $tracker |
497
|
|
|
|
|
|
|
&& $tracker->_on_data($paddr, $data)) |
498
|
0
|
|
|
|
|
0
|
{ $__UDP_OBJECT_CACHE{refaddr $self}{$paddr} |
499
|
|
|
|
|
|
|
= {Object => $tracker}; |
500
|
0
|
|
|
|
|
0
|
weaken($__UDP_OBJECT_CACHE{refaddr $self} |
501
|
|
|
|
|
|
|
{$paddr}{q[Object]}); |
502
|
0
|
|
|
|
|
0
|
next POPSOCK; |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
} |
507
|
123
|
100
|
66
|
|
|
1635
|
if ( $_use_dht{refaddr $self} |
508
|
|
|
|
|
|
|
&& $_dht{refaddr $self}->_on_data($paddr, $data)) |
509
|
57
|
|
|
|
|
642
|
{ $__UDP_OBJECT_CACHE{refaddr $self}{$paddr} |
510
|
|
|
|
|
|
|
= {Object => $_dht{refaddr $self}}; |
511
|
57
|
|
|
|
|
480
|
weaken($__UDP_OBJECT_CACHE{refaddr $self}{$paddr} |
512
|
|
|
|
|
|
|
{q[Object]}); |
513
|
|
|
|
|
|
|
} |
514
|
123
|
|
|
|
|
745
|
next POPSOCK; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
else { |
518
|
4722
|
50
|
|
|
|
16829
|
my $read = (($_max_dl_rate{refaddr $self} |
519
|
|
|
|
|
|
|
? max(0, |
520
|
|
|
|
|
|
|
( $_max_dl_rate{refaddr $self} |
521
|
|
|
|
|
|
|
- $_k_dl{refaddr $self} |
522
|
|
|
|
|
|
|
) |
523
|
|
|
|
|
|
|
) |
524
|
|
|
|
|
|
|
: (2**15) |
525
|
|
|
|
|
|
|
) * vec($$rin, $fileno, 1) |
526
|
|
|
|
|
|
|
); |
527
|
4722
|
50
|
|
|
|
16792
|
my $write = (($_max_ul_rate{refaddr $self} |
528
|
|
|
|
|
|
|
? max(0, |
529
|
|
|
|
|
|
|
( $_max_ul_rate{refaddr $self} |
530
|
|
|
|
|
|
|
- $_k_ul{refaddr $self} |
531
|
|
|
|
|
|
|
) |
532
|
|
|
|
|
|
|
) |
533
|
|
|
|
|
|
|
: (2**15) |
534
|
|
|
|
|
|
|
) * vec($$win, $fileno, 1) |
535
|
|
|
|
|
|
|
); |
536
|
4722
|
|
33
|
|
|
11523
|
my $error = vec($$ein, $fileno, 1) |
537
|
|
|
|
|
|
|
&& ( $^E |
538
|
|
|
|
|
|
|
&& ($^E != _EINPROGRESS) |
539
|
|
|
|
|
|
|
&& ($^E != _EWOULDBLOCK)); |
540
|
4722
|
100
|
100
|
|
|
22627
|
if ($read || $write || $error) { |
|
|
|
66
|
|
|
|
|
541
|
4669
|
|
|
|
|
29731
|
my ($this_r, $this_w) |
542
|
|
|
|
|
|
|
= $_connections{refaddr $self}{$fileno}{q[Object]} |
543
|
|
|
|
|
|
|
->_rw($read, $write, $error); |
544
|
4669
|
100
|
|
|
|
22455
|
$_k_dl{refaddr $self} += defined $this_r ? $this_r : 0; |
545
|
4669
|
100
|
|
|
|
12226
|
$_k_ul{refaddr $self} += defined $this_w ? $this_w : 0; |
546
|
4669
|
|
|
|
|
12405
|
vec($$rin, $fileno, 1) = 0; |
547
|
4669
|
|
|
|
|
12203
|
vec($$win, $fileno, 1) = 0; |
548
|
4669
|
|
|
|
|
15736
|
vec($$ein, $fileno, 1) = 0; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
} |
552
|
812
|
|
|
|
|
2832
|
return 1; |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
# Methods | Private | Torrents |
556
|
|
|
|
|
|
|
sub _locate_torrent { |
557
|
76
|
|
|
76
|
|
220
|
my ($self, $infohash) = @_; |
558
|
76
|
50
|
|
|
|
561
|
carp q[Bad infohash for Net::BitTorrent->_locate_torrent(INFOHASH)] |
559
|
|
|
|
|
|
|
&& return |
560
|
|
|
|
|
|
|
if $infohash !~ m[^[\d|a-f]{40}$]i; |
561
|
76
|
100
|
|
|
|
836
|
return $torrents{refaddr $self}{lc $infohash} |
562
|
|
|
|
|
|
|
? $torrents{refaddr $self}{lc $infohash} |
563
|
|
|
|
|
|
|
: undef; |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
# Methods | Public | Torrents |
567
|
|
|
|
|
|
|
sub add_torrent { |
568
|
31
|
|
|
31
|
1
|
11589
|
my ($self, $args) = @_; |
569
|
31
|
100
|
|
|
|
148
|
if (ref($args) ne q[HASH]) { |
570
|
1
|
|
|
|
|
167
|
carp |
571
|
|
|
|
|
|
|
q[Net::BitTorrent->add_torrent() requires params passed as a hash ref]; |
572
|
1
|
|
|
|
|
92
|
return; |
573
|
|
|
|
|
|
|
} |
574
|
30
|
|
|
|
|
74
|
$args->{q[Client]} = $self; |
575
|
30
|
|
|
|
|
844
|
my $torrent = Net::BitTorrent::Torrent->new($args); |
576
|
30
|
50
|
|
|
|
108
|
return if not defined $torrent; |
577
|
30
|
100
|
|
|
|
120
|
return if $self->_locate_torrent($torrent->infohash); |
578
|
29
|
|
|
|
|
173
|
return $torrents{refaddr $self}{$torrent->infohash} = $torrent; |
579
|
|
|
|
|
|
|
} |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
sub remove_torrent { |
582
|
2
|
|
|
2
|
1
|
7
|
my ($self, $torrent) = @_; |
583
|
2
|
100
|
66
|
|
|
23
|
if ( not blessed($torrent) |
584
|
|
|
|
|
|
|
or not $torrent->isa(q[Net::BitTorrent::Torrent])) |
585
|
1
|
|
|
|
|
344
|
{ carp |
586
|
|
|
|
|
|
|
q[Net::BitTorrent->remove_torrent(TORRENT) requires a blessed Net::BitTorrent::Torrent object]; |
587
|
1
|
|
|
|
|
62
|
return; |
588
|
|
|
|
|
|
|
} |
589
|
1
|
|
|
|
|
7
|
for my $_peer ($torrent->peers) { |
590
|
0
|
|
|
|
|
0
|
$_peer->_disconnect( |
591
|
|
|
|
|
|
|
q[Removing .torrent torrent from local client]); |
592
|
|
|
|
|
|
|
} |
593
|
1
|
|
|
|
|
10
|
$torrent->stop; # XXX - Should this be here? |
594
|
1
|
|
|
|
|
7
|
return delete $torrents{refaddr $self}{$torrent->infohash}; |
595
|
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
# Methods | Public | Callback system |
598
|
|
|
|
|
|
|
sub on_event { |
599
|
32
|
|
|
32
|
1
|
264
|
my ($self, $type, $method) = @_; |
600
|
32
|
50
|
|
|
|
86
|
carp sprintf q[Unknown callback: %s], $type |
601
|
|
|
|
|
|
|
unless ___check_event($type); |
602
|
32
|
|
|
|
|
281
|
$_event{refaddr $self}{$type} = $method; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
# Methods | Private | Callback system |
606
|
|
|
|
|
|
|
sub _event { |
607
|
2118
|
|
|
2118
|
|
4884
|
my ($self, $type, $args) = @_; |
608
|
2118
|
50
|
|
|
|
4922
|
carp sprintf |
609
|
|
|
|
|
|
|
q[Unknown event: %s. This is a bug in Net::BitTorrent; Report it.], |
610
|
|
|
|
|
|
|
$type |
611
|
|
|
|
|
|
|
unless ___check_event($type); |
612
|
2118
|
100
|
|
|
|
15544
|
return $_event{refaddr $self}{$type} |
613
|
|
|
|
|
|
|
? $_event{refaddr $self}{$type}($self, $args) |
614
|
|
|
|
|
|
|
: (); |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
# Functions | Private | Callback system |
618
|
|
|
|
|
|
|
sub ___check_event { |
619
|
2150
|
|
|
2150
|
|
3256
|
my $type = shift; |
620
|
2150
|
|
|
|
|
5092
|
return scalar grep { $_ eq $type } qw[ |
|
43000
|
|
|
|
|
83089
|
|
621
|
|
|
|
|
|
|
ip_filter |
622
|
|
|
|
|
|
|
incoming_packet outgoing_packet |
623
|
|
|
|
|
|
|
peer_connect peer_disconnect |
624
|
|
|
|
|
|
|
peer_read peer_write |
625
|
|
|
|
|
|
|
tracker_connect tracker_disconnect |
626
|
|
|
|
|
|
|
tracker_read tracker_write |
627
|
|
|
|
|
|
|
tracker_success tracker_failure |
628
|
|
|
|
|
|
|
piece_hash_pass piece_hash_fail |
629
|
|
|
|
|
|
|
file_open file_close |
630
|
|
|
|
|
|
|
file_read file_write |
631
|
|
|
|
|
|
|
file_error |
632
|
|
|
|
|
|
|
]; |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
# Methods | Private | Internal event scheduler |
636
|
|
|
|
|
|
|
sub _schedule { |
637
|
2968
|
|
|
2968
|
|
8482
|
my ($self, $args) = @_; |
638
|
2968
|
100
|
66
|
|
|
27627
|
if ((!$args) || (ref $args ne q[HASH])) { |
639
|
1
|
|
|
|
|
264
|
carp |
640
|
|
|
|
|
|
|
q[Net::BitTorrent->_schedule() requires params to be passed as a HashRef]; |
641
|
1
|
|
|
|
|
39
|
return; |
642
|
|
|
|
|
|
|
} |
643
|
2967
|
100
|
66
|
|
|
23232
|
if ((!$args->{q[Object]}) || (!blessed $args->{q[Object]})) { |
644
|
1
|
|
|
|
|
80
|
carp |
645
|
|
|
|
|
|
|
q[Net::BitTorrent->_schedule() requires a blessed 'Object' parameter]; |
646
|
1
|
|
|
|
|
52
|
return; |
647
|
|
|
|
|
|
|
} |
648
|
2966
|
50
|
33
|
|
|
32208
|
if ((!$args->{q[Time]}) || ($args->{q[Time]} !~ m[^\d+(?:\.\d+)?$])) { |
649
|
0
|
|
|
|
|
0
|
carp |
650
|
|
|
|
|
|
|
q[Net::BitTorrent->_schedule() requires an integer or float 'Time' parameter]; |
651
|
0
|
|
|
|
|
0
|
return; |
652
|
|
|
|
|
|
|
} |
653
|
2966
|
50
|
33
|
|
|
18574
|
if ((!$args->{q[Code]}) || (ref $args->{q[Code]} ne q[CODE])) { |
654
|
0
|
|
|
|
|
0
|
carp q[Net::BitTorrent->_schedule() requires a 'Code' parameter]; |
655
|
0
|
|
|
|
|
0
|
return; |
656
|
|
|
|
|
|
|
} |
657
|
2966
|
|
|
|
|
17822
|
my $tid = $self->_generate_token_id(); |
658
|
2966
|
|
|
|
|
24956
|
$_schedule{refaddr $self}{$tid} = {Timestamp => $args->{q[Time]}, |
659
|
|
|
|
|
|
|
Code => $args->{q[Code]}, |
660
|
|
|
|
|
|
|
Object => $args->{q[Object]} |
661
|
|
|
|
|
|
|
}; |
662
|
2966
|
|
|
|
|
16139
|
weaken $_schedule{refaddr $self}{$tid}{q[Object]}; |
663
|
2966
|
|
|
|
|
10731
|
return $tid; |
664
|
|
|
|
|
|
|
} |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
sub _cancel { |
667
|
1
|
|
|
1
|
|
16
|
my ($self, $tid) = @_; |
668
|
1
|
50
|
|
|
|
5
|
if (!$tid) { |
669
|
0
|
|
|
|
|
0
|
carp q[Net::BitTorrent->_cancel( TID ) requires an ID]; |
670
|
0
|
|
|
|
|
0
|
return; |
671
|
|
|
|
|
|
|
} |
672
|
1
|
50
|
|
|
|
6
|
if (!$_schedule{refaddr $self}{$tid}) { |
673
|
0
|
|
|
|
|
0
|
carp sprintf |
674
|
|
|
|
|
|
|
q[Net::BitTorrent->_cancel( TID ) cannot find an event with TID == %s], |
675
|
|
|
|
|
|
|
$tid; |
676
|
0
|
|
|
|
|
0
|
return; |
677
|
|
|
|
|
|
|
} |
678
|
1
|
|
|
|
|
6
|
return delete $_schedule{refaddr $self}{$tid}; |
679
|
|
|
|
|
|
|
} |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
sub _process_schedule { |
682
|
1383
|
|
|
1383
|
|
3059
|
my ($self) = @_; |
683
|
1383
|
|
|
|
|
2789
|
for my $job (keys %{$_schedule{refaddr $self}}) { |
|
1383
|
|
|
|
|
30839
|
|
684
|
34833
|
100
|
|
|
|
164710
|
if ($_schedule{refaddr $self}{$job}->{q[Timestamp]} <= time) { |
685
|
2133
|
100
|
|
|
|
15819
|
&{$_schedule{refaddr $self}{$job}->{q[Code]}}( |
|
2092
|
|
|
|
|
14944
|
|
686
|
|
|
|
|
|
|
$_schedule{refaddr $self}{$job}->{q[Object]}) |
687
|
|
|
|
|
|
|
if defined $_schedule{refaddr $self}{$job}->{q[Object]}; |
688
|
2133
|
|
|
|
|
17369
|
delete $_schedule{refaddr $self}{$job}; |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
} |
691
|
1383
|
|
|
|
|
8225
|
return 1; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
# Methods | Private | Various |
695
|
|
|
|
|
|
|
sub _generate_token_id { |
696
|
2966
|
50
|
|
2966
|
|
8669
|
return if defined $_[1]; |
697
|
2966
|
|
|
|
|
5594
|
my ($self) = @_; |
698
|
2966
|
|
50
|
|
|
13545
|
$_tid{refaddr $self} ||= qq[\0] x 4; |
699
|
2966
|
|
|
|
|
19106
|
my ($len) = ($_tid{refaddr $self} =~ m[^([a-z]+)]); |
700
|
2966
|
50
|
50
|
|
|
30521
|
$_tid{refaddr $self} = ( |
|
|
100
|
|
|
|
|
|
701
|
|
|
|
|
|
|
($_tid{refaddr $self} =~ m[^z*(\0*)$]) |
702
|
|
|
|
|
|
|
? ($_tid{refaddr $self} =~ m[\0] |
703
|
|
|
|
|
|
|
? pack(q[a] . (length $_tid{refaddr $self}), |
704
|
|
|
|
|
|
|
(q[a] x (length($len || q[]) + 1)) |
705
|
|
|
|
|
|
|
) |
706
|
|
|
|
|
|
|
: (q[a] . (qq[\0] x (length($_tid{refaddr $self}) - 1))) |
707
|
|
|
|
|
|
|
) |
708
|
|
|
|
|
|
|
: ++$_tid{refaddr $self} |
709
|
|
|
|
|
|
|
); |
710
|
2966
|
|
|
|
|
21362
|
return $_tid{refaddr $self}; |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
sub _build_reserved { |
714
|
157
|
|
|
157
|
|
337
|
my ($self) = @_; |
715
|
157
|
|
|
|
|
726
|
my @reserved = qw[0 0 0 0 0 0 0 0]; |
716
|
157
|
|
|
|
|
467
|
$reserved[5] |= 0x10; # Ext Protocol |
717
|
157
|
|
|
|
|
351
|
$reserved[7] |= 0x04; # Fast Ext |
718
|
157
|
|
|
|
|
787
|
return join q[], map {chr} @reserved; |
|
1256
|
|
|
|
|
5334
|
|
719
|
|
|
|
|
|
|
} |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
sub as_string { |
722
|
8
|
|
|
8
|
1
|
16
|
my ($self, $advanced) = @_; |
723
|
2
|
|
|
|
|
12
|
my $dump |
724
|
|
|
|
|
|
|
= !$advanced ? $peerid{refaddr $self} : sprintf <<'END', |
725
|
|
|
|
|
|
|
Net::BitTorrent |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
Peer ID: %s |
728
|
|
|
|
|
|
|
DHT is %sabled (Node ID: %s) |
729
|
|
|
|
|
|
|
TCP Address: %s:%d |
730
|
|
|
|
|
|
|
UDP Address: %s:%d |
731
|
|
|
|
|
|
|
---------- |
732
|
|
|
|
|
|
|
Torrents in queue: %d |
733
|
|
|
|
|
|
|
%s |
734
|
|
|
|
|
|
|
---------- |
735
|
|
|
|
|
|
|
END |
736
|
|
|
|
|
|
|
$peerid{refaddr $self}, |
737
|
|
|
|
|
|
|
$_use_dht{refaddr $self} ? q[En] : q[Dis], |
738
|
|
|
|
|
|
|
unpack(q[H*], $_dht{refaddr $self}->node_id), |
739
|
|
|
|
|
|
|
$self->_tcp_host, $self->_tcp_port, $self->_udp_host, |
740
|
0
|
|
|
|
|
0
|
$self->_udp_port, (scalar keys %{$torrents{refaddr $self}}), join( |
741
|
|
|
|
|
|
|
qq[\r\n], |
742
|
|
|
|
|
|
|
map { |
743
|
2
|
|
|
|
|
17
|
sprintf q[%40s (%d: %s)], $_->infohash, $_->status, |
744
|
|
|
|
|
|
|
$_->_status_as_string() |
745
|
8
|
50
|
|
|
|
58
|
} values %{$torrents{refaddr $self}} |
|
|
100
|
|
|
|
|
|
746
|
|
|
|
|
|
|
); |
747
|
8
|
100
|
|
|
|
48
|
return defined wantarray ? $dump : print STDERR qq[$dump\n]; |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
sub CLONE { |
751
|
0
|
|
|
0
|
|
0
|
for my $_oID (keys %REGISTRY) { |
752
|
0
|
|
|
|
|
0
|
my $_obj = $REGISTRY{$_oID}; |
753
|
0
|
|
|
|
|
0
|
my $_nID = refaddr $_obj; |
754
|
0
|
|
|
|
|
0
|
for (@CONTENTS) { |
755
|
0
|
|
|
|
|
0
|
$_->{$_nID} = $_->{$_oID}; |
756
|
0
|
|
|
|
|
0
|
delete $_->{$_oID}; |
757
|
|
|
|
|
|
|
} |
758
|
0
|
|
|
|
|
0
|
delete $_schedule{$_nID}; |
759
|
0
|
|
|
|
|
0
|
weaken($REGISTRY{$_nID} = $_obj); |
760
|
0
|
|
|
|
|
0
|
delete $REGISTRY{$_oID}; |
761
|
|
|
|
|
|
|
} |
762
|
0
|
|
|
|
|
0
|
return 1; |
763
|
|
|
|
|
|
|
} |
764
|
|
|
|
|
|
|
DESTROY { |
765
|
6
|
|
|
6
|
|
1361
|
my ($self) = @_; |
766
|
6
|
50
|
|
|
|
26
|
close($_tcp{refaddr $self}) if $_tcp{refaddr $self}; |
767
|
6
|
50
|
|
|
|
18
|
close($_udp{refaddr $self}) if $_udp{refaddr $self}; |
768
|
6
|
|
|
|
|
7
|
foreach my $conn (values %{$_connections{refaddr $self}}) { |
|
6
|
|
|
|
|
27
|
|
769
|
0
|
0
|
|
|
|
0
|
close($conn->{q[Object]}->_socket) if $conn->{q[Object]}; |
770
|
|
|
|
|
|
|
} |
771
|
6
|
|
|
|
|
11
|
for (@CONTENTS) { delete $_->{refaddr $self}; } |
|
114
|
|
|
|
|
298
|
|
772
|
6
|
|
|
|
|
36
|
return delete $REGISTRY{refaddr $self}; |
773
|
|
|
|
|
|
|
} |
774
|
|
|
|
|
|
|
1; |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
=pod |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
=head1 NAME |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
Net::BitTorrent - BitTorrent peer-to-peer protocol class |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
=head1 Synopsis |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
use Net::BitTorrent; |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
my $client = Net::BitTorrent->new(); |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
$client->on_event( |
790
|
|
|
|
|
|
|
q[piece_hash_pass], |
791
|
|
|
|
|
|
|
sub { |
792
|
|
|
|
|
|
|
my ($self, $args) = @_; |
793
|
|
|
|
|
|
|
printf(qq[pass: piece number %04d of %s\n], |
794
|
|
|
|
|
|
|
$args->{q[Index]}, $args->{q[Torrent]}->infohash); |
795
|
|
|
|
|
|
|
} |
796
|
|
|
|
|
|
|
); |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
my $torrent = $client->add_torrent({Path => q[a.legal.torrent]}) |
799
|
|
|
|
|
|
|
or die q[Cannot load .torrent]; |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
$torrent->hashcheck; # Verify any existing data |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
$client->do_one_loop() while 1; |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
=head1 Description |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
L is a class based implementation of the |
808
|
|
|
|
|
|
|
BitTorrent Protocol for distributed data exchange. |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=head1 Constructor |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
=over 4 |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
=item C |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
Creates a L object. This constructor |
817
|
|
|
|
|
|
|
expects arguments as a hashref, using key-value pairs, all of which are |
818
|
|
|
|
|
|
|
optional. The most common are: |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
=over 4 |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
=item C |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
Local host bind address. The value must be an IPv4 ("dotted quad") IP- |
825
|
|
|
|
|
|
|
address of the C form. |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
Default: C<0.0.0.0> (any address) |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
=item C |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
TCP and UDP port opened to remote peers for incoming connections. If |
832
|
|
|
|
|
|
|
handed a list of ports (ex. C<{ LocalPort =E [6952, 6881..6889] }>), |
833
|
|
|
|
|
|
|
L will traverse the list, attempting to |
834
|
|
|
|
|
|
|
open on each of the ports until we succeed or run out of ports. |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
Default: C<0> (any available, chosen by the OS) |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
=back |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
=back |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
=head1 Methods |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
Unless stated, all methods return either a C or C value, |
845
|
|
|
|
|
|
|
with C meaning that the operation was a success. When a method |
846
|
|
|
|
|
|
|
states that it returns some other specific value, failure will result in |
847
|
|
|
|
|
|
|
C or an empty list. |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
=over 4 |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
=item C |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
Loads a .torrent file and adds the |
854
|
|
|
|
|
|
|
L object to the |
855
|
|
|
|
|
|
|
client's queue. |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
Aside from the C parameter (which is filled in automatically), |
858
|
|
|
|
|
|
|
this method hands everything off to |
859
|
|
|
|
|
|
|
L's constructor, so |
860
|
|
|
|
|
|
|
see L |
861
|
|
|
|
|
|
|
for a list of expected parameters. |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
This method returns the new |
864
|
|
|
|
|
|
|
L object on success. |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
See also: L, |
867
|
|
|
|
|
|
|
L, |
868
|
|
|
|
|
|
|
L |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
=item C |
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
Processes the internal schedule and handles activity of the various |
873
|
|
|
|
|
|
|
socket-containing objects (L, |
874
|
|
|
|
|
|
|
L, |
875
|
|
|
|
|
|
|
L). This method should be called frequently |
876
|
|
|
|
|
|
|
to be of any use at all. |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
The optional TIMEOUT parameter is the maximum amount of time, in seconds, |
879
|
|
|
|
|
|
|
possibly fractional, C |
880
|
|
|
|
|
|
|
This TIMEOUT defaults to C<1.0> (one second). To wait indefinitely, |
881
|
|
|
|
|
|
|
TIMEOUT should be C<-1.0> (C<...-Edo_one_loop(-1)>). |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
=item C |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
Net::BitTorrent provides a convenient callback system. To set a callback, |
886
|
|
|
|
|
|
|
use the C method. For example, to catch all attempts to read |
887
|
|
|
|
|
|
|
from a file, use C<$client-Eon_event( 'file_read', \&on_read )>. |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
See the L section for a list of events sorted by their |
890
|
|
|
|
|
|
|
related classes. |
891
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
=item C |
893
|
|
|
|
|
|
|
|
894
|
|
|
|
|
|
|
Returns the L |
895
|
|
|
|
|
|
|
generated to identify this L object |
896
|
|
|
|
|
|
|
internally, with remote L, and |
897
|
|
|
|
|
|
|
L. |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
See also: wiki.theory.org (http://tinyurl.com/4a9cuv), |
900
|
|
|
|
|
|
|
L |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
=item C |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
Removes a L object |
905
|
|
|
|
|
|
|
from the client's queue. |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
=begin future |
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
Before the torrent torrent is closed, we announce to the tracker that we |
910
|
|
|
|
|
|
|
have 'stopped' downloading and a callback to store the current state is |
911
|
|
|
|
|
|
|
called. |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
=end future |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
See also: L, |
916
|
|
|
|
|
|
|
L, |
917
|
|
|
|
|
|
|
L |
918
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
=item C |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
Returns the list of queued L. |
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
See also: L, |
924
|
|
|
|
|
|
|
L |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
=back |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
=head1 Events |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
When triggered, client-wide callbacks receive two arguments: the |
931
|
|
|
|
|
|
|
C object and a hashref containing pertinent information. |
932
|
|
|
|
|
|
|
For per-torrent callbacks, please see |
933
|
|
|
|
|
|
|
L |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
This is the current list of events and the information passed to |
936
|
|
|
|
|
|
|
callbacks. |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
Note: This list is subject to change. Unless mentioned specifically, |
939
|
|
|
|
|
|
|
return values from callbacks do not affect behavior. |
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
=head2 Net::BitTorrent::Peer |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
=over |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
=item C |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
This gives a client author a chance to block or accept connections with |
948
|
|
|
|
|
|
|
a peer before an initial handshake is sent. The argument hash contains |
949
|
|
|
|
|
|
|
the following key: |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
=over |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
=item C |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
IPv4:port (or, on rare occasions, hostname:port) address of the potential peer. |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
=back |
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
Note: The return value from your C callback determines how we |
960
|
|
|
|
|
|
|
proceed. An I return value (ie C<0>) means this peer |
961
|
|
|
|
|
|
|
should not be contacted and (in the case of an incoming peer) the |
962
|
|
|
|
|
|
|
connection is dropped. |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
=item C |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
Triggered when we have both sent and received a valid handshake with |
967
|
|
|
|
|
|
|
the remote peer. The argument hash contains the following keys: |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
=over |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
=item C |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
The remote L with whom we have established |
974
|
|
|
|
|
|
|
a connection. |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
=back |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
=item C |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
Triggered when a connection with a remote peer is lost or terminated. |
981
|
|
|
|
|
|
|
The argument hash contains the following keys: |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
=over |
984
|
|
|
|
|
|
|
|
985
|
|
|
|
|
|
|
=item C |
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
The remote L with whom we have established |
988
|
|
|
|
|
|
|
a connection. |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
=item C |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
When possible, this is a 'user friendly' string. |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
=back |
995
|
|
|
|
|
|
|
|
996
|
|
|
|
|
|
|
=item C |
997
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
This is triggered whenever we receive data from a remote peer via TCP. |
999
|
|
|
|
|
|
|
The argument hash contains the following keys: |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
=over |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
=item C |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
The L who sent the packet. |
1006
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
=item C |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
The amount of data, in bytes, sent by the peer. |
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
=back |
1012
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
=item C |
1014
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
This is triggered whenever we send data to a remote peer via TCP. The |
1016
|
|
|
|
|
|
|
argument hash contains the following keys: |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
=over |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
=item C |
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
The L on the receiving end of this data. |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
=item C |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
The amount of data, in bytes, sent to the remote peer. |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
=back |
1029
|
|
|
|
|
|
|
|
1030
|
|
|
|
|
|
|
=item C |
1031
|
|
|
|
|
|
|
|
1032
|
|
|
|
|
|
|
Triggered when we send a packet to a remote peer. The argument hash |
1033
|
|
|
|
|
|
|
contains the following keys: |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=over |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
=item C |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
The parsed data sent in the packet (when applicable) in a hashref. |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=item C |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
The remote L receiving this data. |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
=item C |
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
The type of packet sent. These values match the packet types exported |
1048
|
|
|
|
|
|
|
from L. |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
=back |
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
=item C |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
Triggered when we receive a packet to a remote peer. The argument hash |
1055
|
|
|
|
|
|
|
contains the following keys: |
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
=over |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
=item C |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
The parsed data sent in the packet (when applicable) in a hashref. |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
=item C |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
The remote L sending this data. |
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
=item C |
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
The type of packet sent. These values match the packet types exported |
1070
|
|
|
|
|
|
|
from L. |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
=back |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
=back |
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
=head2 Net::BitTorrent::Torrent::File |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
=over |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
=item C |
1081
|
|
|
|
|
|
|
|
1082
|
|
|
|
|
|
|
Triggered when we run into an error handling the file in some way. The |
1083
|
|
|
|
|
|
|
argument hash contains the following keys: |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
=over |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
=item C |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
The L object related to this fault. |
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
=item C |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
The error message describing what (may have) gone wrong. |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
=back |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
=item C |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
Triggered every time we open a file represented in a |
1100
|
|
|
|
|
|
|
L object. The argument |
1101
|
|
|
|
|
|
|
hash contains the following keys: |
1102
|
|
|
|
|
|
|
|
1103
|
|
|
|
|
|
|
=over |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
=item C |
1106
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
The L object. |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
=item C |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
How the file is opened. To simplify things, C currently |
1112
|
|
|
|
|
|
|
uses 'r' for read access and 'w' for write. |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
=back |
1115
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
=item C |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
Triggered every time we close a file. The argument hash contains the |
1119
|
|
|
|
|
|
|
following key: |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
=over |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=item C |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
The L object. |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
=back |
1128
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
=item C |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
Triggered every time we write data to a file. The argument hash contains |
1132
|
|
|
|
|
|
|
the following keys: |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
=over |
1135
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
=item C |
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
The L object. |
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
=item C |
1141
|
|
|
|
|
|
|
|
1142
|
|
|
|
|
|
|
The actual amount of data written to the file. |
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
=back |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
=item C |
1147
|
|
|
|
|
|
|
|
1148
|
|
|
|
|
|
|
Triggered every time we read data from a file. The argument hash |
1149
|
|
|
|
|
|
|
contains the following keys: |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
=over |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
=item C |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
The L object related to this fault. |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
=item C |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
The actual amount of data written to the file. |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
=back |
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
=back |
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
=head2 Net::BitTorrent::Torrent::Tracker::HTTP/Net::BitTorrent::Torrent::Tracker::UDP |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
Note: The tracker objects passed to these callbacks will either be a |
1168
|
|
|
|
|
|
|
L |
1169
|
|
|
|
|
|
|
or a |
1170
|
|
|
|
|
|
|
L. |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
=over |
1173
|
|
|
|
|
|
|
|
1174
|
|
|
|
|
|
|
=item C |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
Triggered when we connect to a remote tracker. The argument hash |
1177
|
|
|
|
|
|
|
contains the following keys: |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
=over |
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
=item C |
1182
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
The tracker object related to this event. |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
=item C |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
If defined, this describes why we are contacting the tracker. See the |
1188
|
|
|
|
|
|
|
BitTorrent specification for more. |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
=back |
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
Note: This callback is only triggered from |
1193
|
|
|
|
|
|
|
L trackers, as |
1194
|
|
|
|
|
|
|
L is 'connection-less.' |
1195
|
|
|
|
|
|
|
|
1196
|
|
|
|
|
|
|
=item C |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
Triggered when we disconnect from a remote tracker. The argument hash |
1199
|
|
|
|
|
|
|
contains the following key: |
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
=over |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
=item C |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
The tracker object related to this event. |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
=back |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
Note: This callback is only triggered from |
1210
|
|
|
|
|
|
|
L trackers, as |
1211
|
|
|
|
|
|
|
L is 'connection-less.' |
1212
|
|
|
|
|
|
|
|
1213
|
|
|
|
|
|
|
=item C |
1214
|
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
|
Triggered when an announce attempt succeeds. The argument hash contains |
1216
|
|
|
|
|
|
|
the following keys: |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
=over |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
=item C |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
The tracker object related to this event. |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
=item C |
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
The data returned by the tracker in a hashref. The content of this |
1227
|
|
|
|
|
|
|
payload based on what we receive from the tracker but these are the |
1228
|
|
|
|
|
|
|
typical keys found therein: |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
=over |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
=item C |
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
The number of seeds in the swarm according to the tracker. |
1235
|
|
|
|
|
|
|
|
1236
|
|
|
|
|
|
|
=item C |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
The number of leeches in the swarm according to the tracker. |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
=item C |
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
A L list of peers in the swarm. |
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
=item C |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
The minimum amount of time before we should contact the tracker again. |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
=back |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
=back |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
=item C |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
Triggered when an announce attempt fails. The argument hash contains the |
1255
|
|
|
|
|
|
|
following keys: |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
=over |
1258
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
=item C |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
The tracker object related to this event. |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
=item C |
1264
|
|
|
|
|
|
|
|
1265
|
|
|
|
|
|
|
The reason given by the remote tracker (when applicable) or as defined |
1266
|
|
|
|
|
|
|
by C on socket errors. |
1267
|
|
|
|
|
|
|
|
1268
|
|
|
|
|
|
|
=back |
1269
|
|
|
|
|
|
|
|
1270
|
|
|
|
|
|
|
=item C |
1271
|
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
Triggered when we write data to a remote tracker. The argument hash |
1273
|
|
|
|
|
|
|
contains the following keys: |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
=over |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
=item C |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
The tracker object related to this event. |
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
=item C |
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
The amount of data sent to the remote tracker. |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
=back |
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
=item C |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
Triggered when data is read from a tracker. The argument hash contains |
1290
|
|
|
|
|
|
|
the following keys: |
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
=over |
1293
|
|
|
|
|
|
|
|
1294
|
|
|
|
|
|
|
=item C |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
The tracker object related to this event. |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
=item C |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
The amount of data received from the remote tracker. |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
=back |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
=back |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
=head2 Net::BitTorrent::Torrent |
1307
|
|
|
|
|
|
|
|
1308
|
|
|
|
|
|
|
=over |
1309
|
|
|
|
|
|
|
|
1310
|
|
|
|
|
|
|
=item C |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
Triggered when a piece fails to validate. The argument hash contains the |
1313
|
|
|
|
|
|
|
following keys: |
1314
|
|
|
|
|
|
|
|
1315
|
|
|
|
|
|
|
=over |
1316
|
|
|
|
|
|
|
|
1317
|
|
|
|
|
|
|
=item C |
1318
|
|
|
|
|
|
|
|
1319
|
|
|
|
|
|
|
The L object related to |
1320
|
|
|
|
|
|
|
this event. |
1321
|
|
|
|
|
|
|
|
1322
|
|
|
|
|
|
|
=item C |
1323
|
|
|
|
|
|
|
|
1324
|
|
|
|
|
|
|
The zero-based index of the piece that failed to match the hash defined |
1325
|
|
|
|
|
|
|
for it in the .torrent metadata. |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
=back |
1328
|
|
|
|
|
|
|
|
1329
|
|
|
|
|
|
|
=item C |
1330
|
|
|
|
|
|
|
|
1331
|
|
|
|
|
|
|
Triggered when a previously missing piece validates. The argument hash |
1332
|
|
|
|
|
|
|
contains the following keys: |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
=over |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
=item C |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
The L object related |
1339
|
|
|
|
|
|
|
to this event. |
1340
|
|
|
|
|
|
|
|
1341
|
|
|
|
|
|
|
=item C |
1342
|
|
|
|
|
|
|
|
1343
|
|
|
|
|
|
|
The zero-based index of the piece that was verified against the .torrent |
1344
|
|
|
|
|
|
|
metadata. |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
=back |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
=item C |
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
Returns a 'ready to print' dump of the object's data structure. If |
1351
|
|
|
|
|
|
|
called in void context, the structure is printed to C. |
1352
|
|
|
|
|
|
|
C is a boolean value. |
1353
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
=back |
1355
|
|
|
|
|
|
|
|
1356
|
|
|
|
|
|
|
=head1 Bugs |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
Numerous, I'm sure. |
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
Please see the section entitled |
1361
|
|
|
|
|
|
|
"L" in |
1362
|
|
|
|
|
|
|
L if you've found one. |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
=head1 Notes |
1365
|
|
|
|
|
|
|
|
1366
|
|
|
|
|
|
|
=head2 Support Links |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
Please refer to |
1369
|
|
|
|
|
|
|
L">. |
1370
|
|
|
|
|
|
|
|
1371
|
|
|
|
|
|
|
=head2 Dependencies |
1372
|
|
|
|
|
|
|
|
1373
|
|
|
|
|
|
|
L requires L and |
1374
|
|
|
|
|
|
|
L to function and relies upon |
1375
|
|
|
|
|
|
|
L for installation. As of perl 5.10, these |
1376
|
|
|
|
|
|
|
are all CORE modules; they come bundled with the distribution. |
1377
|
|
|
|
|
|
|
|
1378
|
|
|
|
|
|
|
=head2 Examples |
1379
|
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
For a demonstration of L, see |
1381
|
|
|
|
|
|
|
F. |
1382
|
|
|
|
|
|
|
|
1383
|
|
|
|
|
|
|
=head2 Installation |
1384
|
|
|
|
|
|
|
|
1385
|
|
|
|
|
|
|
See L. |
1386
|
|
|
|
|
|
|
|
1387
|
|
|
|
|
|
|
=head1 See Also |
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
http://bittorrent.org/beps/bep_0003.html - BitTorrent Protocol |
1390
|
|
|
|
|
|
|
Specification |
1391
|
|
|
|
|
|
|
|
1392
|
|
|
|
|
|
|
L - Random stuff. More |
1393
|
|
|
|
|
|
|
jibba jabba. |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
L - |
1396
|
|
|
|
|
|
|
The standard used to identify L in the |
1397
|
|
|
|
|
|
|
wild. |
1398
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
=head1 Acknowledgments |
1400
|
|
|
|
|
|
|
|
1401
|
|
|
|
|
|
|
Bram Cohen, for designing the base protocol and letting the community |
1402
|
|
|
|
|
|
|
decide what to do with it. |
1403
|
|
|
|
|
|
|
|
1404
|
|
|
|
|
|
|
L Rotger |
1405
|
|
|
|
|
|
|
|
1406
|
|
|
|
|
|
|
C<#bittorrent> on Freenode for letting me idle. |
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
Michel Valdrighi for b2 |
1409
|
|
|
|
|
|
|
|
1410
|
|
|
|
|
|
|
=head1 Author |
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
Sanko Robinson - http://sankorobinson.com/ |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
CPAN ID: SANKO |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
=head1 License and Legal |
1417
|
|
|
|
|
|
|
|
1418
|
|
|
|
|
|
|
Copyright (C) 2008-2009 by Sanko Robinson Esanko@cpan.orgE |
1419
|
|
|
|
|
|
|
|
1420
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
1421
|
|
|
|
|
|
|
it under the terms of The Artistic License 2.0. See the F |
1422
|
|
|
|
|
|
|
file included with this distribution or |
1423
|
|
|
|
|
|
|
http://www.perlfoundation.org/artistic_license_2_0. For |
1424
|
|
|
|
|
|
|
clarification, see http://www.perlfoundation.org/artistic_2_0_notes. |
1425
|
|
|
|
|
|
|
|
1426
|
|
|
|
|
|
|
When separated from the distribution, all POD documentation is covered |
1427
|
|
|
|
|
|
|
by the Creative Commons Attribution-Share Alike 3.0 License. See |
1428
|
|
|
|
|
|
|
http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For |
1429
|
|
|
|
|
|
|
clarification, see http://creativecommons.org/licenses/by-sa/3.0/us/. |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
Neither this module nor the L is affiliated with |
1432
|
|
|
|
|
|
|
BitTorrent, Inc. |
1433
|
|
|
|
|
|
|
|
1434
|
|
|
|
|
|
|
=for svn $Id: BitTorrent.pm d3c97de 2009-09-12 04:31:46Z sanko@cpan.org $ |
1435
|
|
|
|
|
|
|
|
1436
|
|
|
|
|
|
|
=cut |