line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::BitTorrent::Message::Request; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Protocol::BitTorrent::Message::Request::VERSION = '0.004'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings FATAL => 'all', NONFATAL => 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
3
|
use parent qw(Protocol::BitTorrent::Message); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Protocol::BitTorrent::Message::Request - a piece request |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.004 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 new |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new_from_data { |
28
|
1
|
|
|
1
|
0
|
4
|
my $class = shift; |
29
|
1
|
|
|
|
|
3
|
my $data = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Complain mightily if we have an invalid request. |
32
|
|
|
|
|
|
|
# TODO extend this to all message types |
33
|
1
|
50
|
|
|
|
6
|
die "Bad length for buffer: " . join ' ', map sprintf('%02x', ord), split //, $data if length($data) != 12; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
my ($index, $begin, $len) = unpack 'N1N1N1', $data; |
36
|
1
|
50
|
|
|
|
4
|
die join ' ', "Data", unpack('H*', $data), 'has no length' unless defined $len; |
37
|
1
|
|
|
|
|
7
|
$class->new( |
38
|
|
|
|
|
|
|
piece_index => $index, |
39
|
|
|
|
|
|
|
offset => $begin, |
40
|
|
|
|
|
|
|
block_length => $len, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
46
|
1
|
|
|
|
|
5
|
my %args = @_; |
47
|
1
|
|
|
|
|
9
|
my $self = bless { |
48
|
|
|
|
|
|
|
piece_index => $args{piece_index}, |
49
|
|
|
|
|
|
|
offset => $args{offset}, |
50
|
|
|
|
|
|
|
block_length => $args{block_length}, |
51
|
|
|
|
|
|
|
}, $class; |
52
|
1
|
|
|
|
|
7
|
$self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
1
|
14
|
sub type { 'request' } |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
0
|
4
|
sub piece_index { shift->{piece_index} } |
58
|
1
|
|
|
1
|
0
|
5
|
sub offset { shift->{offset} } |
59
|
1
|
|
|
1
|
0
|
10
|
sub block_length { shift->{block_length} } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 as_string |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Returns a stringified version of this message. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub as_string { |
68
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
69
|
1
|
|
|
|
|
10
|
return sprintf '%s, %d bytes, index = %d, begin = %d, length = %d', $self->type, $self->packet_length, $self->piece_index, $self->offset, $self->block_length; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |