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 SCAR 16.1
CC
4
Cov
61%
send_hp_rendezvous
6.0
send_hp_connect
6.0
send_hp_error
6.0
CRAP 5.0
« lib/Net/BitTorrent/Protocol/BEP09.pm ↑ Summary lib/Net/BitTorrent/Tracker/Base.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.0.0 : 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 ADJUST {
11 $self->on(
12 extended_message => sub ( $self, $name, $payload ) {
13 return unless $name eq 'ut_holepunch';
14 my $type = unpack( 'C', substr( $payload, 0, 1, '' ) );
15 my $dict;
16 try {
17 my @res = bdecode( $payload, 1 );
18 if ( @res > 2 ) {
19 pop @res; # Discard leftover
20 $dict = {@res};
21 }
22 else {
23 $dict = $res[0];
24 }
25 }
26 catch ($e) {
27 $self->_emit_log( 'error', "Malformed ut_holepunch message: $e" );
28 return;
29 }
30 if ( ref $dict ne 'HASH' ) {
31 $self->_emit_log( 'error', 'Malformed ut_holepunch message: dict is not a hash' );
32 return;
33 }
34 if ( $type == HP_RENDEZVOUS ) {
35 $self->_emit( hp_rendezvous => $dict->{id} );
36 }
37 elsif ( $type == HP_CONNECT ) {
38 $self->_emit( hp_connect => $dict->{addr}, $dict->{port} );
39 }
40 elsif ( $type == HP_ERROR ) {
41 $self->_emit( hp_error => $dict->{e} );
42 }
43 }
44 57 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
45 }
46  
47 ▶ method send_hp_rendezvous ($target_id) {
Subroutine send_hp_rendezvous: not called CC=2 SCAR=17.9
Pod documented
48 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
49 0 my $payload = bencode( { id => $target_id, } );
50 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_RENDEZVOUS, $payload ) );
51 }
52  
53 ▶ method send_hp_connect ( $ip, $port ) {
Subroutine send_hp_connect: not called CC=2 SCAR=17.9
Pod documented
54 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
55 0 my $payload = bencode( { addr => $ip, port => $port, } );
56 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_CONNECT, $payload ) );
57 }
58  
59 ▶ method send_hp_error ($err_code) {
Subroutine send_hp_error: not called CC=2 SCAR=17.9
Pod documented
60 0 ▶ return unless exists $self->remote_extensions->{ut_holepunch};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->remote_extensions->{"ut_holepunch"} 0 0 0
61 0 my $payload = bencode( { e => $err_code, } );
62 0 $self->send_ext_message( 'ut_holepunch', pack( 'C a*', HP_ERROR, $payload ) );
63 }
64 25 } 1;
« lib/Net/BitTorrent/Protocol/BEP09.pm ↑ Summary lib/Net/BitTorrent/Tracker/Base.pm »