Branch Coverage

blib/lib/Net/BitTorrent/Peer.pm
Criterion Covered Total %
branch 238 512 46.4


line true false branch
136 0 135 unless (defined $args)
141 0 68 unless ($$args{'Socket'} or $$args{'Address'})
149 67 68 if ($$args{'Socket'}) { }
150 0 67 if (ref $$args{'Socket'} ne 'GLOB')
155 0 67 unless ($$args{'Client'} and blessed($$args{'Client'}) and $$args{'Client'}->isa('Net::BitTorrent'))
166 0 67 if (defined $ok and $ok == 0)
168 0 67 if (scalar grep({$$_{'Object'}->port eq $port if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->host and $$_{'Object'}->host eq $ip and $$_{'Object'}->port;} values %{$$args{'Client'}->_connections;}) > $$args{'Client'}->_connections_per_host)
169 406 0 if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->host and $$_{'Object'}->host eq $ip and $$_{'Object'}->port
188 0 67 unless $_client{refaddr $self}->_add_connection($self, 'ro')
193 67 0 $_client{refaddr $self}->_encryption_mode ? :
200 0 68 unless ($$args{'Address'} =~ /^(?:(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.]?){4}):\d+$/)
207 0 68 unless ($$args{'Torrent'} and blessed($$args{'Torrent'}) and $$args{'Torrent'}->isa('Net::BitTorrent::Torrent'))
214 0 68 unless ($$args{'Source'})
219 351 136 if $$_{'Object'}->isa('Net::BitTorrent::Peer')
223 0 68 if ($half_open >= $$args{'Torrent'}->_client->_half_open)
228 0 68 if (scalar $$args{'Torrent'}->peers >= $$args{'Torrent'}->_client->_peers_per_torrent)
233 1 67 if (scalar grep({$$_{'Object'}->port == $_port if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->host and $$_{'Object'}->host eq $_host and $$_{'Object'}->port;} values %{$$args{'Torrent'}->_client->_connections;}) > $$args{'Torrent'}->_client->_connections_per_host)
234 351 0 if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->host and $$_{'Object'}->host eq $_host and $$_{'Object'}->port
245 0 67 unless socket my $socket, 2, 1, getprotobyname 'tcp'
250 0 67 $^O eq 'MSWin32' ? :
0 67 unless ($^O eq 'MSWin32' ? ioctl($_socket{refaddr $self}, 2147772030, "\cA\000\000\000") : fcntl($_socket{refaddr $self}, 4, 2048))
275 32 35 if ($_client{refaddr $self}->_encryption_mode != 0 and not $$args{'_plaintext'}) { }
284 0 67 unless $_client{refaddr $self}->_add_connection($self, 'wo')
288 134 0 if ($self)
319 18 26 unless ($peerid{refaddr $s})
322 5 7 if (not $incoming{refaddr $self} and $torrent{refaddr $self} and $_state{refaddr $self} < REG_ONE())
358 0 134 if ($threads::shared::threads_shared)
359 0 0 if defined $bitfield{refaddr $self}
381 0 2198 if defined $_[1]
383 62 2136 unless ($port{refaddr $self})
384 0 62 unless defined $_socket{refaddr $self}
386 0 62 unless defined $peername
393 0 2198 if defined $_[1]
395 62 2136 unless ($host{refaddr $self})
396 0 62 unless defined $_socket{refaddr $self}
398 0 62 unless defined $peername
421 0 4657 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
427 0 4657 if ($error)
432 0 4657 if (defined $torrent{refaddr $self} and $torrent{refaddr $self}->status & 2)
439 322 4335 if ($read)
440 0 322 if ($_crypto_select{refaddr $self} == CRYPTO_RC4() and $_state{refaddr $self} >= REG_ONE()) { }
444 0 0 $incoming{refaddr $self} ? :
466 19 303 unless ($actual_read)
474 207 96 unless ($peerid{refaddr $self})
481 306 4332 if ($write and $_data_out{refaddr $self})
488 0 306 if (not $actual_write) { }
506 32 486 unless $data
509 0 486 if ($_crypto_select{refaddr $self} == CRYPTO_RC4() and $_state{refaddr $self} >= REG_ONE())
511 0 0 $incoming{refaddr $self} ? :
555 617 325 if ($_state{refaddr $self} != REG_OKAY()) { }
109 216 elsif (length $_data_in{refaddr $self}) { }
556 617 0 if (defined $_parse_packets_handshake_dispatch{$_state{refaddr $self}}) { }
572 0 166 unless ($packet)
573 0 0 if (length $_data_in{refaddr $self} != $data_len)
583 166 0 if (defined $_parse_packets_dispatch{$$packet{'Type'}}) { }
589 0 0 if (eval require Data::Dump) { }
616 942 0 unless $time
655 29 95 if ($_data_in{refaddr $self} =~ /^\x13BitTorrent protocol.{48}$/s)
667 63 32 if (length $_data_in{refaddr $self} < 96)
722 56 32 if (length $_data_in{refaddr $self} < 96)
743 0 32 unless $torrent{refaddr $self}
784 3 79 if (length $_data_in{refaddr $self} < 40)
803 51 28 if (index($_data_in{refaddr $self}, sha1('req1', $_S{refaddr $self})) == -1)
820 28 0 if ((sha1('req2', pack('H*', $torrent->infohash)) ^ sha1('req3', $_S{refaddr $self})) eq $req2_req3)
831 0 28 unless ($torrent{refaddr $self})
835 0 28 unless ($torrent{refaddr $self})
853 0 28 unless ($VC and $crypto_provide)
860 0 28 if (unpack('N', $crypto_provide) & CRYPTO_RC4()) { }
28 0 elsif (unpack('N', $crypto_provide) & CRYPTO_PLAIN()) { }
880 0 28 if ($IA)
881 0 0 if ($_crypto_select{refaddr $self} = CRYPTO_RC4())
909 0 70 if (length $_data_in{refaddr $self} < 34)
929 52 18 if ($index == -1)
930 31 21 if (length $_data_in{refaddr $self} >= 628) { }
932 31 0 unless $incoming{refaddr $self}
955 0 18 if (not $VC or $VC ne VC())
958 0 0 unless $incoming{refaddr $self}
980 0 18 if ($_crypto_select{refaddr $self} == CRYPTO_RC4())
987 0 18 if ($_data_in{refaddr $self})
1029 21 68 unless defined $_socket{refaddr $self}
1031 30 38 unless $_data_in{refaddr $self}
1033 0 38 unless defined $packet
1034 0 38 if ($$packet{'Type'} != HANDSHAKE())
1040 0 38 unless defined $payload
1062 0 38 if ($$payload[2] eq $_client{refaddr $self}->peerid)
1069 0 38 unless (defined $torrent{refaddr $self})
1078 0 38 if (scalar grep({$$_{'Object'}->peerid eq $peerid{refaddr $self} if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->peerid;} values %{$_client{refaddr $self}->_connections;}) > $_client{refaddr $self}->_connections_per_host)
1079 190 253 if $$_{'Object'}->isa('Net::BitTorrent::Peer') and $$_{'Object'}->peerid
1090 0 38 if (scalar $torrent{refaddr $self}->peers >= $_client{refaddr $self}->_peers_per_torrent)
1095 0 38 if ($threads::shared::threads_shared)
1126 0 81 unless defined $_socket{refaddr $self}
1128 54 27 unless $_data_in{refaddr $self}
1130 0 27 unless defined $packet
1131 0 27 if ($$packet{'Type'} != HANDSHAKE())
1137 0 27 unless defined $payload
1162 0 27 if ($$payload[2] eq $_client{refaddr $self}->peerid)
1169 0 27 if ($$payload[1] ne pack('H*', $torrent{refaddr $self}->infohash))
1189 0 0 unless defined $torrent{refaddr $self}
1190 0 0 unless defined $_socket{refaddr $self}
1191 0 0 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1212 0 0 unless defined $torrent{refaddr $self}
1213 0 0 unless defined $_socket{refaddr $self}
1214 0 0 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1243 0 17 unless defined $torrent{refaddr $self}
1244 0 17 unless defined $_socket{refaddr $self}
1245 0 17 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1267 0 17 unless defined $torrent{refaddr $self}
1268 0 17 unless defined $_socket{refaddr $self}
1269 0 17 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1293 0 2 unless defined $torrent{refaddr $self}
1294 0 2 unless defined $_socket{refaddr $self}
1295 0 2 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1318 0 24 unless defined $torrent{refaddr $self}
1319 0 24 unless defined $_socket{refaddr $self}
1320 0 24 unless defined $index
1321 0 24 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1335 0 24 if (not unpack('b*', ${$bitfield{refaddr $self};}) =~ /1/ and $torrent{refaddr $self}->is_complete)
1342 0 24 if (${$am_interested{refaddr $self};} and not ${$peer_choking{refaddr $self};})
1353 0 0 unless defined $torrent{refaddr $self}
1354 0 0 unless defined $_socket{refaddr $self}
1355 0 0 unless defined $payload
1356 0 0 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1370 0 0 if (not unpack('b*', ${$bitfield{refaddr $self};}) =~ /1/ and $torrent{refaddr $self}->is_complete)
1384 0 5 unless defined $torrent{refaddr $self}
1385 0 5 unless defined $_socket{refaddr $self}
1386 0 5 unless defined $payload
1387 0 5 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1403 5 0 unless (@{$requests_in{refaddr $self};})
1422 0 3 unless defined $payload
1423 0 3 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1430 0 3 unless defined $torrent{refaddr $self}
1431 0 3 unless defined $_socket{refaddr $self}
1434 3 0 if $$_{'Index'} == $index and $$_{'Offset'} == $offset
1439 0 3 unless (defined $request)
1445 3 0 unless $$_{'Index'} != $index or $$_{'Offset'} != $offset
1463 3 0 if ($torrent{refaddr $self}->_write_data($index, $offset, \$data))
1468 0 3 unless $okay
1474 0 0 if (defined $requests_out{refaddr $peer}[$x] and $requests_out{refaddr $peer}[$x]{'Index'} == $index and $requests_out{refaddr $peer}[$x]{'Offset'} == $offset and $requests_out{refaddr $peer}[$x]{'Length'} == $length)
1503 3 0 unless (grep {not $_;} @{$$piece{'Blocks_Received'};})
1504 3 0 if ($torrent{refaddr $self}->_check_piece_by_index($index) and defined $torrent{refaddr $self})
1512 0 3 if $self->_check_interest
1521 0 0 unless defined $torrent{refaddr $self}
1522 0 0 unless defined $_socket{refaddr $self}
1523 0 0 unless defined $payload
1524 0 0 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1542 0 0 if ($requests_in{refaddr $self}[$x]{'Index'} == $index and $requests_in{refaddr $self}[$x]{'Offset'} == $offset and $requests_in{refaddr $self}[$x]{'Length'} == $length)
1558 0 9 unless defined $torrent{refaddr $self}
1559 0 9 unless defined $_socket{refaddr $self}
1560 0 9 if (!$torrent{refaddr $self}->status & 1)
1574 3 6 if ($torrent{refaddr $self}->is_complete)
1580 0 6 if (${$am_interested{refaddr $self};} and not ${$peer_choking{refaddr $self};})
1591 0 39 unless defined $torrent{refaddr $self}
1592 0 39 unless defined $_socket{refaddr $self}
1593 0 39 unless ($torrent{refaddr $self}->status & 1)
1614 0 0 unless defined $torrent{refaddr $self}
1615 0 0 unless defined $_socket{refaddr $self}
1616 0 0 unless defined $payload
1632 0 0 unless defined $payload
1633 0 0 unless defined $torrent{refaddr $self}
1634 0 0 unless defined $_socket{refaddr $self}
1636 0 0 if $$_{'Index'} == $index and $$_{'Offset'} == $offset
1642 0 0 unless (defined $request)
1647 0 0 unless $$_{'Index'} != $index or $$_{'Offset'} != $offset
1653 0 0 unless (defined $piece)
1676 0 50 unless defined $torrent{refaddr $self}
1677 3 47 unless defined $_socket{refaddr $self}
1678 0 47 unless defined $payload
1679 0 47 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
1685 0 47 if $torrent{refaddr $self}->status & 32
1687 47 0 if ($packet)
1688 47 0 if ($id == 0)
1689 0 47 if (defined $_client{refaddr $self}->_dht and defined $$packet{'p'})
1716 0 72 unless ($torrent{refaddr $self})
1717 0 72 unless ($torrent{refaddr $self}->status & 1)
1722 0 72 if $torrent{refaddr $self}->status & 32
1727 18 54 index(unpack('b*', $relevence), '1', 0) != -1 ? :
1728 17 55 if ($interesting and not ${$am_interested{refaddr $self};}) { }
3 53 elsif (not $interesting and ${$am_interested{refaddr $self};}) { }
1749 0 0 unless defined $self
1750 0 0 if ($_last_contact{refaddr $self} < time - 180)
1755 0 0 if (${$peer_choking{refaddr $self};} and ${$am_interested{refaddr $self};})
1760 0 0 if (${$peer_choking{refaddr $self};} and not ${$am_interested{refaddr $self};} and not ${$peer_interested{refaddr $self};})
1780 0 36 unless defined $self
1781 7 29 unless defined $_socket{refaddr $self}
1788 0 29 if (@{$requests_out{refaddr $self};} == [])
1793 1 0 if (time <= $$request{'Timestamp'} + 60)
1800 0 0 if (not $$piece{'Touch'} or $$piece{'Touch'} <= time - 180)
1822 0 29 if $canceled
1831 0 17 unless defined $_socket{refaddr $self}
1832 0 17 if ${$peer_choking{refaddr $self};}
1833 0 17 unless ($torrent{refaddr $self}->status & 1)
1839 0 17 if $torrent{refaddr $self}->status & 32
1844 17 0 defined $_range ? :
1855 18 4 if ($piece) { }
1857 0 18 if ($$piece{'Endgame'}) { }
1866 0 0 $_ < 5 && $$piece{'Blocks_Received'}[$tmp_index] == 0 ? :
1877 0 0 if defined $$piece{'Blocks_Requested'}[$index]{refaddr $self}
0 0 unless (grep {$$piece{'Blocks_Received'}[$index] or $$piece{'Index'} == $$_{'Index'} and $index == $$_{'_vec_offset'} if defined $$piece{'Blocks_Requested'}[$index]{refaddr $self};} @{$requests_out{refaddr $self};})
1895 5 13 unless (keys %{$$piece{'Blocks_Requested'}[$i];})
1901 13 5 if (not defined $vec_offset or $vec_offset == -1)
1913 5 0 $vec_offset + 1 == $$piece{'Block_Count'} ? :
1953 0 65 unless defined $torrent{refaddr $self}
1954 0 65 if !$torrent{refaddr $self}->status & 1
1956 0 65 unless defined $_socket{refaddr $self}
1957 0 65 unless defined $reserved_bytes{refaddr $self}
1960 26 494 if $x
1963 50 15 if (scalar @have == 0 and ord substr($reserved_bytes{refaddr $self}, 7, 1) & 4) { }
11 4 elsif (scalar @have == $self->torrent->piece_count and ord substr($reserved_bytes{refaddr $self}, 7, 1) & 4) { }
0 4 elsif (scalar @have > 12) { }
2001 0 65 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
2008 0 65 unless defined $torrent{refaddr $self}
2009 0 65 unless defined $_socket{refaddr $self}
2010 0 65 unless defined $reserved_bytes{refaddr $self}
2012 0 65 unless ord substr($reserved_bytes{refaddr $self}, 5, 1) & 16
2016 5 60 $_client{refaddr $self}->_use_dht ? :
65 0 $_packed_ip ? :
2041 0 0 unless defined $self
2042 0 0 unless defined $_socket{refaddr $self}
2043 0 0 unless defined $torrent{refaddr $self}
2044 0 0 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
2056 0 0 if $torrent{refaddr $self}->status & 32
2072 0 5 unless defined $torrent{refaddr $self}
2073 0 5 unless defined $_socket{refaddr $self}
2074 0 5 if $torrent{refaddr $self}->status & 32
2075 0 5 unless @{$requests_in{refaddr $self};}
2076 0 5 if ${$am_choking{refaddr $self};}
2077 0 5 if (defined $torrent{refaddr $self} and not $torrent{refaddr $self}->status & 1)
2084 0 5 if (defined $torrent{refaddr $self} and $torrent{refaddr $self}->status & 32)
2092 0 5 unless $torrent{refaddr $self}->_check_piece_by_index($$request{'Index'})
2094 0 5 unless $$request{'Length'}
2124 0 5 if @{$requests_in{refaddr $self};}
2125 0 5 unless $_client{refaddr $self}->_add_connection($self, 'rw')
2133 0 0 unless defined $torrent{refaddr $self}
2134 0 0 unless defined $_socket{refaddr $self}
2135 0 0 if (defined $torrent{refaddr $self} and $torrent{refaddr $self}->status & 2)
2141 0 0 if ${$am_choking{refaddr $self};} == 1
2152 0 0 unless $_client{refaddr $self}->_add_connection($self, 'rw')
2160 0 17 unless defined $torrent{refaddr $self}
2161 0 17 unless defined $_socket{refaddr $self}
2162 0 17 if (defined $torrent{refaddr $self} and $torrent{refaddr $self}->status & 2)
2168 0 17 if $torrent{refaddr $self}->status & 32
2169 0 17 if ${$am_choking{refaddr $self};} == 0
2170 17 0 if (scalar grep({$_->am_choking == 0;} $torrent{refaddr $self}->peers) <= 16) { }
2177 0 17 unless $_client{refaddr $self}->_add_connection($self, 'rw')
2204 40 31 if (defined $_socket{refaddr $self})
2209 0 71 $extra ? :
2222 0 0 $_ ? :
2256 0 0 !$advanced ? :
0 0 $peerid{refaddr $self} ? :
0 0 $torrent{refaddr $self} ? :
0 0 $incoming{refaddr $self} ? :
0 0 vec(${$bitfield{refaddr $self};}, $_, 1) ? :
0 0 $_state{refaddr $self} == REG_OKAY() ? :
2262 0 0 defined wantarray ? :
2283 23 1 if ($torrent{refaddr $self})
2316 176 208 if ($reset or not $_RC4_S{refaddr $self}{$pass})