lib/Net/BitTorrent/Protocol/BEP55.pm

filter: Statementstmt 71.8% 23 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 3 / 3 totaltotal 65.3% 34 / 52 CC 4 SCAR 11.5
CC
4
Cov
61%
send_hp_rendezvous
6.0
send_hp_connect
6.0
send_hp_error
6.0
CRAP 3.1
« lib/Net/BitTorrent/Tracker/Base.pm ↑ Summary lib/Net/BitTorrent/Protocol/MSE/KeyExchange.pm »
1 25 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 25 ▶use feature 'class', 'try';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶no warnings 'experimental::class', 'experimental::try';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶class Net::BitTorrent::Protocol::BEP55 v2.1.1 : isa(Net::BitTorrent::Protocol::BEP11) {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶ use Net::BitTorrent::Protocol::BEP03::Bencode qw[bencode bdecode];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶ use Net::BitTorrent::Protocol::BEP23;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # BEP 55 Message IDs (internal to ut_holepunch)
9 25 ▶ use constant { HP_RENDEZVOUS => 0, HP_CONNECT => 1, HP_ERROR => 2, };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 57 ▶ ADJUST {
Subroutine __ANON__: called CC=1 SCAR=0.0
11 $self->on(
12 extended_message => sub ( $self, $name, $payload ) {
13 return unless $name eq 'ut_holepunch';
14 return if length($payload) < 1;
15 my $type = unpack( 'C', substr( $payload, 0, 1, '' ) );
16 my $dict;
17 try {
18 my @res = bdecode( $payload, 1 );
19 if ( @res > 2 ) {
20 pop @res; # Discard leftover
21 $dict = {@res};
22 }
23 else {
24 $dict = $res[0];
25 }
26 }
27 catch ($e) {
28 $self->_emit_log( 'error', "Malformed ut_holepunch message: $e" );
29 return;
30 }
31 if ( ref $dict ne 'HASH' ) {
32 $self->_emit_log( 'error', 'Malformed ut_holepunch message: dict is not a hash' );
33 return;
34 }
35 if ( $type == HP_RENDEZVOUS ) {
36 $self->_emit( hp_rendezvous => $dict->{id} );
37 }
38 elsif ( $type == HP_CONNECT ) {
39 $self->_emit( hp_connect => $dict->{addr}, $dict->{port} );
40 }
41 elsif ( $type == HP_ERROR ) {
42 $self->_emit( hp_error => $dict->{e} );
43 }
44 }
45 57 );
46 }
47  
48 0 ▶ method send_hp_rendezvous ($target_id) {
Subroutine send_hp_rendezvous: not called CC=2 SCAR=17.9
Pod documented
49 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
50 0 my $payload = bencode( { id => $target_id, } );
51 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_RENDEZVOUS, $payload ) );
52 }
53  
54 0 ▶ method send_hp_connect ( $ip, $port ) {
Subroutine send_hp_connect: not called CC=2 SCAR=17.9
Pod documented
55 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
56 0 my $payload = bencode( { addr => $ip, port => $port, } );
57 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_CONNECT, $payload ) );
58 }
59  
60 0 ▶ method send_hp_error ($err_code) {
Subroutine send_hp_error: not called CC=2 SCAR=17.9
Pod documented
61 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
62 0 my $payload = bencode( { e => $err_code, } );
63 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_ERROR, $payload ) );
64 }
65 25 } 1;
« lib/Net/BitTorrent/Tracker/Base.pm ↑ Summary lib/Net/BitTorrent/Protocol/MSE/KeyExchange.pm »