DirectConnect.pm

filter: Statementstmt 6.2% 57 / 911 Branchbran 0.5% 3 / 574 Conditioncond 0.3% 2 / 548 MC/DCmcdc 0.0% 0 / 314 Subroutinesub 15.8% 16 / 101 Podpod 0.0% 0 / 73 totaltotal 3.0% 78 / 2521 CC 525 SCAR 60.3
CC
525
Cov
3%
new
1806.0
recv
1122.0
parser
930.0
CRAP 416.8
« DirectConnect/adc.pm ↑ Summary DirectConnect/pslib/psmisc.pm »
1 #$Id: DirectConnect.pm 1002 2014-08-27 14:35:23Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/lib/Net/DirectConnect.pm $
2 package Net::DirectConnect;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings "NONFATAL" => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '0.14'; # . '_' . ( split ' ', '$Revision: 1002 $' )[1];
9 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #use Fcntl;
16 1 ▶use Time::HiRes qw(time sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 $Data::Dumper::Sortkeys = $Data::Dumper::Useqq = $Data::Dumper::Indent = $Data::Dumper::Terse = 1;
19 1 our $AUTOLOAD;
20 1 our %global;
21 0 ▶sub is_code ($) { UNIVERSAL::isa( $_[0], 'CODE' ) }
Subroutine is_code: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub code_run ($;@) { my $f = shift; return $f->(@_) if is_code $f }
Subroutine code_run: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if &is_code($f) 0 0 0
23 0 ▶sub is_object ($) { ref $_[0] and ref $_[0] ne 'HASH' }
Subroutine is_object: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] and ref $_[0] ne "HASH" 0 0 0
24 0 ▶sub can_run ($$;@) { my $c = shift || return; return unless is_object $c; my $f = shift || return; my $r = $c->can($f); return $r->( $c, @_ ) if $r; }
Subroutine can_run: not called CC=5 SCAR=34.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
unless &is_object($c) 0 0 0
if $r 0 0 0
Condition0%0/4
shift() || (return)
l!l
00
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
25  
26 0 ▶sub float { #v1
Subroutine float: not called CC=6 SCAR=37.4
Pod undocumented
27 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
28 0 ▶ return ( $_[0] < 8 and $_[0] - int( $_[0] ) )
Branch: 3 branches
BranchTrueFalseTotal
$_[0] < 8 && $_[0] - int($_[0]) ? : 0 0 0
$_[0] < 1 ? : 0 0 0
$_[0] < 3 ? : 0 0 0
Condition0%0/3
$_[0] < 8 and $_[0] - int($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] < 8 and $_[0] - int($_[0])
$_[0] < 8 $_[0] - int($_[0])
Truth table0%0/3
A and B
A= $_[0] < 8B= $_[0] - int($_[0])
ABresult
0X0
100
111
29 ? sprintf( '%.' . ( $_[0] < 1 ? 3 : ( $_[0] < 3 ? 2 : 1 ) ) . 'f', $_[0] )
30 : int( $_[0] );
31 }
32  
33 0 ▶sub mkdir_rec(;$$) {
Subroutine mkdir_rec: not called CC=6 SCAR=37.4
Pod undocumented
34 0 ▶ local $_ = shift // $_;
Condition0%0/3
shift() // $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $_
shift() $_
Truth table0%0/3
A // B
A= shift()B= $_
ABresult
1X1
011
000
35 0 ▶ $_ .= '/' unless m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless m[/$] 0 0 0
36 0 ▶ while (m{/}g) { @_ ? mkdir $`, $_[0] : mkdir $` if length $` }
Branch: 3 branches
BranchTrueFalseTotal
if (m[/]g) 0 0 0
if length $` 0 0 0
@_ ? : 0 0 0
37 }
38  
39 0 ▶sub send_udp ($$;@) {
Subroutine send_udp: not called CC=6 SCAR=37.4
Pod undocumented
40 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
41 0 my $host = shift;
42 #$host =~ s/:(\d+)$//;
43 0 my $port = shift;
44 #$port ||= $1;
45 0 $self->log( 'dcdev', "sending UDP to [$host]:[$port] = [$_[0]]" );
46 #$self->log( 'dcdev', "sending UDP to [$host] = [$_[0]]" );
47 0 ▶ my $opt = $_[1] || {};
Condition0%0/2
$_[1] || {}
l!l
00
MC/DC0%0/1
$_[1] || {}
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
48 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (my $s = $self->{'socket_class'}->new('PeerAddr', $host, $port ? ('PeerPort', $port) : (), 'Proto', 'udp', 'Timeout', $opt->{'Timeout'}, ('Blocking', 0), %{$opt->{'socket_options'} or {};})) { } 0 0 0
$port ? : 0 0 0
49 my $s = $self->{'socket_class'}->new(
50 'PeerAddr' => $host,
51 ( $port ? ( 'PeerPort' => $port ) : () ),
52 'Proto' => 'udp',
53 'Timeout' => $opt->{'Timeout'}, (
54 #$opt->{'nonblocking'} ? (
55 'Blocking' => 0,
56 #'MultiHomed' => 1, #del
57 #) : ()
58 ),
59 0 ▶ %{ $opt->{'socket_options'} || {} },
Condition0%0/2
$opt->{'socket_options'} || {}
l!l
00
MC/DC0%0/1
$opt->{'socket_options'} || {}
$opt->{'socket_options'}
Truth table0%0/2
A
A= $opt->{'socket_options'}
Aresult
11
00
60 )
61 )
62 {
63 0 $s->send( Encode::encode $self->{charset_protocol}, $_[0], Encode::FB_WARN );
64 0 $self->{bytes_send} += length $_[0];
65 #$s->shutdown(2);
66 0 $s->close();
67 #close($s);
68 #$self->log( 'dcdev', "sent ",length $_[0]," closed [$s],");
69 } else {
70 #$self->log( 'dcerr', "FAILED sending UDP to $host :$port = [$_[0]]" );
71 0 $self->log( 'dcerr', "FAILED sending UDP to $host = [$_[0]]" );
72 }
73 }
74  
75 0 ▶sub socket_addr ($) {
Subroutine socket_addr: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my ($socket) = @_;
77 0 ▶ return wantarray ? ( $socket->peerhost, $socket->peerport ) : $socket->peerhost;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
78  
79 =old
80 local @_;
81 #eval { @_ = unpack_sockaddr_in( getpeername($socket) || return ) };
82 eval { @_ = unpack_sockaddr_in( $socket->peername || return ) };
83 return unless $_[1];
84 return unless $_[1] = inet_ntoa( $_[1] );
85 return @_;
86 =cut
87  
88 =todo
89 my ($err, $hostname, $servicename) = Socket::getnameinfo($socket->peername);
90 if ($err) {
91 if (use_try 'Socket6') {
92 #warn "Cannot getnameinfo - $err; $hostname, $servicename" ;
93 $hostname = Socket6::getnameinfo($socket->peername);
94 }
95 }
96 warn 'getn', $hostname,$servicename;
97 return wantarray ? ($hostname,$servicename) : $hostname;
98 =cut
99  
100 }
101  
102 sub schedule($$;@)
103 0 ▶{ #$Id: DirectConnect.pm 1002 2014-08-27 14:35:23Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/lib/Net/DirectConnect.pm $
Subroutine schedule: not called CC=16 SCAR=56.1
Pod undocumented
104 0 our %schedule;
105 0 my ( $every, $func ) = ( shift, shift );
106 0 my $p;
107 0 ▶ ( $p->{'wait'}, $p->{'every'}, $p->{'runs'}, $p->{'cond'}, $p->{'id'} ) = @$every if ref $every eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $every eq "ARRAY" 0 0 0
108 0 ▶ $p = $every if ref $every eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $every eq "HASH" 0 0 0
109 0 ▶ $p->{'every'} ||= $every if !ref $every;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $every 0 0 0
Condition0%0/3
$p->{"every"} ||= $every
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"every"} ||= $every
$p->{"every"} $every
Truth table0%0/3
A ||= B
A= $p->{"every"}B= $every
ABresult
1X1
011
000
110 0 ▶ $p->{'id'} ||= join ';', caller;
Condition0%0/3
$p->{"id"} ||= join(";", caller)
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"id"} ||= join(";", caller)
$p->{"id"} join(";", caller)
Truth table0%0/3
A ||= B
A= $p->{"id"}B= join(";", caller)
ABresult
1X1
011
000
111 #dmp $p, \%schedule;
112 #dmp $schedule{ $p->{'id'} }{'runs'}, $p->{'runs'}, $p, $schedule{ $p->{'id'} } if $p->{'runs'};
113 0 ▶ $schedule{ $p->{'id'} }{'func'} = $func if !$schedule{ $p->{'id'} }{'func'} or $p->{'update'};
Branch: 1 branch
BranchTrueFalseTotal
if not $Net::DirectConnect::schedule{$p->{"id"}}{"func"} or $p->{"update"} 0 0 0
Condition0%0/3
not $Net::DirectConnect::schedule{$p->{"id"}}{"func"} or $p->{"update"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $Net::DirectConnect::schedule{$p->{"id"}}{"func"} or $p->{"update"}
not $Net::DirectConnect::schedule{$p->{"id"}}{"func"} $p->{"update"}
Truth table0%0/3
not(A) or B
A= not $Net::DirectConnect::schedule{$p->{"id"}}{"func"}B= $p->{"update"}
ABresult
1X1
011
000
114 0 ▶ $schedule{ $p->{'id'} }{'last'} = time - $p->{'every'} + $p->{'wait'} if $p->{'wait'} and !$schedule{ $p->{'id'} }{'last'};
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"wait"} and not $Net::DirectConnect::schedule{$p->{"id"}}{"last"} 0 0 0
Condition0%0/3
$p->{"wait"} and not $Net::DirectConnect::schedule{$p->{"id"}}{"last"}
!ll&&!rl&&r
000
MC/DC0%0/2
$p->{"wait"} and not $Net::DirectConnect::schedule{$p->{"id"}}{"last"}
$p->{"wait"} not $Net::DirectConnect::schedule{$p->{"id"}}{"last"}
Truth table0%0/3
A and not(B)
A= $p->{"wait"}B= not $Net::DirectConnect::schedule{$p->{"id"}}{"last"}
ABresult
0X0
100
111
115 #dmp("RUN", $p->{'id'}),
116 ++$schedule{ $p->{'id'} }{'runs'}, $schedule{ $p->{'id'} }{'last'} = time, $schedule{ $p->{'id'} }{'func'}->(@_),
117 if ( $schedule{ $p->{'id'} }{'last'} + $p->{'every'} < time )
118 and ( !$p->{'runs'} or $schedule{ $p->{'id'} }{'runs'} < $p->{'runs'} )
119 and ( !( ref $p->{'cond'} eq 'CODE' ) or $p->{'cond'}->( $p, $schedule{ $p->{'id'} }, @_ ) )
120 0 ▶ and ref $schedule{ $p->{'id'} }{'func'} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() and !$p->{"runs"} || $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"} and !(ref $p->{"cond"} eq "CODE") || $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_) and ref $Net::DirectConnect::schedule{$p->{"id"}}{"func"} eq "CODE" 0 0 0
Condition0%0/15
$Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() and !$p->{"runs"} || $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"} and !(ref $p->{"cond"} eq "CODE") || $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_) and ref $Net::DirectConnect::schedule{$p->{"id"}}{"func"} eq "CODE"
!ll&&!rl&&r
000
$Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() and !$p->{"runs"} || $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"} and !(ref $p->{"cond"} eq "CODE") || $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_)
!ll&&!rl&&r
000
$Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() and !$p->{"runs"} || $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"}
!ll&&!rl&&r
000
not $p->{"runs"} or $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"}
l!l&&r!l&&!r
000
not ref $p->{"cond"} eq "CODE" or $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_)
l!l&&r!l&&!r
000
MC/DC0%0/6
$Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() and !$p->{"runs"} || $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"} and !(ref $p->{"cond"} eq "CODE") || $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_) and ref $Net::DirectConnect::schedule{$p->{"id"}}{"func"} eq "CODE"
$Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time() not $p->{"runs"} $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"} not ref $p->{"cond"} eq "CODE" $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_) ref $Net::DirectConnect::schedule{$p->{"id"}}{"func"} eq "CODE"
Truth table0%0/12
A and not(B) or C and not(D) or E and F
A= $Net::DirectConnect::schedule{$p->{"id"}}{"last"} + $p->{"every"} < &Net::DirectConnect::time()B= not $p->{"runs"}C= $Net::DirectConnect::schedule{$p->{"id"}}{"runs"} < $p->{"runs"}D= not ref $p->{"cond"} eq "CODE"E= $p->{"cond"}->($p, $Net::DirectConnect::schedule{$p->{"id"}}, @_)F= ref $Net::DirectConnect::schedule{$p->{"id"}}{"func"} eq "CODE"
ABCDEFresult
0XXXXX0
100XXX0
11X00X0
10100X0
11X1X00
11X0100
1011X00
1010100
11X1X11
11X0111
1011X11
1010111
121 }
122  
123 0 ▶sub notone (@) {
Subroutine notone: not called CC=3 SCAR=24.8
Pod undocumented
124 0 ▶ @_ = grep { $_ and $_ != 1 } @_;
Condition0%0/3
$_ && $_ != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && $_ != 1
$_ $_ != 1
Truth table0%0/3
A && B
A= $_B= $_ != 1
ABresult
0X0
100
111
125 0 ▶ wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
126 }
127  
128 1 ▶sub use_try ($;@) {
Subroutine use_try: called CC=5 SCAR=17.6
Pod undocumented
129 1 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 1 1
130 1 our %tried;
131 1 ( my $path = ( my $module = shift ) . '.pm' ) =~ s{::}{/}g;
132 1 ▶ return $tried{$module} if exists $tried{$module};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Net::DirectConnect::tried{$module} 0 1 1
133 1 local $SIG{__DIE__} = undef;
134 1 ▶ $tried{$module} = ( $INC{$path} or eval 'use ' . $module . ' qw(' . ( join ' ', @_ ) . ');1;' and $INC{$path} );
Subroutine BEGIN: called CC=1 SCAR=0.6
Condition33%2/6
$INC{$path} || eval 'use ' . $module . ' qw(' . join(' ', @_) . ');1;' && $INC{$path}
l!l&&r!l&&!r
010
eval 'use ' . $module . ' qw(' . join(" ", @_) . ');1;' and $INC{$path}
!ll&&!rl&&r
001
MC/DC0%0/3
$INC{$path} || eval 'use ' . $module . ' qw(' . join(' ', @_) . ');1;' && $INC{$path}
$INC{$path} eval 'use ' . $module . ' qw(' . join(" ", @_) . ');1;' $INC{$path}
Truth table25%1/4
A || B and C
A= $INC{$path}B= eval 'use ' . $module . ' qw(' . join(" ", @_) . ');1;'C= $INC{$path}
ABCresult
1XX1
0111
00X0
0100
135 }
136  
137 0 ▶sub module_load {
Subroutine module_load: not called CC=8 SCAR=42.8
Pod undocumented
138 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
139 0 local $_ = shift;
140 0 ▶ return unless length $_;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
141 #$self->log( 'dev', "loading", $_, $self->{'module_loaded'}{$_});
142 0 ▶ return if $self->{'module_loaded'}{$_}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"module_loaded"}{$_}++ 0 0 0
143 0 my $module = __PACKAGE__ . '::' . $_;
144 #eval "use $module;";
145 0 ▶ $self->log( 'err', 'cant load', $module, $@ ), return unless use_try $module;
Branch: 1 branch
BranchTrueFalseTotal
unless &use_try($module) 0 0 0
146 #$self->log( 'err', 'cant load', $module, $@ ), return if $@;
147 #${module}::new($self, @_) if $module->can('new');
148 #${module}::init($self, @_) if $module->can('init');
149 #$self->log( 'dev', 'can', $module->can('new'));
150 #$self->log( 'dev', 'can', $module->can('init'));
151 #eval "$module\::new(\$self, \@_);"; #, \@param
152 0 ▶ $_->( $self, @_ ) if $_ = $module->can('new') and $_ ne __PACKAGE__->can('new');
Branch: 1 branch
BranchTrueFalseTotal
if $_ = $module->can("new") and $_ ne __PACKAGE__->can("new") 0 0 0
Condition0%0/3
$_ = $module->can("new") and $_ ne __PACKAGE__->can("new")
!ll&&!rl&&r
000
MC/DC0%0/2
$_ = $module->can("new") and $_ ne __PACKAGE__->can("new")
$_ = $module->can("new") $_ ne __PACKAGE__->can("new")
Truth table0%0/3
A and B
A= $_ = $module->can("new")B= $_ ne __PACKAGE__->can("new")
ABresult
0X0
100
111
153 0 ▶ $_->( $self, @_ ) if $_ = $module->can('init');
Branch: 1 branch
BranchTrueFalseTotal
if $_ = $module->can("init") 0 0 0
154 #$self->log( 'err', 'cant new', $module, $@ ), return if $@;
155 #eval "$module\::init(\$self, \@_);"; #, \@param
156 #$self->log( 'err', 'cant init', $module, $@ ), return if $@;
157 # $self->log( 'ddev', 'loaded module', $module, );
158 0 1;
159 }
160  
161 0 ▶sub new {
Subroutine new: not called CC=42 SCAR=75.0
Pod undocumented
162 #print 'NEW:',Dumper \@_;
163 0 my $class = shift;
164 0 my $self = {};
165 0 ▶ if ( ref $class eq __PACKAGE__ ) { $self = $class; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class eq __PACKAGE__) { } 0 0 0
166 0 ▶ else { bless( $self, $class ) unless ref $class; }
Branch: 1 branch
BranchTrueFalseTotal
unless ref $class 0 0 0
167 #print ref $self;
168 #$self-
169 #psmisc::printlog('dev', 'new', @_);
170 #psmisc::printlog('dev', 'func', Dumper @_);
171 0 ▶ $self->{'number'} ||= ++$global{'total'};
Condition0%0/3
$self->{"number"} ||= ++$Net::DirectConnect::global{"total"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"number"} ||= ++$Net::DirectConnect::global{"total"}
$self->{"number"} ++$Net::DirectConnect::global{"total"}
Truth table0%0/3
A ||= B
A= $self->{"number"}B= ++$Net::DirectConnect::global{"total"}
ABresult
1X1
011
000
172 0 ++$global{'count'};
173 #$self->log('dev', 'new', @_);
174 0 $self->func(@_); #@param
175 0 ▶ eval { $self->{'recv_flags'} = MSG_DONTWAIT; } unless $^O =~ /win/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O =~ /win/i 0 0 0
176 0 ▶ $self->{'recv_flags'} ||= 0;
Condition0%0/2
$self->{"recv_flags"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"recv_flags"} ||= 0
$self->{"recv_flags"}
Truth table0%0/2
A
A= $self->{"recv_flags"}
Aresult
11
00
177 #psmisc::printlog('dev', 'init');
178 0 $self->init_main(@_); #@param
179 0 $self->init(@_); #@param
180 #}
181 0 $self->{activity} = time;
182 #$self->{$_} ||= $self->{'parent'}{$_} for grep { exists $self->{'parent'}{$_} } qw(log sockets select select_send);
183 #(!$self->{'parent'}{$_} ? () : $self->{$_} = $self->{'parent'}{$_} ) for qw(log );
184 #$self->{'log'} = $self->{'parent'}{'log'} if $self->{'parent'}{'log'};
185 #$self->{$_} ||= $self->{'parent'}{$_} ||= {}
186 #$self->log( 'dev', '1uphandler my=',$self->{handler},Dumper($self->{handler}) , 'p=',Dumper($self->{'parent'}{handler}),$self->{'parent'}{handler},);
187 #$self->{'parent'}{$_} ||= {} , $self->{$_} ||= $self->{'parent'}{$_},
188 #$self->log( 'dev', '2uphandler my=',$self->{handler},Dumper($self->{handler}) , 'p=',Dumper($self->{'parent'}{handler}),$self->{'parent'}{handler},);
189 #$self->log( 'dev', "my number=$self->{'number'} total=$global{'total'} count=$global{'count'}" );
190 #$self->log( 'dev', $class ,' eq ', __PACKAGE__);
191 0 ▶ if ( $class eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
192 #local %_ = (@_);
193 #$self->log( 'dev', $class ,' eq ', __PACKAGE__, Dumper @_);
194  
195 #for keys
196 #$self->{$_} = $_{$_} for keys %_;
197 #$self->log( 'init00', $self, "h=$self->{'host'}", 'p=', $self->{'protocol'}, 'm=', $self->{'module'} );
198 0 ▶ if ( $self->{'host'} ~~ m{^(?:\w+://)?broadcast} or $self->{'host'} =~ /^(?:255\.|\[?ff)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"host"} ~~ qr"^(?:\w+://)?broadcast" or $self->{"host"} =~ /^(?:255\.|\[?ff)/i) 0 0 0
Condition0%0/3
$self->{"host"} ~~ qr"^(?:\w+://)?broadcast" or $self->{"host"} =~ /^(?:255\.|\[?ff)/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"host"} ~~ qr"^(?:\w+://)?broadcast" or $self->{"host"} =~ /^(?:255\.|\[?ff)/i
$self->{"host"} ~~ qr"^(?:\w+://)?broadcast" $self->{"host"} =~ /^(?:255\.|\[?ff)/i
Truth table0%0/3
A or B
A= $self->{"host"} ~~ qr"^(?:\w+://)?broadcast"B= $self->{"host"} =~ /^(?:255\.|\[?ff)/i
ABresult
1X1
011
000
199 #if (use_try 'Socket::Multicast6', 'ipv6') {
200 #IPV6_JOIN_GROUP
201 #}
202 0 ▶ $self->{'protocol'} ||= 'adc';
Condition0%0/2
$self->{"protocol"} ||= "adc"
l!l
00
MC/DC0%0/1
$self->{"protocol"} ||= "adc"
$self->{"protocol"}
Truth table0%0/2
A
A= $self->{"protocol"}
Aresult
11
00
203 0 $self->{'auto_listen'} = 1;
204 0 delete $self->{'auto_connect'};
205 0 $self->{'Proto'} = 'udp';
206 0 $self->{'socket_options'}{'Broadcast'} = 1;
207 0 $self->{'socket_options'}{'ReuseAddr'} = 1;
208 #$self->{'host'} = $self->{dev_ipv6} ? 'ff02::1' : inet_ntoa(INADDR_BROADCAST) if $self->{'host'} !~ /^(?:255\.|\[?ff)/i;
209 0 ▶ $self->{'host'} = inet_ntoa(INADDR_BROADCAST) if $self->{'host'} !~ /^(?:255\.|\[?ff)/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"host"} =~ /^(?:255\.|\[?ff)/i 0 0 0
210 #$self->{socket_options_listen}{'LocalHost'} = 'ff02::1';
211 #$self->{'port'},
212 #$self->log( 'dev', "send to", );
213 0 $self->{'broadcast'} = 1;
214 #$self->{'lis'} = 1;
215 #$self->log('dev', "broadcast=$self->{'host'}, auto_listen=$self->{'auto_listen'} auto_connect=$self->{'auto_connect'}");
216 }
217 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"protocol"} and $self->{"host"}) 0 0 0
Condition0%0/3
not $self->{"protocol"} and $self->{"host"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"protocol"} and $self->{"host"}
not $self->{"protocol"} $self->{"host"}
Truth table0%0/3
not(A) and B
A= not $self->{"protocol"}B= $self->{"host"}
ABresult
0X0
100
111
218 #!$self->{'module'} and
219 !$self->{'protocol'} and $self->{'host'}
220 )
221 {
222 #$self->log( 'proto0 ', $1);
223 0 ▶ my $p = lc $1 if $self->{'host'} =~ m{^(.+?)://};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"host"} =~ m[^(.+?)://] 0 0 0
224 #$self->protocol_init($p);
225 0 $self->{'protocol'} = $p;
226 $self->{'protocol'} = 'nmdc'
227 if !$self->{'protocol'}
228 0 ▶ or $self->{'protocol'} eq 'dchub';
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"protocol"} or $self->{"protocol"} eq "dchub" 0 0 0
Condition0%0/3
not $self->{"protocol"} or $self->{"protocol"} eq "dchub"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->{"protocol"} or $self->{"protocol"} eq "dchub"
not $self->{"protocol"} $self->{"protocol"} eq "dchub"
Truth table0%0/3
not(A) or B
A= not $self->{"protocol"}B= $self->{"protocol"} eq "dchub"
ABresult
1X1
011
000
229 #$self->{'protocol'}
230 #$self->log( 'proto ', $self->{'protocol'} );
231 }
232 #$self->{'module'} ||= $self->{'protocol'};
233 #if ( $self->{'module'} eq 'nmdc' ) {
234 # $self->{'module'} = [ 'nmdc', ( $self->{'hub'} ? 'hubcli' : 'clihub' ) ];
235 #}
236 0 ++$self->{'module'}{ $self->{'protocol'} };
237 0 ▶ if ( $self->{'protocol'} eq 'nmdc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"protocol"} eq "nmdc") 0 0 0
238 0 ▶ ++$self->{'module'}{ $self->{'hub'} ? 'hubcli' : 'clihub' };
Branch: 1 branch
BranchTrueFalseTotal
$self->{'hub'} ? : 0 0 0
239 }
240 #++$self->{'module'}{$_} for grep { $self->{ 'dev_' . $_ } } qw(ipv6);
241 #, ($] < 5.014 ? 'ipv6' : ()); #sctp
242 #if ( $self->{'module'} ) {
243 }
244 0 ▶ if ( $self->{'dev_sctp'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dev_sctp"}) 0 0 0
245 0 ▶ unless ( $self->{'no_sctp_fallback'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'no_sctp_fallback'}) { } 0 0 0
246 0 $self->log( 'dev', 'make sctp clone', $class );
247 0 $self->{'clients'}{ 'sctp_' . $self->{'number'} } = $class->new(
248 @_,
249 'dev_sctp' => undef,
250 'parent' => $self,
251 auto_work => 0,
252 no_wait_connect => 1,
253 #reconnect_tries=>1,
254 #myport_tries=>1,
255 #'Proto' => 'sctp',
256 modules => [qw(sctp)],
257 );
258 } else {
259 0 ++$self->{'module'}{'sctp'};
260 }
261 0 $self->info;
262 }
263 0 ++$self->{'module'}{$_} for grep { $self->{'protocol'} eq $_ } qw(adcs http);
264 #$self->log( 'dev', 'module load', $self->{'module'}, 'p', $self->{'protocol'} );
265 0 my @modules; #= ($self->{'module'});
266 0 for (qw(module modules)) {
267 0 ▶ push @modules, @{ $self->{$_} } if ref $self->{$_} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{$_} eq "ARRAY" 0 0 0
268 0 ▶ push @modules, keys %{ $self->{$_} } if ref $self->{$_} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{$_} eq "HASH" 0 0 0
269 0 ▶ push @modules, split /[;,\s]/, $self->{$_} unless ref $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{$_} 0 0 0
270 }
271 #$self->log( 'dev', 'modules load', @modules );
272 #$self->log( 'modules load', @modules, @_);
273 0 $self->module_load( $_, @_ ) for @modules;
274 #$self->log( 'now proto', $self->{'Proto'});
275 0 ▶ $self->{charset_chat} ||= $self->{charset_protocol};
Condition0%0/3
$self->{"charset_chat"} ||= $self->{"charset_protocol"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"charset_chat"} ||= $self->{"charset_protocol"}
$self->{"charset_chat"} $self->{"charset_protocol"}
Truth table0%0/3
A ||= B
A= $self->{"charset_chat"}B= $self->{"charset_protocol"}
ABresult
1X1
011
000
276 #$self->protocol_init();
277 #$self->log( 'dev', $self, 'new inited', "MT:$self->{'message_type'}", 'autolisten=', $self->{'auto_listen'} );
278 #$self->{charset_console} = 'utf8';
279 # $self->log( 'dev', "set console encoding [$self->{charset_console}]");
280 #eval qq{use encoding $self->{charset_console}};
281 eval qq{use encoding '$self->{charset_internal}', STDOUT=> '$self->{charset_console}', STDIN => '$self->{charset_console}'}
282 if !$self->{parent}
283 and !$self->{no_charset_console}
284 and $self->{charset_internal}
285 0 ▶ and $self->{charset_console};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"parent"} || $self->{"no_charset_console"} and $self->{"charset_internal"} and $self->{"charset_console"} 0 0 0
Condition0%0/9
not $self->{"parent"} || $self->{"no_charset_console"} and $self->{"charset_internal"} and $self->{"charset_console"}
!ll&&!rl&&r
000
not $self->{"parent"} || $self->{"no_charset_console"} and $self->{"charset_internal"}
!ll&&!rl&&r
000
$self->{'parent'} || $self->{'no_charset_console'}
l!l&&r!l&&!r
000
MC/DC0%0/4
not $self->{"parent"} || $self->{"no_charset_console"} and $self->{"charset_internal"} and $self->{"charset_console"}
$self->{'parent'} $self->{'no_charset_console'} $self->{"charset_internal"} $self->{"charset_console"}
Truth table0%0/5
not(A || B) and C and D
A= $self->{'parent'}B= $self->{'no_charset_console'}C= $self->{"charset_internal"}D= $self->{"charset_console"}
ABCDresult
1XXX0
01XX0
000X0
00100
00111
286 #$self->log( 'dev', 'utf8: УТф восемь');
287 #$self->log( 'dev', Dumper $self);
288 $self->log( 'dcdbg',
289 "using encodings console:[$self->{charset_console}] protocol:[$self->{charset_protocol}] fs:[$self->{charset_fs}]" )
290 0 ▶ unless $self->{parent}{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parent"}{"parent"} 0 0 0
291 0 ▶ if ( $self->{'auto_say'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"auto_say"}) 0 0 0
292 0 ▶ for my $cmd ( @{ $self->{'auto_say_cmd'} || [] } ) {
Condition0%0/2
$self->{'auto_say_cmd'} || []
l!l
00
MC/DC0%0/1
$self->{'auto_say_cmd'} || []
$self->{'auto_say_cmd'}
Truth table0%0/2
A
A= $self->{'auto_say_cmd'}
Aresult
11
00
293 #$self->log('AS', $cmd);
294 0 ▶ $self->{'handler_int'}{$cmd} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
295 0 my $dc = shift;
296 #$self->log('ASH', $cmd);
297 0 $self->say( $cmd, @_ ); #print with console encoding
298 0 };
299 }
300 }
301 #$self->log('dev', 'sctp', $self->{'dev_sctp'});
302 #$self->log('dev', "auto_listen=$self->{'auto_listen'} auto_connect=$self->{'auto_connect'}");
303 0 ▶ if ( $self->{'auto_listen'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'auto_listen'}) { } 0 0 0
elsif ($self->{'auto_connect'}) { } 0 0 0
304 #$self->{'disconnect_recursive'} = $self->{'parent'}{'disconnect_recursive'};
305 0 ▶ $self->{'incomingclass'} ||= $self->{'parent'}{'incomingclass'}; # if $self->{'parent'};
Condition0%0/3
$self->{"incomingclass"} ||= $self->{"parent"}{"incomingclass"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"incomingclass"} ||= $self->{"parent"}{"incomingclass"}
$self->{"incomingclass"} $self->{"parent"}{"incomingclass"}
Truth table0%0/3
A ||= B
A= $self->{"incomingclass"}B= $self->{"parent"}{"incomingclass"}
ABresult
1X1
011
000
306 0 $self->listen();
307 #$self->log('go conaft');
308 0 ▶ $self->connect_aft() if $self->{'broadcast'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"broadcast"} 0 0 0
309 } elsif ( $self->{'auto_connect'} ) {
310 #$self->log( $self, 'new inited', "auto_connect MT:$self->{'message_type'}", ' with' );
311 0 $self->connect();
312 #$self->work();
313 0 ▶ $self->wait_connect() unless $self->{'no_wait_connect'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_wait_connect"} 0 0 0
314 } else {
315 0 $self->get_my_addr();
316 0 $self->get_peer_addr();
317 }
318 0 ▶ if ( $self->{'auto_work'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"auto_work"}) 0 0 0
319 #$self->log( $self, '', "auto_work ", $self->active() );
320 0 ▶ while ( $self->active() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
321 0 $self->work(); #forever
322 #$self->{'auto_work'}->($self) if ref $self->{'auto_work'} eq 'CODE';
323 #Time::HiRes::sleep 0.01;
324 }
325 0 $self->disconnect();
326 }
327 #@ psmisc::file_rewrite( 'dump.new', Dumper $self);
328 0 return $self;
329 }
330  
331 0 ▶sub log(@) {
Subroutine log: not called CC=2 SCAR=17.9
Pod undocumented
332 0 my $self = shift;
333 0 ▶ return $self->{'log'}->( $self, @_ ) if ref $self->{'log'} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"log"} eq "CODE" 0 0 0
334 0 print( join( ' ', "[$self->{'number'}]", @_ ), "\n" );
335 }
336  
337 0 ▶sub cmd {
Subroutine cmd: not called CC=25 SCAR=64.8
Pod undocumented
338 0 my $self = shift;
339 #return unless $self->{'cmd'};
340 0 my $dst;
341 $dst = #$_[0]
342 0 ▶ shift if $self->{'adc'} and length $_[0] == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"adc"} and length $_[0] == 1 0 0 0
Condition0%0/3
$self->{"adc"} and length $_[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"adc"} and length $_[0] == 1
$self->{"adc"} length $_[0] == 1
Truth table0%0/3
A and B
A= $self->{"adc"}B= length $_[0] == 1
ABresult
0X0
100
111
343 0 my $cmd = shift;
344 0 my ( @ret, $ret );
345 #$self->{'log'}->($self,'dev', 'cmd', $cmd, @_) if $cmd ne 'log';
346 #$self->{'log'}->($self,'dev', $self->{number},'cmd', $cmd, @_) if $cmd ne 'log';
347 0 my ( $func, $handler );
348 0 ▶ if ( $self->{'cmd'} and ref $self->{'cmd'}{$cmd} eq 'CODE' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'cmd'} and ref $self->{'cmd'}{$cmd} eq 'CODE') { } 0 0 0
elsif (ref $self->{$cmd} eq 'CODE') { } 0 0 0
elsif ($self->{'cmd'} and ref $self->{'cmd'}{$dst . $cmd} eq 'CODE') { } 0 0 0
elsif ($func = $self->can($cmd)) { } 0 0 0
Condition0%0/3
$self->{"cmd"} and ref $self->{"cmd"}{$cmd} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"cmd"} and ref $self->{"cmd"}{$cmd} eq "CODE"
$self->{"cmd"} ref $self->{"cmd"}{$cmd} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"cmd"}B= ref $self->{"cmd"}{$cmd} eq "CODE"
ABresult
0X0
100
111
349 0 $func = $self->{'cmd'}{$cmd};
350 0 $handler = '_cmd';
351 0 ▶ unshift @_, $dst if $dst;
Branch: 1 branch
BranchTrueFalseTotal
if $dst 0 0 0
352 } elsif ( ref $self->{$cmd} eq 'CODE' ) {
353 0 $func = $self->{$cmd};
354 ▶ } elsif ( $self->{'cmd'} and ref $self->{'cmd'}{ $dst . $cmd } eq 'CODE' ) {
Condition0%0/3
$self->{"cmd"} and ref $self->{"cmd"}{$dst . $cmd} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"cmd"} and ref $self->{"cmd"}{$dst . $cmd} eq "CODE"
$self->{"cmd"} ref $self->{"cmd"}{$dst . $cmd} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"cmd"}B= ref $self->{"cmd"}{$dst . $cmd} eq "CODE"
ABresult
0X0
100
111
355 0 $func = $self->{'cmd'}{ $dst . $cmd };
356 0 $handler = '_cmd';
357 #unshift @_, $dst if $dst;
358 } elsif ( $func = $self->can($cmd) ) {
359 }
360 0 $self->handler( $cmd . $handler . '_bef_bef', \@_ );
361 0 ▶ if ( $self->{'min_cmd_delay'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"min_cmd_delay"} and &Net::DirectConnect::time() - $self->{"last_cmd_time"} < $self->{"min_cmd_delay"}) 0 0 0
Condition0%0/3
$self->{"min_cmd_delay"} and &Net::DirectConnect::time() - $self->{"last_cmd_time"} < $self->{"min_cmd_delay"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"min_cmd_delay"} and &Net::DirectConnect::time() - $self->{"last_cmd_time"} < $self->{"min_cmd_delay"}
$self->{"min_cmd_delay"} &Net::DirectConnect::time() - $self->{"last_cmd_time"} < $self->{"min_cmd_delay"}
Truth table0%0/3
A and B
A= $self->{"min_cmd_delay"}B= &Net::DirectConnect::time() - $self->{"last_cmd_time"} < $self->{"min_cmd_delay"}
ABresult
0X0
100
111
362 and ( time - $self->{'last_cmd_time'} < $self->{'min_cmd_delay'} ) )
363 {
364 0 $self->log( 'dbg', 'sleepcmd', $self->{'min_cmd_delay'} - time + $self->{'last_cmd_time'} );
365 0 sleep( $self->{'min_cmd_delay'} - time + $self->{'last_cmd_time'} );
366 }
367 0 $self->{'last_cmd_time'} = time;
368 0 $self->handler( $cmd . $handler . '_bef', \@_ );
369 #$self->{'log'}->($self,'dev', $self->{number},'cmdrun', $dst, $cmd, @_, $func) if $cmd ne 'log';
370 0 ▶ if ($func) {
Branch: 3 branches
BranchTrueFalseTotal
if ($func) { } 0 0 0
elsif ($self->{'adc'} and length $dst == 1 and length $cmd == 3) { } 0 0 0
elsif (exists $self->{$cmd}) { } 0 0 0
371 0 @ret = $func->( $self, @_ ); #$self->{'cmd'}{$cmd}->(@_);
372 ▶ } elsif ( $self->{'adc'} and length $dst == 1 and length $cmd == 3 ) {
Condition0%0/6
$self->{"adc"} and length $dst == 1 and length $cmd == 3
!ll&&!rl&&r
000
$self->{"adc"} and length $dst == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"adc"} and length $dst == 1 and length $cmd == 3
$self->{"adc"} length $dst == 1 length $cmd == 3
Truth table0%0/4
A and B and C
A= $self->{"adc"}B= length $dst == 1C= length $cmd == 3
ABCresult
0XX0
10X0
1100
1111
373 0 @ret = $self->cmd_adc( $dst, $cmd, @_ );
374 } elsif ( exists $self->{$cmd} ) {
375 0 $self->log( 'dev', "cmd call by var name $cmd=$self->{$cmd}" );
376 0 @ret = ( $self->{$cmd} );
377 } else {
378 $self->log(
379 'dev',
380 "UNKNOWN CMD(st[$self->{'status'}]):[$cmd]{@_}: please add \$dc->{'cmd'}{'$cmd'} = sub { ... };",
381 "self=", ref $self,
382 #Dumper $self->{'cmd'},
383 $self->{'parse'}
384 0 ▶ ) if !grep { $cmd eq $_ } qw(new init);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$cmd eq $_;} "new", "init" 0 0 0
385 0 ▶ $self->{'cmd'}{$cmd} = sub { }
Subroutine __ANON__: not called CC=1 SCAR=0.0
386 0 ▶ if $self->{'cmd'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cmd"} 0 0 0
387 }
388 0 ▶ $ret = scalar @ret > 1 ? \@ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret > 1 ? : 0 0 0
389 0 $self->handler( $cmd . $handler . '_aft', \@_, $ret );
390 0 ▶ if ( $self->{'cmd'} and $self->{'cmd'}{$cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cmd"} and $self->{"cmd"}{$cmd}) 0 0 0
Condition0%0/3
$self->{"cmd"} and $self->{"cmd"}{$cmd}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"cmd"} and $self->{"cmd"}{$cmd}
$self->{"cmd"} $self->{"cmd"}{$cmd}
Truth table0%0/3
A and B
A= $self->{"cmd"}B= $self->{"cmd"}{$cmd}
ABresult
0X0
100
111
391 0 ▶ if ( $self->{'auto_wait'} ) { $self->wait(); }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'auto_wait'}) { } 0 0 0
elsif ($self->{'auto_recv'}) { } 0 0 0
392 0 elsif ( $self->{'auto_recv'} ) { $self->select(); }
393 }
394 0 $self->handler( $cmd . $handler . '_aft_aft', \@_, $ret );
395 0 ▶ return wantarray ? @ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
396 }
397  
398 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
399 #psmisc::printlog('autoload', $AUTOLOAD,@_);
400 0 ▶ my $self = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
401 0 ▶ my $type = ref($self) || return;
Condition0%0/2
ref $self || (return)
l!l
00
MC/DC0%0/1
ref $self || (return)
ref $self
Truth table0%0/2
A
A= ref $self
Aresult
11
00
402 #my @p = @_;
403 0 my $name = $AUTOLOAD;
404 0 $name =~ s/.*\://;
405 #return $self->cmd( $name, @p );
406 0 return $self->cmd( $name, @_ );
407 }
408  
409 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
410 0 my $self = shift;
411 #warn "DESTROY [$self->{number}]";
412 #$self->log( 'dev', 'DESTROYing' );
413 0 $self->destroy();
414 0 --$global{'count'};
415 }
416  
417 0 ▶sub handler {
Subroutine handler: not called CC=6 SCAR=37.4
Pod undocumented
418 0 my $self = shift;
419 0 ▶ shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
420 0 my $cmd = shift;
421 #$self->log('dev', 'handler select', $cmd, $self->{'handler_int'}{$cmd}, $self->{'handler'}{$cmd});
422 $self->{'handler_int'}{$cmd}->( $self, @_ )
423 if $self->{'handler_int'}
424 0 ▶ and ref $self->{'handler_int'}{$cmd} eq 'CODE'; #internal lib
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"handler_int"} and ref $self->{"handler_int"}{$cmd} eq "CODE" 0 0 0
Condition0%0/3
$self->{"handler_int"} and ref $self->{"handler_int"}{$cmd} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"handler_int"} and ref $self->{"handler_int"}{$cmd} eq "CODE"
$self->{"handler_int"} ref $self->{"handler_int"}{$cmd} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"handler_int"}B= ref $self->{"handler_int"}{$cmd} eq "CODE"
ABresult
0X0
100
111
425 $self->{'handler'}{$cmd}->( $self, @_ )
426 0 ▶ if $self->{'handler'} and ref $self->{'handler'}{$cmd} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"handler"} and ref $self->{"handler"}{$cmd} eq "CODE" 0 0 0
Condition0%0/3
$self->{"handler"} and ref $self->{"handler"}{$cmd} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"handler"} and ref $self->{"handler"}{$cmd} eq "CODE"
$self->{"handler"} ref $self->{"handler"}{$cmd} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"handler"}B= ref $self->{"handler"}{$cmd} eq "CODE"
ABresult
0X0
100
111
427 }
428 #sub baseinit {
429 #my $self = shift;
430 #$self->{'number'} = ++$global{'total'};
431 #$self->myport_generate();
432 #$self->{'port'} = $1 if $self->{'host'} =~ s/:(\d+)//;
433 #$self->{'want'} ||= {};
434 #$self->{'NickList'} ||= {};
435 #$self->{'IpList'} ||= {};
436 #$self->{'PortList'} ||= {};
437 #++$global{'count'};
438 #$self->{'status'} = 'disconnected';
439 #$self->protocol_init( $self->{'protocol'} );
440 #}
441 0 ▶sub func {
Subroutine func: not called CC=1 SCAR=6.9
Pod undocumented
442 0 my $self = shift;
443 #$self->log( 'dev', 'func', __PACKAGE__, 'func', __FILE__, __LINE__ );
444 }
445  
446 0 ▶sub init_main { #$self->{'init_main'} ||= sub {
Subroutine init_main: not called CC=27 SCAR=66.3
Pod undocumented
447 0 my $self = shift;
448 #$self->log( 'dev', 'init', __PACKAGE__, 'func', __FILE__, __LINE__ , Dumper \@_);
449 0 local %_ = @_;
450 #warn Dumper \%_;
451 #$self->log('dev', __LINE__, "Proto=$self->{Proto}");
452 0 $self->{$_} = $_{$_} for keys %_;
453 local %_ = (
454 'recv' => 'recv',
455 'send' => 'send',
456 'Listen' => 10,
457 'Timeout' => 10, #connect
458 'Timeout_connected' => 300,
459 'myport' => 412, #first try
460 'myport_base' => 40000,
461 'myport_random' => 1000,
462 'myport_tries' => 5,
463 'cmd_sep' => ' ',
464 0 ▶ 'no_print' => { map { $_ => 1 } qw(Search Quit MyINFO Hello SR UserCommand) },
Branch: 3 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
$^O eq 'MSWin32' ? : 0 0 0
&use_try('IO::Socket::IP') ? : 0 0 0
465 0 ▶ 'log' => sub (@) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
466 0 ▶ my $self = ref $_[0] ? shift() : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
467 0 ▶ if ( ref $self->{'parent'}{'log'} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"parent"}{"log"} eq "CODE") 0 0 0
468 0 return $self->{'parent'}->log( "[$self->{'number'}]", @_ );
469 }
470 #utf8::valid(join '', @_) and
471 0 print( join( ' ', "[$self->{'number'}]", @_ ), "\n" );
472 #Dumper \
473 },
474 #'auto_recv' => 1,
475 #'max_reads' => 20,
476 #'wait_once' => 0.1,
477 #'waits' => 100,
478 #'wait_finish_tries' => 600,
479 #'wait_finish_by' => 1,
480 #'wait_connect_tries' => 600,
481 0 'clients_max' => 50,
482 #'wait_clients_tries' => 200,
483 'wait_finish_tries' => 300, #5 min
484 'wait_clients' => 300, #5 min
485 #del 'wait_clients_by' => 0.01,
486 #'work_sleep' => 0.01,
487 'work_sleep' => 0.005,
488 'select_timeout' => 1,
489 'cmd_recurse_sleep' => 0,
490 #( $^O eq 'MSWin32' ? () : ( 'nonblocking' => 1 ) ),
491 #'nonblocking' => 1,
492 'informative' => [qw(number peernick status host port filebytes filetotal proxy bytes_send bytes_recv)], # sharesize
493 #'informative_hash' => [qw(clients)], #NickList IpList PortList
494 #'disconnect_recursive' => 1,
495 'reconnect_sleep' => 5,
496 'partial_ext' => '.partial',
497 'file_send_by' => 1024 * 1024, #1024 * 64,
498 'local_mask_rfc' => [qw(10 172.[123]\d 192\.168)],
499 'status' => 'disconnected',
500 'time_start' => time,
501 #'peers' => {},
502 'download_to' => './downloads/',
503 #'partial_prefix' => './downloads/Incomplete/',
504 #ADC
505 #number => ++$global{'total'},
506 #};
507 'charset_fs' => (
508 $^O eq 'MSWin32'
509 ? 'cp1251'
510 #: $^O eq 'freebsd' ? 'koi8r'
511 : 'utf8'
512 ),
513 'charset_console' => ( $^O eq 'MSWin32' ? 'cp866' :
514 #$^O eq 'freebsd' ? 'koi8r' :
515 'utf8' ),
516 'charset_protocol' => 'utf8',
517 'charset_internal' => 'utf8',
518 #charset_nick => 'utf8',
519 'socket_class' => ( use_try('IO::Socket::IP') ? 'IO::Socket::IP' : 'IO::Socket::INET' ),
520 );
521 #$self->log(__LINE__, "Proto=$self->{Proto}, protocol=$self->{protocol} class $self->{'socket_class'}");
522 0 ▶ $self->{'wait_connect_tries'} //= $self->{'Timeout'};
Condition0%0/3
$self->{"wait_connect_tries"} //= $self->{"Timeout"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"wait_connect_tries"} //= $self->{"Timeout"}
$self->{"wait_connect_tries"} $self->{"Timeout"}
Truth table0%0/3
A //= B
A= $self->{"wait_connect_tries"}B= $self->{"Timeout"}
ABresult
1X1
011
000
523 0 ▶ $self->{$_} //= $self->{'parent'}{$_} ||= {} for qw(peers peers_sid peers_cid handler clients); #want share_full share_tth
Condition0%0/4
$self->{$_} //= ($self->{"parent"}{$_} ||= {})
l!l
00
$self->{"parent"}{$_} ||= {}
l!l
00
MC/DC0%0/1
$self->{$_} //= ($self->{"parent"}{$_} ||= {})
$self->{$_}
MC/DC0%0/1
$self->{"parent"}{$_} ||= {}
$self->{"parent"}{$_}
Truth table0%0/2
A
A= $self->{$_}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"parent"}{$_}
Aresult
11
00
524 #$self->{$_} ||= $self->{'parent'}{$_} ||= {}, for qw( );
525 0 ▶ $self->{$_} //= $self->{'parent'}{$_} ||= [] for qw(queue_download);
Condition0%0/4
$self->{$_} //= ($self->{"parent"}{$_} ||= [])
l!l
00
$self->{"parent"}{$_} ||= []
l!l
00
MC/DC0%0/1
$self->{$_} //= ($self->{"parent"}{$_} ||= [])
$self->{$_}
MC/DC0%0/1
$self->{"parent"}{$_} ||= []
$self->{"parent"}{$_}
Truth table0%0/2
A
A= $self->{$_}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"parent"}{$_}
Aresult
11
00
526 $self->{$_} //= $self->{'parent'}{$_} ||= $global{$_} ||= {},
527 0 ▶ for qw(sockets share_full share_tth want want_download want_download_filename downloading);
Condition0%0/7
$self->{$_} //= ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= {}))
l!l
00
$self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= {})
l!l&&r!l&&!r
000
$Net::DirectConnect::global{$_} ||= {}
l!l
00
MC/DC0%0/1
$self->{$_} //= ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= {}))
$self->{$_}
MC/DC0%0/2
$self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= {})
$self->{"parent"}{$_} ($Net::DirectConnect::global{$_} ||= {})
MC/DC0%0/1
$Net::DirectConnect::global{$_} ||= {}
$Net::DirectConnect::global{$_}
Truth table0%0/2
A
A= $self->{$_}
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"parent"}{$_}B= ($Net::DirectConnect::global{$_} ||= {})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $Net::DirectConnect::global{$_}
Aresult
11
00
528 0 ▶ $self->{$_} //= $self->{'parent'}{$_} ||= $global{$_}, for qw(db);
Condition0%0/6
$self->{$_} //= ($self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_})
l!l&&r!l&&!r
000
$self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} //= ($self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_})
$self->{$_} ($self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_})
MC/DC0%0/2
$self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_}
$self->{"parent"}{$_} $Net::DirectConnect::global{$_}
Truth table0%0/3
A //= B
A= $self->{$_}B= ($self->{"parent"}{$_} ||= $Net::DirectConnect::global{$_})
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $self->{"parent"}{$_}B= $Net::DirectConnect::global{$_}
ABresult
1X1
011
000
529 $self->{'parent'}{$_} ? $self->{$_} //= $self->{'parent'}{$_} : ()
530 0 ▶ for
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parent'}{$_} ? : 0 0 0
Condition0%0/3
$self->{$_} //= $self->{"parent"}{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} //= $self->{"parent"}{$_}
$self->{$_} $self->{"parent"}{$_}
Truth table0%0/3
A //= B
A= $self->{$_}B= $self->{"parent"}{$_}
ABresult
1X1
011
000
531 qw(log disconnect_recursive partial_prefix partial_ext download_to Proto dev_ipv6 protocol myport_inc no_sctp_fallback)
532 ; #dev_adcs socket_class
533 #$self->log( 'dev', "Proto=$self->{Proto}, Listen=$self->{Listen} protocol=$self->{protocol} inc=$self->{myport_inc}" );
534 0 ▶ $self->{$_} //= { %{ $self->{'parent'}{$_} } } for qw(socket_options); # clone, childs can change
Condition0%0/2
$self->{$_} //= {%{$self->{"parent"}{$_};}}
l!l
00
MC/DC0%0/1
$self->{$_} //= {%{$self->{"parent"}{$_};}}
$self->{$_}
Truth table0%0/2
A
A= $self->{$_}
Aresult
11
00
535 0 ▶ $self->{$_} //= $_{$_} for keys %_;
Condition0%0/3
$self->{$_} //= $_{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} //= $_{$_}
$self->{$_} $_{$_}
Truth table0%0/3
A //= B
A= $self->{$_}B= $_{$_}
ABresult
1X1
011
000
536 0 ▶ $self->{'partial_prefix'} //= $self->{'download_to'} . 'Incomplete/';
Condition0%0/2
$self->{"partial_prefix"} //= $self->{"download_to"} . 'Incomplete/'
l!l
00
MC/DC0%0/1
$self->{"partial_prefix"} //= $self->{"download_to"} . 'Incomplete/'
$self->{"partial_prefix"}
Truth table0%0/2
A
A= $self->{"partial_prefix"}
Aresult
11
00
537 #$self->log(__LINE__, "Proto=$self->{Proto}, protocol=$self->{protocol} class $self->{'socket_class'} ");
538 #$self->log("charset_console=$self->{charset_console} charset_fs=$self->{charset_fs}");
539 #psmisc::printlog('dev', 'init0', Dumper $self);
540 }
541  
542 0 ▶sub myport_generate { #$self->{'myport_generate'} ||= sub {
Subroutine myport_generate: not called CC=7 SCAR=40.3
Pod undocumented
543 0 my $self = shift;
544 #$self->log( 'myport', "$self->{'myport'}: $self->{'myport_base'} or $self->{'myport_random'}" );
545 return $self->{'myport'}
546 unless $self->{'myport_base'}
547 0 ▶ or $self->{'myport_random'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"myport_base"} or $self->{"myport_random"} 0 0 0
Condition0%0/3
$self->{"myport_base"} or $self->{"myport_random"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"myport_base"} or $self->{"myport_random"}
$self->{"myport_base"} $self->{"myport_random"}
Truth table0%0/3
A or B
A= $self->{"myport_base"}B= $self->{"myport_random"}
ABresult
1X1
011
000
548 0 ▶ $self->{'myport'} = undef if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
549 0 ▶ return $self->{'myport'} ||= $self->{'myport_base'} + $self->{'myport_inc'}++ if $self->{'myport_inc'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"myport_inc"} 0 0 0
Condition0%0/3
$self->{"myport"} ||= $self->{"myport_base"} + $self->{"myport_inc"}++
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"myport"} ||= $self->{"myport_base"} + $self->{"myport_inc"}++
$self->{"myport"} $self->{"myport_base"} + $self->{"myport_inc"}++
Truth table0%0/3
A ||= B
A= $self->{"myport"}B= $self->{"myport_base"} + $self->{"myport_inc"}++
ABresult
1X1
011
000
550 0 ▶ return $self->{'myport'} ||= $self->{'myport_base'} + int( rand( $self->{'myport_random'} ) );
Condition0%0/3
$self->{"myport"} ||= $self->{"myport_base"} + int(rand $self->{"myport_random"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"myport"} ||= $self->{"myport_base"} + int(rand $self->{"myport_random"})
$self->{"myport"} $self->{"myport_base"} + int(rand $self->{"myport_random"})
Truth table0%0/3
A ||= B
A= $self->{"myport"}B= $self->{"myport_base"} + int(rand $self->{"myport_random"})
ABresult
1X1
011
000
551 }
552  
553 0 ▶sub select_add { #$self->{'select_add'} ||= sub {
Subroutine select_add: not called CC=6 SCAR=37.4
Pod undocumented
554 0 my $self = shift;
555 #$self->{'select'} ||= $self->{parent}{'select'} $self->{'select_send'} ||= $self->{parent}{'select_send'} if $self->{parent};
556 #$self->{'sockets'} ||= $self->{parent}{'sockets'} if $self->{parent};
557 0 ▶ $self->{$_} ||= $self->{parent}{$_} ||= $global{$_} ||= IO::Select->new() for qw (select select_send);
Condition0%0/9
$self->{$_} ||= ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new))
l!l&&r!l&&!r
000
$self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new)
l!l&&r!l&&!r
000
$Net::DirectConnect::global{$_} ||= "IO::Select"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} ||= ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new))
$self->{$_} ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new))
MC/DC0%0/2
$self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new)
$self->{"parent"}{$_} ($Net::DirectConnect::global{$_} ||= "IO::Select"->new)
MC/DC0%0/2
$Net::DirectConnect::global{$_} ||= "IO::Select"->new
$Net::DirectConnect::global{$_} "IO::Select"->new
Truth table0%0/3
A ||= B
A= $self->{$_}B= ($self->{"parent"}{$_} ||= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new))
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $self->{"parent"}{$_}B= ($Net::DirectConnect::global{$_} ||= "IO::Select"->new)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $Net::DirectConnect::global{$_}B= "IO::Select"->new
ABresult
1X1
011
000
558 #$self->{'select'} ||= IO::Select->new(); #$self->{'socket'}
559 #$self->{'select_send'} ||= IO::Select->new(); #$self->{'socket'}
560 0 ▶ return unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
561 0 $self->{'select'}->add( $self->{'socket'} );
562 0 $self->{'select_send'}->add( $self->{'socket'} );
563 0 $self->{'sockets'}{ $self->{'socket'} } = $self;
564 #$self->log( 'dev', 'add:', $self->{'socket'},' current select', $self->{'select'}->handles );
565 }
566 #$self->{'connect_check'} ||= sub {
567 0 ▶sub connect_check {
Subroutine connect_check: not called CC=7 SCAR=40.3
Pod undocumented
568 0 my $self = shift;
569 #$self->log('dev', 'connect_check', " s=$self->{'status'}, i=$self->{'incoming'}");
570 return 0
571 if $self->{'Proto'} eq 'udp'
572 or $self->{'incoming'}
573 #or $self->{'status'} eq 'listening' or
574 or $self->{'listener'}
575 or (
576 0 ▶ $self->{'socket'}
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Proto"} eq "udp" or $self->{"incoming"} or $self->{"listener"} or $self->{"socket"} or not $self->active 0 0 0
Condition0%0/12
$self->{"Proto"} eq "udp" or $self->{"incoming"} or $self->{"listener"} or $self->{"socket"} or not $self->active
l!l&&r!l&&!r
000
$self->{"Proto"} eq "udp" or $self->{"incoming"} or $self->{"listener"} or $self->{"socket"}
l!l&&r!l&&!r
000
$self->{"Proto"} eq "udp" or $self->{"incoming"} or $self->{"listener"}
l!l&&r!l&&!r
000
$self->{"Proto"} eq "udp" or $self->{"incoming"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->{"Proto"} eq "udp" or $self->{"incoming"} or $self->{"listener"} or $self->{"socket"} or not $self->active
$self->{"Proto"} eq "udp" $self->{"incoming"} $self->{"listener"} $self->{"socket"} not $self->active
Truth table0%0/6
A or B or C or D or not(E)
A= $self->{"Proto"} eq "udp"B= $self->{"incoming"}C= $self->{"listener"}D= $self->{"socket"}E= not $self->active
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
577 #and $self->{'socket'}->connected()
578 ) or !$self->active();
579 #$self->log( 'warn', 'connect_check: must reconnect', Dumper $self->{'socket'}->connected(), $self->{'socket'}, $self->{'status'});
580 0 $self->{'status'} = 'reconnecting';
581 $self->every(
582 $self->{'reconnect_sleep'},
583 0 ▶ $self->{'reconnect_func'} ||= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
584 0 ▶ if ( $self->{'reconnect_tries'}++ < $self->{'reconnects'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'reconnect_tries'}++ < $self->{'reconnects'}) { } 0 0 0
585 $self->log(
586 'warn',
587 "reconnecting ($self->{'host'}) [$self->{'reconnect_tries'}/$self->{'reconnects'}] every",
588 0 $self->{'reconnect_sleep'}
589 );
590 0 $self->connect();
591 } else {
592 0 $self->{'status'} = 'disconnected';
593 }
594 }
595 0 ▶ );
Condition0%0/3
$self->{"reconnect_func"} ||= sub { if ($self->{"reconnect_tries"}++ < $self->{"reconnects"}) { $self->log("warn", qq[reconnecting ($self->{"host"}) [$self->{"reconnect_tries"}/$self->{"reconnects"}] every], $self->{"reconnect_sleep"}); $self->connect; } else { $self->{"status"} = "disconnected"; } ; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"reconnect_func"} ||= sub { if ($self->{"reconnect_tries"}++ < $self->{"reconnects"}) { $self->log("warn", qq[reconnecting ($self->{"host"}) [$self->{"reconnect_tries"}/$self->{"reconnects"}] every], $self->{"reconnect_sleep"}); $self->connect; } else { $self->{"status"} = "disconnected"; } ; }
$self->{"reconnect_func"} sub { if ($self->{"reconnect_tries"}++ < $self->{"reconnects"}) { $self->log("warn", qq[reconnecting ($self->{"host"}) [$self->{"reconnect_tries"}/$self->{"reconnects"}] every], $self->{"reconnect_sleep"}); $self->connect; } else { $self->{"status"} = "disconnected"; } ; }
Truth table0%0/3
A ||= B
A= $self->{"reconnect_func"}B= sub { if ($self->{"reconnect_tries"}++ < $self->{"reconnects"}) { $self->log("warn", qq[reconnecting ($self->{"host"}) [$self->{"reconnect_tries"}/$self->{"reconnects"}] every], $self->{"reconnect_sleep"}); $self->connect; } else { $self->{"status"} = "disconnected"; } ; }
ABresult
1X1
011
000
596 0 return 1;
597 }
598  
599 0 ▶sub connect { #$self->{'connect'} ||= sub {
Subroutine connect: not called CC=16 SCAR=56.1
Pod undocumented
600 0 my $self = shift;
601 #$self->log( 'c', 'connect0 inited', "MT:$self->{'message_type'}", ' with', $self->{'host'} );
602 0 ▶ if ( $_[0] or $self->{'host'} =~ /:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] or $self->{"host"} =~ /:/) 0 0 0
Condition0%0/3
$_[0] or $self->{"host"} =~ /:/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] or $self->{"host"} =~ /:/
$_[0] $self->{"host"} =~ /:/
Truth table0%0/3
A or B
A= $_[0]B= $self->{"host"} =~ /:/
ABresult
1X1
011
000
603 0 ▶ $self->{'host'} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
604 0 $self->{'host'} =~ s{^(.*?)://}{};
605 0 my $p = lc $1;
606 0 ▶ $self->module_load('adcs') if $p eq 'adcs';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "adcs" 0 0 0
607 #$self->protocol_init($p) if $p =~ /^adc/;
608 0 $self->{'host'} =~ s{/.*}{}g;
609 0 ▶ ( $self->{'host'}, $self->{'port'} ) = ( $1, $2 ) if $self->{'host'} =~ m{^\[(\S+)\]:(\d+)}; # [::1]:411
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"host"} =~ /^\[(\S+)\]:(\d+)/ 0 0 0
610 0 ▶ ( $self->{'host'}, $self->{'port'} ) = ( $1, $2 ) if $self->{'host'} =~ s{^([^:]+):(\d+)$}{}; # 1.2.3.4:411
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"host"} =~ s/^([^:]+):(\d+)$// 0 0 0
611 }
612 #$self->log('dev', 'host, port =', $self->{'host'}, $self->{'port'} );
613 #$self->log( 'H:', ((),$self->{'host'} =~ /(:)/g)>1 );
614 #$self->module_load('ipv6') if @{ [ $self->{'host'} =~ /(:)/g ] } > 1;
615 #$self->{'port'} = $_[1] if $_[1];
616 #print "Hhohohhhh" ,$self->{'protocol'},$self->{'host'};
617 return 0
618 if ( $self->{'socket'} and $self->{'socket'}->connected() )
619 0 ▶ or grep { $self->{'status'} eq $_ } qw(destroy); #connected
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"socket"} and $self->{"socket"}->connected or grep {$self->{"status"} eq $_;} "destroy" 0 0 0
Condition0%0/6
$self->{"socket"} and $self->{"socket"}->connected or grep {$self->{"status"} eq $_;} "destroy"
l!l&&r!l&&!r
000
$self->{"socket"} and $self->{"socket"}->connected
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"socket"} and $self->{"socket"}->connected or grep {$self->{"status"} eq $_;} "destroy"
$self->{"socket"} $self->{"socket"}->connected grep {$self->{"status"} eq $_;} "destroy"
Truth table0%0/5
A and B or C
A= $self->{"socket"}B= $self->{"socket"}->connectedC= grep {$self->{"status"} eq $_;} "destroy"
ABCresult
11X1
0X11
1011
0X00
1000
620 $self->log(
621 'info',
622 "connecting to $self->{'protocol'}://[$self->{'host'}]:$self->{'port'} via $self->{'Proto'} class $self->{'socket_class'}",
623 0 ▶ %{ $self->{'socket_options'} || {} }
Condition0%0/2
$self->{'socket_options'} || {}
l!l
00
MC/DC0%0/1
$self->{'socket_options'} || {}
$self->{'socket_options'}
Truth table0%0/2
A
A= $self->{'socket_options'}
Aresult
11
00
624 );
625 #$self->{'status'} = 'connecting';
626 0 $self->{'status'} = 'connecting_tcp';
627 0 $self->{'outgoing'} = 1;
628 #$self->{'port'} = $1 if $self->{'host'} =~ s/:(\d+)//;
629 0 delete $self->{'recv_buf'};
630 #$self->log('dev', 'conn strt', $self->{'Timeout'}, $self->{'Proto'}, Socket::SOCK_STREAM);
631 0 eval {
632 $self->{'socket'} ||= $self->{'socket_class'}->new(
633 'PeerAddr' => $self->{'host'},
634 ( $self->{'port'} ? ( 'PeerPort' => $self->{'port'} ) : () ),
635 ( $self->{'Proto'} ? ( 'Proto' => $self->{'Proto'} ) : () ),
636 #( $self->{'Proto'} eq 'sctp' ? ( 'Type' => Socket::SOCK_STREAM ) : () ),
637 #'Timeout' => $self->{'Timeout'},
638 #(
639 #$self->{'nonblocking'} ? (
640 'Blocking' => 0,
641 #'MultiHomed' => 1, #del
642 #) : ()
643 #),
644 0 %{ $self->{'socket_options'} },
645 0 ▶ %{ $self->{'socket_options_connect'} },
Branch: 2 branches
BranchTrueFalseTotal
$self->{'port'} ? : 0 0 0
$self->{'Proto'} ? : 0 0 0
Condition0%0/3
$self->{"socket"} ||= $self->{"socket_class"}->new("PeerAddr", $self->{"host"}, $self->{"port"} ? ("PeerPort", $self->{"port"}) : (), $self->{"Proto"} ? ("Proto", $self->{"Proto"}) : (), "Blocking", 0, %{$$self{"socket_options"};}, %{$$self{"socket_options_connect"};})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"socket"} ||= $self->{"socket_class"}->new("PeerAddr", $self->{"host"}, $self->{"port"} ? ("PeerPort", $self->{"port"}) : (), $self->{"Proto"} ? ("Proto", $self->{"Proto"}) : (), "Blocking", 0, %{$$self{"socket_options"};}, %{$$self{"socket_options_connect"};})
$self->{"socket"} $self->{"socket_class"}->new("PeerAddr", $self->{"host"}, $self->{"port"} ? ("PeerPort", $self->{"port"}) : (), $self->{"Proto"} ? ("Proto", $self->{"Proto"}) : (), "Blocking", 0, %{$$self{"socket_options"};}, %{$$self{"socket_options_connect"};})
Truth table0%0/3
A ||= B
A= $self->{"socket"}B= $self->{"socket_class"}->new("PeerAddr", $self->{"host"}, $self->{"port"} ? ("PeerPort", $self->{"port"}) : (), $self->{"Proto"} ? ("Proto", $self->{"Proto"}) : (), "Blocking", 0, %{$$self{"socket_options"};}, %{$$self{"socket_options_connect"};})
ABresult
1X1
011
000
646 );
647 };
648 #$self->log('dev', 'connect end');
649 $self->log(
650 'err',
651 "connect socket error: $@,",
652 Encode::decode( $self->{charset_fs}, $!, Encode::FB_WARN ),
653 "[$self->{'socket'}]"
654 ),
655 return 1
656 0 ▶ if !$self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
657 #$self->log( 'dev', 'timeout to', $self->{'Timeout'});
658 0 ▶ $self->{'socket'}->timeout( $self->{'Timeout'} ) if $self->{'Timeout'}; #timeout must be after new, ifyou want nonblocking
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Timeout"} 0 0 0
659 #$self->log( 'dev', 'ssltry'), IO::Socket::SSL->start_SSL($self->{'socket'}) if $self->{'protocol'} eq 'adcs';
660 #$self->log( 'err', "connect socket error: $@, $! [$self->{'socket'}]" ), return 1 if !$self->{'socket'};
661 #$self->{'socket'}->binmode(":encoding($self->{charset_protocol})");
662 #$self->{charset_protocol} = 'utf8';
663 #$self->log( 'dev', "set encoding of socket to [$self->{charset_protocol}]");
664 # binmode($self->{'socket'}, ":encoding($self->{charset_protocol})");
665 # binmode($self->{'socket'}, ":raw:encoding($self->{charset_protocol})");
666 # binmode($self->{'socket'}, ":encoding($self->{charset_protocol}):bytes");
667 # binmode($self->{'socket'}, ":$self->{charset_protocol}");
668 #eval {$self->{'socket'}->fcntl( Fcntl::O_ASYNC,1);}; $self->log('warn', "cant Fcntl::O_ASYNC : $@") if $@;
669 #eval {$self->{'socket'}->fcntl( Fcntl::O_NONBLOCK,1);}; $self->log('warn', "cant Fcntl::O_NONBLOCK : $@") if $@;
670 0 $self->select_add();
671 0 $self->{time_start} = time;
672 #$self->log($self, 'connected2 inited',"MT:$self->{'message_type'}", ' with');
673 #$self->log( 'dev', "connect_aft after", );
674 #!!$self->select();
675 #$self->log( 'dev', "connect after", );
676 0 return 0;
677 }
678  
679 0 ▶sub connected { #$self->{'connected'} ||= sub {
Subroutine connected: not called CC=9 SCAR=45.0
Pod undocumented
680 0 my $self = shift;
681 0 $self->get_my_addr();
682 #$self->log( 'info', 'broken socket, cant get my ip'),
683 #$self->destroy(),
684 0 ▶ return unless $self->{'myip'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"myip"} 0 0 0
685 0 $self->{'status'} = 'connecting';
686 #$self->log( 'dev', "connected0", "[$self->{'socket'}] c=", $self->{'socket'}->connected(), 'p=', $self->{'socket'}->protocol() );
687 #$self->log( 'dev', 'timeout to', $self->{'Timeout_connected'});
688 0 ▶ $self->{'socket'}->timeout( $self->{'Timeout_connected'} ) if $self->{'Timeout_connected'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Timeout_connected"} 0 0 0
689 0 $self->get_peer_addr();
690 #$self->get_my_addr();
691 #!$self->{'hostip'} ||= $self->{'host'};
692 #my $localmask ||= join '|', @{ $self->{'local_mask_rfc'} || [] }, @{ $self->{'local_mask'} || [] };
693 0 ▶ my $localmask ||= join '|', map { ref $_ eq 'ARRAY' ? @$_ : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
694 0 grep { $_ } $self->{'local_mask_rfc'},
695 0 ▶ $self->{'local_mask'};
Condition0%0/3
my $localmask ||= join("|", map({ref $_ eq "ARRAY" ? @$_ : $_;} grep({$_;} $self->{"local_mask_rfc"}, $self->{"local_mask"})))
l!l&&r!l&&!r
000
MC/DC0%0/2
my $localmask ||= join("|", map({ref $_ eq "ARRAY" ? @$_ : $_;} grep({$_;} $self->{"local_mask_rfc"}, $self->{"local_mask"})))
my $localmask join("|", map({ref $_ eq "ARRAY" ? @$_ : $_;} grep({$_;} $self->{"local_mask_rfc"}, $self->{"local_mask"})))
Truth table0%0/3
A ||= B
A= my $localmaskB= join("|", map({ref $_ eq "ARRAY" ? @$_ : $_;} grep({$_;} $self->{"local_mask_rfc"}, $self->{"local_mask"})))
ABresult
1X1
011
000
696 0 ▶ my $is_local_ip = sub ($) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
697 #$self->log( 'info', "test ip [$_[0]] in [$localmask] ");
698 0 return $_[0] =~ /^(?:$localmask)\./;
699 0 };
700 $self->log( 'info', "my internal ip detected, using passive mode", $self->{'myip'}, $self->{'hostip'}, $localmask ),
701 $self->{'M'} = 'P'
702 if !$self->{'M'}
703 and $is_local_ip->( $self->{'myip'} )
704 0 ▶ and !$is_local_ip->( $self->{'hostip'} );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"M"} and &$is_local_ip($self->{"myip"}) and not &$is_local_ip($self->{"hostip"}) 0 0 0
Condition0%0/6
not $self->{"M"} and &$is_local_ip($self->{"myip"}) and not &$is_local_ip($self->{"hostip"})
!ll&&!rl&&r
000
not $self->{"M"} and &$is_local_ip($self->{"myip"})
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->{"M"} and &$is_local_ip($self->{"myip"}) and not &$is_local_ip($self->{"hostip"})
not $self->{"M"} &$is_local_ip($self->{"myip"}) not &$is_local_ip($self->{"hostip"})
Truth table0%0/4
not(A) and B and not(C)
A= not $self->{"M"}B= &$is_local_ip($self->{"myip"})C= not &$is_local_ip($self->{"hostip"})
ABCresult
0XX0
10X0
1100
1111
705 0 ▶ $self->{'M'} ||= 'A';
Condition0%0/2
$self->{"M"} ||= "A"
l!l
00
MC/DC0%0/1
$self->{"M"} ||= "A"
$self->{"M"}
Truth table0%0/2
A
A= $self->{"M"}
Aresult
11
00
706 #$self->log( 'info', "mode set [$self->{'M'}] ");
707 0 $self->log( 'info', "connect to $self->{'host'}($self->{'hostip'}):$self->{'port'} [me=$self->{'myip'}] ok ", );
708 #$self->log( $self, 'connected1 inited', "MT:$self->{'message_type'}", ' with' );
709 #$self->log( 'dev', 'ssltry'),IO::Socket::SSL->start_SSL($self->{'socket'}) if $self->{'protocol'} eq 'adcs';
710 0 $self->connect_aft();
711 }
712  
713 0 ▶sub reconnect { #$self->{'reconnect'} ||= sub {
Subroutine reconnect: not called CC=1 SCAR=6.9
Pod undocumented
714 0 my $self = shift;
715 #$self->log( 'dev', 'reconnect');
716 0 $self->disconnect();
717 0 $self->{'status'} = 'reconnecting';
718 #!sleep $self->{'reconnect_sleep'};
719 #!$self->connect();
720 }
721  
722 0 ▶sub listen { #$self->{'listen'} ||= sub {
Subroutine listen: not called CC=10 SCAR=47.0
Pod undocumented
723 0 my $self = shift;
724 $self->log( 'err', 'listen off', "[$self->{'Listen'}] [$self->{'M'}] [$self->{'allow_passive_ConnectToMe'}]" ), return
725 0 ▶ if !$self->{'Listen'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Listen"} 0 0 0
726 #or ( $self->{'M'} eq 'P' and !$self->{'allow_passive_ConnectToMe'} ); #RENAME
727 0 $self->{'listener'} = 1;
728 0 $self->myport_generate();
729 #$self->log( 'dev', 'listen', "p=$self->{'myport'}; proto=$self->{'Proto'} cl=$self->{'socket_class'}",'sockopts', Dumper $self->{'socket_options'}, $self->{'socket_options_listen'} );
730 0 for ( 1 .. $self->{'myport_tries'} ) {
731 local @_ = (
732 'LocalPort' => $self->{'myport'},
733 #'Proto' => $self->{'Proto'} || 'tcp',
734 ( $self->{'Proto'} ? ( 'Proto' => $self->{'Proto'} ) : () ),
735 (
736 $self->{'Proto'} ne 'udp'
737 ? ( 'Listen' => $self->{'Listen'} )
738 : ()
739 ),
740 #( $self->{'Proto'} eq 'sctp' ? ( 'Type' => Socket::SOCK_STREAM ) : () ),
741 #( $self->{'nonblocking'} ? ( 'Blocking' => 0 ) : () ),
742 Blocking => 0,
743 #ReuseAddr => 1,
744 0 %{ $self->{'socket_options'} },
745 0 ▶ %{ $self->{'socket_options_listen'} },
Branch: 2 branches
BranchTrueFalseTotal
$self->{'Proto'} ? : 0 0 0
$self->{'Proto'} ne 'udp' ? : 0 0 0
746 );
747 #$self->log( 'dev', 'listen', $self->{'socket_class'}, @_);
748 0 ▶ eval { $self->{'socket'} ||= $self->{'socket_class'}->new(@_); };
Condition0%0/3
$self->{"socket"} ||= $self->{"socket_class"}->new(@_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"socket"} ||= $self->{"socket_class"}->new(@_)
$self->{"socket"} $self->{"socket_class"}->new(@_)
Truth table0%0/3
A ||= B
A= $self->{"socket"}B= $self->{"socket_class"}->new(@_)
ABresult
1X1
011
000
749 0 ▶ $self->select_add(), last if $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"socket"} 0 0 0
750 $self->log( 'err', "listen [$_/$self->{'myport_tries'}] ($self->{'Listen'}) $self->{'myport'} socket error: $@" ),
751 $self->myport_generate(1),
752 0 ▶ unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
753 }
754 0 ▶ $self->log( 'err', 'cant listen' ), return unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
755 0 eval { $self->{'listener'} = $self->{'socket'}->sockhost; };
756 0 $self->log( 'info', "listening", $self->{'listener'}, "$self->{'myport'} $self->{'Proto'} with $self->{'socket_class'}" );
757 0 ▶ $self->{'accept'} = 1 if $self->{'Proto'} ne 'udp';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Proto"} ne "udp" 0 0 0
758 0 $self->{'status'} = 'listening';
759 #$self->select();
760 }
761  
762 0 ▶sub disconnect { #$self->{'disconnect'} ||= sub {
Subroutine disconnect: not called CC=9 SCAR=45.0
Pod undocumented
763 0 my $self = shift;
764 #$self->log('dev', 'in disconnect', $self->{'status'}, caller);
765 #$self->log( 'dev', "[$self->{'number'}] status=",$self->{'status'}, $self->{'destroying'});
766 0 $self->handler('disconnect_bef');
767 0 $self->{'status'} = 'disconnected';
768 0 ▶ if ( $self->{'socket'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"socket"}) 0 0 0
769 #$self->log( 'dev', "[$self->{'number'}] Closing socket",
770 0 ▶ $self->{'select'}->remove( $self->{'socket'} ) if $self->{'select'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"select"} 0 0 0
771 0 ▶ $self->{'select_send'}->remove( $self->{'socket'} ) if $self->{'select_send'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"select_send"} 0 0 0
772 0 delete $self->{'sockets'}{ $self->{'socket'} };
773 #$self->{'socket'}->shutdown(2);
774 0 $self->{'socket'}->close();
775 0 delete $self->{'socket'};
776 }
777 #delete $self->{'select'};
778 #$self->log('dev',"delclient($self->{'clients'}{$_}->{'number'})[$_][$self->{'clients'}{$_}]\n") for grep {$_} keys %{ $self->{'clients'} };
779 #$self->log('dev', 'run file_close');
780 0 $self->file_close();
781 0 ▶ if ( $self->{'disconnect_recursive'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"disconnect_recursive"}) 0 0 0
782 0 for my $client (
783 grep {
784 #$self->{'clients'}{$_} and
785 0 !$self->{'clients'}{$_}{'auto_listen'}
786 }
787 #keys %{ $self->{'clients'} }
788 $self->clients_my()
789 )
790 {
791 #next if $self->{'clients'}{$client} eq $self;
792 #$self->log( 'dev', "destroy cli", $self->{'clients'}{$_}, ref $self->{'clients'}{$_} ),
793 #$self->{'clients'}{$client}->destroy()
794 0 ▶ $self->{'clients'}{$client}->disconnect() if ref $self->{'clients'}{$client};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"clients"}{$client} 0 0 0
795 #and $self->{'clients'}{$client}{'destroy'};
796 0 $self->{$_} += $self->{'clients'}{$client}{$_} for qw(bytes_recv bytes_send);
797 #%{$self->{'clients'}{$client}} = ();
798 0 delete $self->{'clients'}{$client};
799 }
800 }
801 0 $self->handler('disconnect_aft');
802 0 delete $self->{$_} for qw(NickList IpList PortList PortList_udp peers peers_cid peers_sid);
803 #$self->log( 'info', "disconnected", __FILE__, __LINE__ );
804 #$self->log('dev', caller($_)) for 0..5;
805 }
806 #$self->{'destroy'} ||= sub {
807 0 ▶sub destroy {
Subroutine destroy: not called CC=3 SCAR=24.8
Pod undocumented
808 0 my $self = shift;
809 #$self->log('dev', 'in destroy');
810 0 $self->disconnect(); # if ref $self and !$self->{'destroying'}++;
811 #!? delete $self->{$_} for keys %$self;
812 0 $self->info();
813 0 $self->{'status'} = 'destroy';
814 0 ▶ delete $self->{$_} for grep { ref $self->{$_} and !ref $self->{$_} eq 'CODE' } keys %$self;
Condition0%0/3
ref $self->{$_} && !ref($self->{$_}) eq 'CODE'
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{$_} && !ref($self->{$_}) eq 'CODE'
ref $self->{$_} !ref($self->{$_}) eq 'CODE'
Truth table0%0/3
A && not(B)
A= ref $self->{$_}B= !ref($self->{$_}) eq 'CODE'
ABresult
0X0
100
111
815 #$self = {};
816 #!?%$self = ();
817 }
818  
819 0 ▶sub recv { # $self->{'recv'} ||= sub {
Subroutine recv: not called CC=33 SCAR=70.2
Pod undocumented
820 0 my $self = shift;
821 0 my $client = shift;
822 #my $socket = shift;
823 #$self->log( 'dev', 'recv', $client, $self->{'socket'}, $self->{'accept'});
824 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"accept"}) 0 0 0
825 $self->{'accept'}
826 #and $client eq $self->{'socket'}
827 )
828 {
829 0 local $_ = $self->{'socket'}->accept();
830 0 ▶ if ($_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) { } 0 0 0
831 #$self->log( 'traceDEV', 'DC::recv', 'accept', $self->{'incomingclass'} );
832 $self->log( 'err', 'cant accept, no incomingclass' ), return,
833 0 ▶ unless $self->{'incomingclass'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incomingclass"} 0 0 0
834 #my $host = $_->peerhost;
835 0 my ($host) = socket_addr $_;
836 #; # || $self->{parent}{'allow'};
837 #$self->log( 'info', "incoming [$host] (".ref($_).")to $self->{'incomingclass'}", ($self->{'allow'} ? "allow=$self->{'allow'}" : ()) );
838 $self->log(
839 'info',
840 "incoming [$host] (" . ref($_) . ") to $self->{'incomingclass'}",
841 0 ▶ ( $self->{'allow'} ? "allow=$self->{'allow'}" : () )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'allow'} ? : 0 0 0
842 );
843 0 ▶ if ( my $allow = $self->{'allow'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $allow = $self->{"allow"}) 0 0 0
844 #my ( undef, $host ) = socket_addr $_;
845 0 ▶ $self->log( 'warn', "disallowed connect from $host" ), return
Branch: 1 branch
BranchTrueFalseTotal
unless $host eq $allow 0 0 0
846 unless $host eq $allow;
847 }
848 #$self->log( 'dev', "incp[$self->{'protocol'}]");
849 $_ = $self->{'incomingclass'}->new(
850 #%$self, clear(),
851 'socket' => $_,
852 'LocalPort' => $self->{'myport'},
853 'incoming' => 1,
854 #'want' => \%{ $self->{'want'} }, 'NickList' => \%{ $self->{'NickList'} }, 'IpList' => \%{ $self->{'IpList'} }, 'PortList' => \%{ $self->{'PortList'} },
855 #'want' => $self->{'want'},
856 #'NickList' => $self->{'NickList'},
857 #'IpList' => $self->{'IpList'},
858 #'PortList' => $self->{'PortList'},
859 #'auto_listen' => 0, 'auto_connect' => 0,
860 'parent' => $self,
861 #'share_tth' => $self->{'share_tth'},
862 'status' => 'connected',
863 #$self->incomingopt(),
864 0 ▶ %{ $self->{'incomingopt'} || {} },
Condition0%0/2
$self->{'incomingopt'} || {}
l!l
00
MC/DC0%0/1
$self->{'incomingopt'} || {}
$self->{'incomingopt'}
Truth table0%0/2
A
A= $self->{'incomingopt'}
Aresult
11
00
865 );
866 0 ▶ my $name = ( $_->{hostip} || $_->{host} ) . ( $_->{port} ? ':' : () ) . $_->{port};
Branch: 1 branch
BranchTrueFalseTotal
$_->{'port'} ? : 0 0 0
Condition0%0/3
$_->{'hostip'} || $_->{'host'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'hostip'} || $_->{'host'}
$_->{'hostip'} $_->{'host'}
Truth table0%0/3
A || B
A= $_->{'hostip'}B= $_->{'host'}
ABresult
1X1
011
000
867 0 ▶ $self->{'clients'}{$name} ||= $_;
Condition0%0/3
$self->{"clients"}{$name} ||= $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"clients"}{$name} ||= $_
$self->{"clients"}{$name} $_
Truth table0%0/3
A ||= B
A= $self->{"clients"}{$name}B= $_
ABresult
1X1
011
000
868 0 $self->{'clients'}{$name}->select_add();
869 #$self->log( 'dev', 'child created', $_, $self->{'clients'}{$_});
870 #++$ret;
871 } else {
872 0 $self->log( 'err', "Accepting fail! ($_) [$self->{'Proto'}]", $!, $@ );
873 }
874 #next;
875 0 return;
876 }
877 $self->log( 'dev', "SOCKERR", $client, $self->{'socket'}, $self->{'select'} )
878 0 ▶ if $client ne $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
if $client ne $self->{"socket"} 0 0 0
879 0 $self->{'databuf'} = '';
880 #my $r;
881 0 my $recv = $self->{'recv'};
882 0 ▶ if ( (!defined( $self->{'recv_addr'} = $client->$recv( $self->{'databuf'}, POSIX::BUFSIZ, $self->{'recv_flags'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($self->{'recv_addr'} = $client->$recv($self->{'databuf'}, 8192, $self->{'recv_flags'})) && length $self->{'databuf'} and $recv ~~ 'recv') { } 0 0 0
Condition0%0/6
not defined($self->{"recv_addr"} = $client->$recv($self->{"databuf"}, 8192, $self->{"recv_flags"})) && length $self->{"databuf"} and $recv ~~ "recv"
!ll&&!rl&&r
000
defined($self->{'recv_addr'} = $client->$recv($self->{'databuf'}, 8192, $self->{'recv_flags'})) && length $self->{'databuf'}
!ll&&!rl&&r
000
MC/DC0%0/3
not defined($self->{"recv_addr"} = $client->$recv($self->{"databuf"}, 8192, $self->{"recv_flags"})) && length $self->{"databuf"} and $recv ~~ "recv"
defined($self->{'recv_addr'} = $client->$recv($self->{'databuf'}, 8192, $self->{'recv_flags'})) length $self->{'databuf'} $recv ~~ "recv"
Truth table0%0/5
not(A && B) and C
A= defined($self->{'recv_addr'} = $client->$recv($self->{'databuf'}, 8192, $self->{'recv_flags'}))B= length $self->{'databuf'}C= $recv ~~ "recv"
ABCresult
11X0
0X00
1000
0X11
1011
883 or !length( $self->{'databuf'} )) and $recv ~~ 'recv' )
884 {
885 #TODO not here
886 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($self->active and not $self->{'incoming'}) { } 0 0 0
elsif ($self->{'status'} ne 'listening') { } 0 0 0
Condition0%0/3
$self->active and not $self->{"incoming"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->active and not $self->{"incoming"}
$self->active not $self->{"incoming"}
Truth table0%0/3
A and not(B)
A= $self->activeB= not $self->{"incoming"}
ABresult
0X0
100
111
887 $self->active()
888 and !$self->{'incoming'}
889 #and $self->{'reconnect_tries'}++ < $self->{'reconnects'}
890 )
891 {
892 0 $self->log( 'dcdbg',
893 "recv err, reconnect [$self->{'reconnect_tries'}/$self->{'reconnects'}]. d=[$self->{'databuf'}] i=[$self->{'incoming'}]"
894 );
895 #$self->log( 'dcdbg', "recv err, reconnect," );
896 0 $self->reconnect();
897 } elsif ( $self->{'status'} ne 'listening' ) {
898 0 $self->log( 'dcdbg', "recv err, destroy," );
899 0 $self->destroy();
900 }
901 } else {
902 #++$readed;
903 #++$ret;
904 0 $self->{bytes_recv} += length $self->{'databuf'};
905 0 $self->{activity} = time;
906 #$self->log( 'dcdmp', "[$self->{'number'}]", "raw recv ", length( $self->{'databuf'} ), $self->{'databuf'} );
907 }
908 #$self->log( 'dcdmp', "0rawrawrcv [fh:$self->{'filehandle'}]:", $self->{'databuf'} );
909 0 ▶ if ( $self->{'filehandle'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'filehandle'}) { } 0 0 0
elsif (length $self->{'databuf'}) { } 0 0 0
910 0 $self->file_write( \$self->{'databuf'} );
911 } elsif ( length $self->{'databuf'} ) {
912 #$self->log( 'dcdmp', "rawrawrcv:", $self->{'databuf'} );
913 0 $self->{'recv_buf'} .= $self->{'databuf'};
914 #$self->log( 'dcdmp', "rawrawbuf:", $self->{'recv_buf'} );
915 local $self->{'cmd_aft'} = "\x0A"
916 if !$self->{'adc'}
917 0 ▶ and $self->{'recv_buf'} =~ /^[BCDEFHITU][A-Z]{,5} /;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"adc"} and $self->{"recv_buf"} =~ /^[BCDEFHITU][A-Z]{,5} / 0 0 0
Condition0%0/3
not $self->{"adc"} and $self->{"recv_buf"} =~ /^[BCDEFHITU][A-Z]{,5} /
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"adc"} and $self->{"recv_buf"} =~ /^[BCDEFHITU][A-Z]{,5} /
not $self->{"adc"} $self->{"recv_buf"} =~ /^[BCDEFHITU][A-Z]{,5} /
Truth table0%0/3
not(A) and B
A= not $self->{"adc"}B= $self->{"recv_buf"} =~ /^[BCDEFHITU][A-Z]{,5} /
ABresult
0X0
100
111
918 #$self->log( 'dcdbg', "[$self->{'number'}]", "raw to parse [$self->{'buf'}] sep[$self->{'cmd_aft'}]" ) unless $self->{'filehandle'};
919 $self->{'recv_buf'} .= $self->{'cmd_aft'}
920 0 ▶ if $self->{'Proto'} eq 'udp' and $self->{'status'} eq 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Proto"} eq "udp" and $self->{"status"} eq "listening" 0 0 0
Condition0%0/3
$self->{"Proto"} eq "udp" and $self->{"status"} eq "listening"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Proto"} eq "udp" and $self->{"status"} eq "listening"
$self->{"Proto"} eq "udp" $self->{"status"} eq "listening"
Truth table0%0/3
A and B
A= $self->{"Proto"} eq "udp"B= $self->{"status"} eq "listening"
ABresult
0X0
100
111
921 0 ▶ while ( $self->{'recv_buf'} =~ s/^(.*?)\Q$self->{'cmd_aft'}//s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"recv_buf"} =~ s/^(.*?)\Q$self->{"cmd_aft"}\E//s) 0 0 0
922 0 local $_ = $1;
923 #$self->log('dcdmp', 'DC::recv', "parse [$_]($self->{'cmd_aft'})");
924 0 ▶ last if $self->{'status'} eq 'destroy';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"status"} eq "destroy" 0 0 0
925 #$self->log( 'dcdbg',"[$self->{'number'}] dev cycle ",length $_," [$_]", );
926 0 ▶ last unless length $_ and length $self->{'cmd_aft'};
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ and length $self->{"cmd_aft"} 0 0 0
Condition0%0/3
length $_ and length $self->{"cmd_aft"}
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ and length $self->{"cmd_aft"}
length $_ length $self->{"cmd_aft"}
Truth table0%0/3
A and B
A= length $_B= length $self->{"cmd_aft"}
ABresult
0X0
100
111
927 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
928 0 ▶ $self->get_peer_addr_recv() if $self->{'broadcast'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"broadcast"} 0 0 0
929 0 $_ = Encode::decode $self->{charset_protocol}, $_, Encode::FB_WARN;
930 # $Encode::encode $self->{charset_console},
931 0 $self->parser($_);
932 #$self->log( 'dcdbg', "[$self->{'number'}]", "left to parse [$self->{'buf'}] sep[$self->{'cmd_aft'}] now was [$_]" );
933 0 ▶ last if ( $self->{'filehandle'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filehandle"} 0 0 0
934 }
935 $self->file_write( \$self->{'recv_buf'} ), $self->{'recv_buf'} = ''
936 if length( $self->{'recv_buf'} )
937 0 ▶ and $self->{'filehandle'};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"recv_buf"} and $self->{"filehandle"} 0 0 0
Condition0%0/3
length $self->{"recv_buf"} and $self->{"filehandle"}
!ll&&!rl&&r
000
MC/DC0%0/2
length $self->{"recv_buf"} and $self->{"filehandle"}
length $self->{"recv_buf"} $self->{"filehandle"}
Truth table0%0/3
A and B
A= length $self->{"recv_buf"}B= $self->{"filehandle"}
ABresult
0X0
100
111
938 }
939 }
940  
941 0 ▶sub select { #$self->{'select'} ||= sub {
Subroutine select: not called CC=12 SCAR=50.5
Pod undocumented
942 0 my $self = shift;
943 #$self->{'recv_runned'}{ $self->{'number'} } = 1;
944 0 ▶ my $sleep = shift || $self->{'select_timeout'};
Condition0%0/3
shift() || $self->{'select_timeout'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'select_timeout'}
shift() $self->{'select_timeout'}
Truth table0%0/3
A || B
A= shift()B= $self->{'select_timeout'}
ABresult
1X1
011
000
945 0 my $nosend = shift;
946 0 my $ret = 0;
947 #$self->connect_check();
948 #$self->log( 'dev', 'cant recv, ret' ),
949 #return unless $self->{'socket'} and ( $self->{'status'} eq 'listening' or $self->{'socket'}->connected );
950 #$self->{'select'} = IO::Select->new( $self->{'socket'} ) if !$self->{'select'} and $self->{'socket'};
951 #my ( $readed, $reads );
952 #$self->{'databuf'} = '';
953 #$self->log( 'dev', 'select', 'bef', $sleep, $nosend , ) if $nosend;
954 my ( $recv, $send, $exeption ) =
955 0 ▶ IO::Select->select( $self->{'select'}, ( $nosend ? undef : $self->{'select_send'} ), $self->{'select'}, $sleep );
Branch: 1 branch
BranchTrueFalseTotal
$nosend ? : 0 0 0
956 #$self->log( 'traceD', 'DC::select', 'aft' , Dumper ($recv, $send, $exeption));
957 #schedule(10, sub { $self->log( 'dev', 'DC::select', 'aft' , Dumper ($recv, $send, $exeption), 'from', $self->{'select'}->handles() , 'and ', $self->{'select_send'}->handles()); });
958 #$self->{'select'}->remove(@$exeption) if $exeption;
959 #for ( keys %{ $self->{sockets} } ) {
960 #$self->log( 'tracez', 'C:', $self->{sockets}{$_}{socket}, $self->{sockets}{$_}{socket}->connected());
961 #}
962 0 for (@$exeption) {
963 #$self->log( 'dcdbg', 'exeption', $_, $self->{sockets}{$_}{number} ),
964 #$self->{'select'}->remove($_);
965 #can_run( $self->{sockets}{$_}, 'destroy' );
966 0 can_run( $self->{sockets}{$_}, 'reconnect' );
967 #$self->{sockets}{$_}->destroy() if ref $self->{sockets}{$_};
968 0 delete $self->{sockets}{$_};
969 0 ++$ret,;
970 }
971 #for (@$recv, @$send) {
972  
973 =hm
974 for ( keys %{ $self->{sockets} } ) {
975 #$self->log( 'dev', 'connected chk' , $self->{sockets}{$_}{socket}, $self->{sockets}{$_}{socket}->connected());
976 #$self->log( 'dev', 'connected call' ),
977 $self->{sockets}{$_}->connected(), ++$ret,
978 if $self->{sockets}{$_}{status} eq 'connecting_tcp' and $self->{sockets}{$_}{socket}->connected();
979 }
980 =cut
981 0 for (@$send) {
982 0 ▶ next unless $self->{sockets}{$_} and $self->{sockets}{$_}{socket};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sockets"}{$_} and $self->{"sockets"}{$_}{"socket"} 0 0 0
Condition0%0/3
$self->{"sockets"}{$_} and $self->{"sockets"}{$_}{"socket"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sockets"}{$_} and $self->{"sockets"}{$_}{"socket"}
$self->{"sockets"}{$_} $self->{"sockets"}{$_}{"socket"}
Truth table0%0/3
A and B
A= $self->{"sockets"}{$_}B= $self->{"sockets"}{$_}{"socket"}
ABresult
0X0
100
111
983 #$self->log('connect test', $self->{sockets}{$_}{status}, $self->{sockets}{$_}{socket}->connected(), caller);
984 #$self->{'select'}->remove($_),
985 $self->{sockets}{$_}->connected(),
986 #can_run($self->{sockets}{$_}, 'connected'),
987 ++$ret,
988 0 ▶ if $self->{sockets}{$_}{status} eq 'connecting_tcp';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sockets"}{$_}{"status"} eq "connecting_tcp" 0 0 0
989 # and $self->{sockets}{$_}{socket}->connected();
990 #$self->log( 'err', 'no object for send handle',$_, ) , next , unless $self->{sockets}{$_};
991 #++$self->{sockets}{$_}{send_can};
992 #$self->log( 'dev', 'can_send', $_, $self->{sockets}{$_}{number}, $self->{sockets}{$_}{send_can} );
993 #$ret += $self->{sockets}{$_}->send_can();
994 0 $ret += can_run( $self->{sockets}{$_}, 'send_can' );
995 0 ▶ if ( $self->{sockets}{$_}{'filehandle_send'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sockets"}{$_}{"filehandle_send"}) 0 0 0
996 0 $ret += $self->{sockets}{$_}->file_send_part();
997 }
998 #$self->{sockets}{$_}->send();
999 }
1000 0 for (@$recv) {
1001 #next unless $self->{sockets}{$_};
1002 $self->log( 'err', 'no object for recv handle', $_, Dumper $self->{sockets}{$_} ),
1003 can_run( $self->{'select'}, 'remove', $_ ), next,
1004 #if !$self->{sockets}{$_} or !ref $self->{sockets}{$_};
1005 0 ▶ if !ref $self->{sockets}{$_} or ref $self->{sockets}{$_} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $self->{"sockets"}{$_} or ref $self->{"sockets"}{$_} eq "HASH" 0 0 0
Condition0%0/3
not ref $self->{"sockets"}{$_} or ref $self->{"sockets"}{$_} eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $self->{"sockets"}{$_} or ref $self->{"sockets"}{$_} eq "HASH"
not ref $self->{"sockets"}{$_} ref $self->{"sockets"}{$_} eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $self->{"sockets"}{$_}B= ref $self->{"sockets"}{$_} eq "HASH"
ABresult
1X1
011
000
1006 #$self->log( 'dev',ref $self->{sockets}{$_});
1007 0 $ret += $self->{sockets}{$_}->recv($_);
1008 }
1009 #if ( $self->{'filehandle_send'} ) { $self->file_send_part(); }
1010 #$self->{'recv_runned'}{ $self->{'number'} } = undef;
1011 0 return $ret;
1012 }
1013  
1014 =no
1015 sub wait { #$self->{'wait'} ||= sub {
1016 my $self = shift;
1017 my ( $waits, $wait_once ) = @_;
1018 $waits ||= $self->{'waits'};
1019 #$wait_once ||= $self->{'wait_once'};
1020 local $_;
1021 my $ret;
1022 #$self->log( 'dev', "start wait", $waits, caller, '::::', caller 1, );
1023 while ( --$waits > 0 and !$ret ) {
1024 #$ret += $self->select($wait_once);
1025 last unless $self->active();
1026 $ret += $self->select(undef, 1);
1027 #$self->log( 'dev', "wait", $waits, $ret);
1028 #sleep 0.1 if !$ret;
1029 }
1030 #$ret += $self->work($wait_once) while --$waits > 0 and !$ret;
1031 return $ret;
1032 }
1033 =cut
1034  
1035 0 ▶sub finished { #$self->{'finished'} ||= sub {
Subroutine finished: not called CC=5 SCAR=34.0
Pod undocumented
1036 0 my $self = shift;
1037 $self->log( 'dcdev', 'not finished file:', "$self->{'filebytes'} / $self->{'filetotal'}", $self->{'peernick'} ), return 0
1038 if ($self->{'filebytes'}
1039 and $self->{'filetotal'}
1040 0 ▶ and $self->{'filebytes'} < $self->{'filetotal'} - 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filebytes"} and $self->{"filetotal"} and $self->{"filebytes"} < $self->{"filetotal"} - 1 0 0 0
Condition0%0/6
$self->{"filebytes"} and $self->{"filetotal"} and $self->{"filebytes"} < $self->{"filetotal"} - 1
!ll&&!rl&&r
000
$self->{"filebytes"} and $self->{"filetotal"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"filebytes"} and $self->{"filetotal"} and $self->{"filebytes"} < $self->{"filetotal"} - 1
$self->{"filebytes"} $self->{"filetotal"} $self->{"filebytes"} < $self->{"filetotal"} - 1
Truth table0%0/4
A and B and C
A= $self->{"filebytes"}B= $self->{"filetotal"}C= $self->{"filebytes"} < $self->{"filetotal"} - 1
ABCresult
0XX0
10X0
1100
1111
1041 0 local @_;
1042 $self->log( 'dcdev', 'not finished clients:', @_ ), return 0
1043 if @_ =
1044 0 ▶ grep { !$self->{'clients'}{$_}->finished() } $self->clients_my(); #keys %{ $self->{'clients'} };
Branch: 1 branch
BranchTrueFalseTotal
if @_ = grep({not $self->{"clients"}{$_}->finished;} $self->clients_my) 0 0 0
1045 0 return 1;
1046 }
1047  
1048 0 ▶sub wait_connect { #$self->{'wait_connect'} ||= sub {
Subroutine wait_connect: not called CC=4 SCAR=30.0
Pod undocumented
1049 0 my $self = shift;
1050 #$self->log( 'dev', "wait_connect", $self->{'wait_connect_tries'});
1051 0 ▶ for ( 0 .. ( $_[0] || $self->{'wait_connect_tries'} ) ) {
Condition0%0/3
$_[0] || $self->{'wait_connect_tries'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] || $self->{'wait_connect_tries'}
$_[0] $self->{'wait_connect_tries'}
Truth table0%0/3
A || B
A= $_[0]B= $self->{'wait_connect_tries'}
ABresult
1X1
011
000
1052 #$self->log('dev', 'ws', $self->{'status'}, $_, ( $_[0] , $self->{'wait_connect_tries'}));
1053 0 ▶ last if grep { $self->{'status'} eq $_ } qw(connected transfer disconnecting disconnected destroy), '';
Branch: 1 branch
BranchTrueFalseTotal
if grep {$self->{"status"} eq $_;} ("connected", "transfer", "disconnecting", "disconnected", "destroy"), "" 0 0 0
1054 #$self->wait(1);
1055 0 $self->work(1);
1056 }
1057 0 return $self->{'status'};
1058 }
1059  
1060 0 ▶sub wait_finish { #$self->{'wait_finish'} ||= sub {
Subroutine wait_finish: not called CC=5 SCAR=34.0
Pod undocumented
1061 0 my $self = shift;
1062 0 ▶ my $time = time() + ( shift || $self->{'wait_finish'} );
Condition0%0/3
shift() || $self->{'wait_finish'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'wait_finish'}
shift() $self->{'wait_finish'}
Truth table0%0/3
A || B
A= shift()B= $self->{'wait_finish'}
ABresult
1X1
011
000
1063 0 ▶ while ( $time > time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time > &Net::DirectConnect::time()) 0 0 0
1064 #for ( 0 .. $self->{'wait_finish_tries'} ) {
1065 0 ▶ last if $self->finished();
Branch: 1 branch
BranchTrueFalseTotal
if $self->finished 0 0 0
1066 #$self->wait( undef, $self->{'wait_finish_by'} );
1067 #$self->log( 'dev', 'wait_finish', $_);
1068 #$self->wait();
1069 0 $self->work(1);
1070 #$self->work( undef, $self->{'wait_finish_by'} );
1071 }
1072 0 local @_;
1073 $self->info(),
1074 $self->log(
1075 'info',
1076 'finished, but clients still active:',
1077 0 ▶ map { "[$self->{'clients'}{$_}{'number'}]$_;st=$self->{'clients'}{$_}{'status'}" } @_
Branch: 1 branch
BranchTrueFalseTotal
if @_ = $self->clients_my 0 0 0
1078 ) if @_ = $self->clients_my(); #keys %{ $self->{'clients'} };
1079 }
1080  
1081 0 ▶sub wait_clients { #$self->{'wait_clients'} ||= sub {
Subroutine wait_clients: not called CC=6 SCAR=37.4
Pod undocumented
1082 0 my $self = shift;
1083 #for my $n ( 0 .. $self->{'wait_clients_tries'} ) {
1084 0 ▶ my $time = time() + ( shift || $self->{'wait_clients'} );
Condition0%0/3
shift() || $self->{'wait_clients'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'wait_clients'}
shift() $self->{'wait_clients'}
Truth table0%0/3
A || B
A= shift()B= $self->{'wait_clients'}
ABresult
1X1
011
000
1085 0 ▶ while ( $time > time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time > &Net::DirectConnect::time()) 0 0 0
1086 0 local @_;
1087 last
1088 if !$self->{'clients_max'}
1089 0 ▶ or $self->{'clients_max'} > ( @_ = $self->clients_my() ); #keys %{ $self->{'clients'} };
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"clients_max"} or $self->{"clients_max"} > (@_ = $self->clients_my) 0 0 0
Condition0%0/3
not $self->{"clients_max"} or $self->{"clients_max"} > (@_ = $self->clients_my)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->{"clients_max"} or $self->{"clients_max"} > (@_ = $self->clients_my)
not $self->{"clients_max"} $self->{"clients_max"} > (@_ = $self->clients_my)
Truth table0%0/3
not(A) or B
A= not $self->{"clients_max"}B= $self->{"clients_max"} > (@_ = $self->clients_my)
ABresult
1X1
011
000
1090 0 ▶ $self->info() unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
1091 0 $self->log(
1092 'info', "wait clients",
1093 scalar( @_ = $self->clients_my() ) . "/$self->{'clients_max'} ",
1094 int( $time - time() )
1095 );
1096 #$self->wait( undef, $self->{'wait_clients_by'} );
1097 0 $self->work(10);
1098 }
1099 }
1100 #sub wait_sleep { #$self->{'wait_sleep'} ||= sub {
1101 0 ▶sub wait { #$self->{'wait_sleep'} ||= sub {
Subroutine wait: not called CC=5 SCAR=34.0
Pod undocumented
1102 0 my $self = shift;
1103 0 my $ret;
1104 0 ▶ my $time = time() + ( shift || 1 );
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1105 #$self->log( 'dev', "wait_sleep", $time );
1106 0 ▶ while ( $time > time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time > &Net::DirectConnect::time()) 0 0 0
1107 0 ▶ last unless $self->active();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->active 0 0 0
1108 #$ret += $self->wait(@_);
1109 0 ▶ $ret += $self->select() || $self->select( 1, 1 );
Condition0%0/3
$self->select || $self->select(1, 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->select || $self->select(1, 1)
$self->select $self->select(1, 1)
Truth table0%0/3
A || B
A= $self->selectB= $self->select(1, 1)
ABresult
1X1
011
000
1110 }
1111 0 return $ret;
1112 #$self->log( 'dev', "wait_sleep",$starttime , $how , time(), "==", $starttime + $how),
1113 #$self->work(@_) while $starttime + $how > time();
1114 }
1115  
1116 0 ▶sub work { #$self->{'work'} ||= sub {
Subroutine work: not called CC=11 SCAR=48.8
Pod undocumented
1117 0 my $self = shift;
1118 #$self->log( 'dev', 'work', ref $self->{parent}, $self->{parent});
1119 0 ▶ return $self->{parent}->work(@_) if is_object($self->{parent});
Branch: 1 branch
BranchTrueFalseTotal
if &is_object($self->{"parent"}) 0 0 0
1120 0 my @params = @_;
1121 #$self->periodic();
1122 #$self->log( 'dev', 'work', @params);
1123 0 code_run $self->{'auto_work'}, @params; # if ref $self->{'auto_work'} eq 'CODE';
1124 schedule(
1125 1,
1126 0 ▶ our $___work_every ||= sub {
Subroutine __ANON__: not called CC=19 SCAR=59.4
1127 0 my $self = shift;
1128 0 $self->connect_check();
1129 0 ▶ code_run( $_, $self ) for values %{ $self->{periodic} || {} };
Condition0%0/2
$self->{'periodic'} || {}
l!l
00
MC/DC0%0/1
$self->{'periodic'} || {}
$self->{'periodic'}
Truth table0%0/2
A
A= $self->{'periodic'}
Aresult
11
00
1130 #print ("P:$_\n"),
1131 #$self->{periodic}{$_}->() for grep {ref$self->{periodic}{$_} eq 'CODE'}keys %{$self->{periodic} || {}};
1132 #$self->log('dev', 'work for', keys %{$self->{'clients'}});
1133 0 for (
1134 0 keys %{ $self->{'clients'} }
1135 #$self->clients_my()
1136 )
1137 {
1138 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}) 0 0 0
Condition0%0/18
not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}
l!l&&r!l&&!r
000
not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy"
l!l&&r!l&&!r
000
$self->{'clients'}{$_}{'socket'} && length $self->{'clients'}{$_}{'status'}
!ll&&!rl&&r
000
$self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}
!ll&&!rl&&r
000
$self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"}
!ll&&!rl&&r
000
$self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working"
!ll&&!rl&&r
000
MC/DC0%0/7
not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}
$self->{'clients'}{$_}{'socket'} length $self->{'clients'}{$_}{'status'} $self->{"clients"}{$_}{"status"} eq "destroy" $self->{"clients"}{$_}{"status"} ne "listening" $self->{"clients"}{$_}{"status"} ne "working" $self->{"clients"}{$_}{"inactive_timeout"} &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}
Truth table0%0/8
not(A && B) or C or D and E and F and G
A= $self->{'clients'}{$_}{'socket'}B= length $self->{'clients'}{$_}{'status'}C= $self->{"clients"}{$_}{"status"} eq "destroy"D= $self->{"clients"}{$_}{"status"} ne "listening"E= $self->{"clients"}{$_}{"status"} ne "working"F= $self->{"clients"}{$_}{"inactive_timeout"}G= &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}
ABCDEFGresult
0XXXXXX1
10XXXXX1
111XXXX1
11011111
1100XXX0
11010XX0
110110X0
11011100
1139 !$self->{'clients'}{$_}{'socket'}
1140 or !length $self->{'clients'}{$_}{'status'}
1141 or $self->{'clients'}{$_}{'status'} eq 'destroy'
1142 or ( $self->{'clients'}{$_}{'status'} ne 'listening'
1143 and $self->{'clients'}{$_}{'status'} ne 'working'
1144 and $self->{'clients'}{$_}{inactive_timeout}
1145 and time - $self->{'clients'}{$_}{activity} > $self->{'clients'}{$_}{inactive_timeout} )
1146 )
1147 {
1148 $self->log(
1149 'dev',
1150 "del client[$self->{'clients'}{$_}{'number'}][$_] socket=[$self->{'clients'}{$_}{'socket'}] status=[$self->{'clients'}{$_}{'status'}] listener=[$self->{'listener'}] last active=",
1151 int( time - $self->{'clients'}{$_}{activity} )
1152 0 );
1153 #(
1154 #!ref $self->{'clients'}{$_}{destroy} ? () :
1155 # $self->{'clients'}{$_}->destroy()
1156 #);
1157 #%{$self->{'clients'}{$_}} = (),
1158 0 delete $self->{'clients'}{$_};
1159 #$self->log('dev', "now clients", map { "$_" }sort keys %{ $self->{'clients'} });
1160 0 next;
1161 }
1162 #$ret += $self->{'clients'}{$_}->recv();
1163 #$self->log('dev', 'work', $self->{'clients'}{$_}{'number'}, $self->{'clients'}{$_}, $self);
1164 #next if $self->{'clients'}{$_} eq $self;
1165 #$self->{'clients'}{$_}->work();
1166 }
1167 0 for ( keys %{ $self->{'sockets'} } ) {
1168 0 ▶ next if $self->{'sockets'}{$_} and %{ $self->{'sockets'}{$_} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};} 0 0 0
Condition0%0/3
$self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}
$self->{"sockets"}{$_} %{$self->{"sockets"}{$_};}
Truth table0%0/3
A and B
A= $self->{"sockets"}{$_}B= %{$self->{"sockets"}{$_};}
ABresult
0X0
100
111
1169 0 delete $self->{'sockets'}{$_};
1170 }
1171 #$self->log('dev', 'parent:', $self->{parent}, $self->{parent}{parent}, is_object($self->{parent}));
1172 0 ▶ if ( !$self->{parent} or !$self->{parent}{parent} ) { # first parent always autocreated on init
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"parent"} and $self->{"parent"}{"parent"}) 0 0 0
Condition0%0/3
$self->{"parent"} and $self->{"parent"}{"parent"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"parent"} and $self->{"parent"}{"parent"}
$self->{"parent"} $self->{"parent"}{"parent"}
Truth table0%0/3
A and B
A= $self->{"parent"}B= $self->{"parent"}{"parent"}
ABresult
0X0
100
111
1173 0 code_run( $self->{$_}, $self ) for qw(worker); #auto_work
1174 }
1175 #$self->log('dev', 'work parent', scalar keys %{ $self->{parent}} , scalar keys %{ $self->{parent}{parent}} );
1176 0 for (
1177 0 grep { $self->{'clients'}{$_} ne $self }
1178 0 keys %{ $self->{'clients'} }
1179 #$self->clients_my()
1180 )
1181 {
1182 #$self->log('dev', 'starting work on', $self->{'clients'}{$_}{'number'}, $self,$self->{'clients'}{$_});
1183 0 ▶ $self->{'clients'}{$_}->work() if $self->{'clients'}{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clients"}{$_} 0 0 0
1184 }
1185 },
1186 0 ▶ $self
Condition0%0/3
our $___work_every ||= sub { my $self = shift(); $self->connect_check; &code_run($_, $self) foreach (values %{$self->{"periodic"} or {};}); foreach $_ (keys %{$$self{"clients"};}) { if (not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}) { $self->log("dev", qq[del client[$self->{"clients"}{$_}{"number"}][$_] socket=[$self->{"clients"}{$_}{"socket"}] status=[$self->{"clients"}{$_}{"status"}] listener=[$self->{"listener"}] last active=], int &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"}); delete $self->{"clients"}{$_}; next; } ; } ; foreach $_ (keys %{$$self{"sockets"};}) { next if $self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}; delete $self->{"sockets"}{$_}; } ; unless ($self->{"parent"} and $self->{"parent"}{"parent"}) { &code_run($self->{$_}, $self) foreach ("worker"); } ; foreach $_ (grep {$self->{"clients"}{$_} ne $self;} keys %{$$self{"clients"};}) { $self->{"clients"}{$_}->work if $self->{"clients"}{$_}; } ; }
l!l&&r!l&&!r
000
MC/DC0%0/2
our $___work_every ||= sub { my $self = shift(); $self->connect_check; &code_run($_, $self) foreach (values %{$self->{"periodic"} or {};}); foreach $_ (keys %{$$self{"clients"};}) { if (not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}) { $self->log("dev", qq[del client[$self->{"clients"}{$_}{"number"}][$_] socket=[$self->{"clients"}{$_}{"socket"}] status=[$self->{"clients"}{$_}{"status"}] listener=[$self->{"listener"}] last active=], int &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"}); delete $self->{"clients"}{$_}; next; } ; } ; foreach $_ (keys %{$$self{"sockets"};}) { next if $self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}; delete $self->{"sockets"}{$_}; } ; unless ($self->{"parent"} and $self->{"parent"}{"parent"}) { &code_run($self->{$_}, $self) foreach ("worker"); } ; foreach $_ (grep {$self->{"clients"}{$_} ne $self;} keys %{$$self{"clients"};}) { $self->{"clients"}{$_}->work if $self->{"clients"}{$_}; } ; }
our $___work_every sub { my $self = shift(); $self->connect_check; &code_run($_, $self) foreach (values %{$self->{"periodic"} or {};}); foreach $_ (keys %{$$self{"clients"};}) { if (not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}) { $self->log("dev", qq[del client[$self->{"clients"}{$_}{"number"}][$_] socket=[$self->{"clients"}{$_}{"socket"}] status=[$self->{"clients"}{$_}{"status"}] listener=[$self->{"listener"}] last active=], int &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"}); delete $self->{"clients"}{$_}; next; } ; } ; foreach $_ (keys %{$$self{"sockets"};}) { next if $self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}; delete $self->{"sockets"}{$_}; } ; unless ($self->{"parent"} and $self->{"parent"}{"parent"}) { &code_run($self->{$_}, $self) foreach ("worker"); } ; foreach $_ (grep {$self->{"clients"}{$_} ne $self;} keys %{$$self{"clients"};}) { $self->{"clients"}{$_}->work if $self->{"clients"}{$_}; } ; }
Truth table0%0/3
A ||= B
A= our $___work_everyB= sub { my $self = shift(); $self->connect_check; &code_run($_, $self) foreach (values %{$self->{"periodic"} or {};}); foreach $_ (keys %{$$self{"clients"};}) { if (not $self->{"clients"}{$_}{"socket"} && length $self->{"clients"}{$_}{"status"} or $self->{"clients"}{$_}{"status"} eq "destroy" or $self->{"clients"}{$_}{"status"} ne "listening" and $self->{"clients"}{$_}{"status"} ne "working" and $self->{"clients"}{$_}{"inactive_timeout"} and &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"} > $self->{"clients"}{$_}{"inactive_timeout"}) { $self->log("dev", qq[del client[$self->{"clients"}{$_}{"number"}][$_] socket=[$self->{"clients"}{$_}{"socket"}] status=[$self->{"clients"}{$_}{"status"}] listener=[$self->{"listener"}] last active=], int &Net::DirectConnect::time() - $self->{"clients"}{$_}{"activity"}); delete $self->{"clients"}{$_}; next; } ; } ; foreach $_ (keys %{$$self{"sockets"};}) { next if $self->{"sockets"}{$_} and %{$self->{"sockets"}{$_};}; delete $self->{"sockets"}{$_}; } ; unless ($self->{"parent"} and $self->{"parent"}{"parent"}) { &code_run($self->{$_}, $self) foreach ("worker"); } ; foreach $_ (grep {$self->{"clients"}{$_} ne $self;} keys %{$$self{"clients"};}) { $self->{"clients"}{$_}->work if $self->{"clients"}{$_}; } ; }
ABresult
1X1
011
000
1187 );
1188 schedule(
1189 10,
1190 0 ▶ our $___work_downloader ||= sub {
Subroutine __ANON__: not called CC=24 SCAR=64.0
1191 0 my $self = shift;
1192 0 ▶ return unless $self->active();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->active 0 0 0
1193 0 ▶ return if $self->{'status'} eq 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"status"} eq "listening" 0 0 0
1194 0 my $time = time;
1195 0 for my $tth ( keys %{ $self->{'downloading'} } ) {
1196 0 ▶ if ( $self->{'downloading'}{$tth}{connect_start}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60) 0 0 0
Condition0%0/3
$self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60
$self->{"downloading"}{$tth}{"connect_start"} $self->{"downloading"}{$tth}{"connect_start"} < $time - 60
Truth table0%0/3
A and B
A= $self->{"downloading"}{$tth}{"connect_start"}B= $self->{"downloading"}{$tth}{"connect_start"} < $time - 60
ABresult
0X0
100
111
1197 and $self->{'downloading'}{$tth}{connect_start} < $time - 60 )
1198 {
1199 #$self->log('dev', 'want', $tth,'no connection, return to want queue');
1200 0 $self->{'want_download'}{$tth} = $self->{'downloading'}{$tth};
1201 0 delete $self->{'downloading'}{$tth};
1202 }
1203 }
1204 0 for my $tth ( keys %{ $self->{'want_download'} } ) {
1205 0 delete $self->{'want_download'}{$tth}{connect_start};
1206 }
1207 0 ▶ if ( $self->{'queue_download'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"queue_download"} and @{$self->{"queue_download"};}) 0 0 0
Condition0%0/3
$self->{"queue_download"} and @{$self->{"queue_download"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"queue_download"} and @{$self->{"queue_download"};}
$self->{"queue_download"} @{$self->{"queue_download"};}
Truth table0%0/3
A and B
A= $self->{"queue_download"}B= @{$self->{"queue_download"};}
ABresult
0X0
100
111
1208 0 and @{ $self->{'queue_download'} } )
1209 {
1210 0 my $file = shift @{ $self->{'queue_download'} };
1211 0 $self->search($file);
1212 }
1213 #if (!)
1214 #=todo
1215 #$self->log('dev', 'work want:', Dumper $self->{'want_download'});
1216 0 for my $tth (
1217 0 grep { keys %{ $self->{'want_download'}{$_} } }
1218 0 keys %{ $self->{'want_download'} }
1219 )
1220 {
1221 0 ▶ my $wdls = $self->{'want_download'}{$tth} || {};
Condition0%0/2
$self->{'want_download'}{$tth} || {}
l!l
00
MC/DC0%0/1
$self->{'want_download'}{$tth} || {}
$self->{'want_download'}{$tth}
Truth table0%0/2
A
A= $self->{'want_download'}{$tth}
Aresult
11
00
1222 local @_ = (
1223 #grep { $wdls->{$_}{slotsfree} or $wdls->{$_}{SL} }
1224 sort {
1225 0 $wdls->{$a}{tries} <=> $wdls->{$b}{tries}
1226 or ( $wdls->{$b}{slotsfree} || $wdls->{$b}{SL} ) <=> ( $wdls->{$a}{slotsfree} || $wdls->{$a}{SL} )
1227 0 ▶ } keys %$wdls
Condition0%0/9
$wdls->{$a}{'tries'} <=> $wdls->{$b}{'tries'} || ($wdls->{$b}{'slotsfree'} || $wdls->{$b}{'SL'}) <=> ($wdls->{$a}{'slotsfree'} || $wdls->{$a}{'SL'})
l!l&&r!l&&!r
000
$wdls->{$b}{'slotsfree'} || $wdls->{$b}{'SL'}
l!l&&r!l&&!r
000
$wdls->{$a}{'slotsfree'} || $wdls->{$a}{'SL'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$wdls->{$a}{'tries'} <=> $wdls->{$b}{'tries'} || ($wdls->{$b}{'slotsfree'} || $wdls->{$b}{'SL'}) <=> ($wdls->{$a}{'slotsfree'} || $wdls->{$a}{'SL'})
$wdls->{$a}{'tries'} <=> $wdls->{$b}{'tries'} $wdls->{$b}{'slotsfree'} $wdls->{$b}{'SL'}
MC/DC0%0/2
$wdls->{$a}{'slotsfree'} || $wdls->{$a}{'SL'}
$wdls->{$a}{'slotsfree'} $wdls->{$a}{'SL'}
Truth table0%0/4
A || B || C
A= $wdls->{$a}{'tries'} <=> $wdls->{$b}{'tries'}B= $wdls->{$b}{'slotsfree'}C= $wdls->{$b}{'SL'}
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/3
A || B
A= $wdls->{$a}{'slotsfree'}B= $wdls->{$a}{'SL'}
ABresult
1X1
011
000
1228 );
1229 #$self->log('dev', 'from can:', @_ );
1230 0 ▶ if ( my ($fromk) = $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($fromk) = $_[0]) 0 0 0
1231 0 my $from = $wdls->{$fromk};
1232 0 my ($filename);
1233 0 for my $file ( keys %{ $self->{'want_download_filename'}{$tth} } ) {
1234 0 my $partial = $file;
1235 0 $partial = $self->{'partial_prefix'} . $partial . $self->{'partial_ext'};
1236 $partial = Encode::encode $self->{charset_fs}, $file, Encode::FB_WARN
1237 0 ▶ if $self->{charset_fs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
1238 0 ▶ if ( -s $partial ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $partial) 0 0 0
1239 0 $self->log( 'dev', 'already downloading: ', $file, -s $partial );
1240 0 $filename = $file;
1241 0 last;
1242 }
1243 }
1244 $filename //= (
1245 0 sort { $self->{'want_download_filename'}{$tth}{$a} <=> $self->{'want_download_filename'}{$tth}{$b} }
1246 0 ▶ keys %{ $self->{'want_download_filename'}{$tth} }
Condition0%0/3
$filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]
$filename (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]
Truth table0%0/3
A //= B
A= $filenameB= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]
ABresult
1X1
011
000
1247 )[0];
1248 0 ▶ $filename //= $from->{FN};
Condition0%0/3
$filename //= $from->{"FN"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename //= $from->{"FN"}
$filename $from->{"FN"}
Truth table0%0/3
A //= B
A= $filenameB= $from->{"FN"}
ABresult
1X1
011
000
1249 0 $filename =~ s{^.*[/\\]}{}g;
1250 #$self->log( "selected22 [$filename] keys",( grep { $wdls->{$_}{slotsfree} or $wdls->{$_}{SL} } sort {$wdls->{$b}{tries} <=> $wdls->{$a}{tries} }keys %$wdls )," from", Dumper $from,);
1251 #my $dst = $self->{'get_dir'} . $filename;
1252 0 ▶ my $size = $from->{size} || $from->{SI} || 0;
Condition0%0/5
$from->{'size'} || $from->{'SI'} || 0
l!l
00
$from->{"size"} or $from->{"SI"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$from->{'size'} || $from->{'SI'} || 0
$from->{"size"} $from->{"SI"}
Truth table0%0/3
A or B
A= $from->{"size"}B= $from->{"SI"}
ABresult
1X1
011
000
1253 #my $sizenow = -s $dst || 0;
1254 #$self->log( 'dcdev', "selected23 -e $dst and ( !$size or $sizenow < $size" );
1255 #if ( !-e $dst or ( !$size or $sizenow < $size ) ) {
1256 0 ++$self->{'want_download'}{$tth}{$fromk}{tries};
1257 $self->get(
1258 $from->{nick} || $from->{CID} || $from->{NI},
1259 #'TTH/' . $tth,
1260 0 ▶ undef, $filename, undef, undef, $size, $tth
Condition0%0/6
$from->{'nick'} || $from->{'CID'} || $from->{'NI'}
l!l&&r!l&&!r
000
$from->{"nick"} or $from->{"CID"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$from->{'nick'} || $from->{'CID'} || $from->{'NI'}
$from->{"nick"} $from->{"CID"} $from->{'NI'}
Truth table0%0/4
A or B || C
A= $from->{"nick"}B= $from->{"CID"}C= $from->{'NI'}
ABCresult
1XX1
01X1
0011
0000
1261 );
1262 0 $self->{'downloading'}{$tth} = $self->{'want_download'}{$tth};
1263 0 $self->{'downloading'}{$tth}{connect_start} = $time;
1264 0 delete $self->{'want_download'}{$tth};
1265 0 last;
1266 #}
1267 #$work{'tthfrom'}{$s{tth}}
1268 }
1269 }
1270 #=cut
1271 },
1272 0 ▶ $self
Condition0%0/3
our $___work_downloader ||= sub { my $self = shift(); return unless $self->active; return if $self->{"status"} eq "listening"; my $time = &Net::DirectConnect::time(); foreach my $tth (keys %{$$self{"downloading"};}) { if ($self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60) { $self->{"want_download"}{$tth} = $self->{"downloading"}{$tth}; delete $self->{"downloading"}{$tth}; } ; } ; foreach my $tth (keys %{$$self{"want_download"};}) { delete $self->{"want_download"}{$tth}{"connect_start"}; } ; if ($self->{"queue_download"} and @{$self->{"queue_download"};}) { my $file = shift @{$$self{"queue_download"};}; $self->search($file); } ; foreach my $tth (grep {keys %{$$self{"want_download"}{$_};};} keys %{$$self{"want_download"};}) { my $wdls = $self->{"want_download"}{$tth} || {}; local(@_) = (sort {$wdls->{$a}{"tries"} <=> $wdls->{$b}{"tries"} or ($wdls->{$b}{"slotsfree"} || $wdls->{$b}{"SL"}) <=> ($wdls->{$a}{"slotsfree"} || $wdls->{$a}{"SL"});} keys %$wdls); if (my($fromk) = $_[0]) { my $from = $wdls->{$fromk}; my $filename; foreach my $file (keys %{$$self{"want_download_filename"}{$tth};}) { my $partial = $file; $partial = $self->{"partial_prefix"} . $partial . $self->{"partial_ext"}; $partial = &Encode::encode($self->{"charset_fs"}, $file, 6) if $self->{"charset_fs"}; if (-s $partial) { $self->log("dev", "already downloading: ", $file, -s $partial); $filename = $file; last; } ; } ; $filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]; $filename //= $from->{"FN"}; $filename =~ s(^.*[/\\])[]g; my $size = $from->{"size"} || $from->{"SI"} || 0; ++$self->{"want_download"}{$tth}{$fromk}{"tries"}; $self->get($from->{"nick"} || $from->{"CID"} || $from->{"NI"}, undef, $filename, undef, undef, $size, $tth); $self->{"downloading"}{$tth} = $self->{"want_download"}{$tth}; $self->{"downloading"}{$tth}{"connect_start"} = $time; delete $self->{"want_download"}{$tth}; last; } ; } ; }
l!l&&r!l&&!r
000
MC/DC0%0/2
our $___work_downloader ||= sub { my $self = shift(); return unless $self->active; return if $self->{"status"} eq "listening"; my $time = &Net::DirectConnect::time(); foreach my $tth (keys %{$$self{"downloading"};}) { if ($self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60) { $self->{"want_download"}{$tth} = $self->{"downloading"}{$tth}; delete $self->{"downloading"}{$tth}; } ; } ; foreach my $tth (keys %{$$self{"want_download"};}) { delete $self->{"want_download"}{$tth}{"connect_start"}; } ; if ($self->{"queue_download"} and @{$self->{"queue_download"};}) { my $file = shift @{$$self{"queue_download"};}; $self->search($file); } ; foreach my $tth (grep {keys %{$$self{"want_download"}{$_};};} keys %{$$self{"want_download"};}) { my $wdls = $self->{"want_download"}{$tth} || {}; local(@_) = (sort {$wdls->{$a}{"tries"} <=> $wdls->{$b}{"tries"} or ($wdls->{$b}{"slotsfree"} || $wdls->{$b}{"SL"}) <=> ($wdls->{$a}{"slotsfree"} || $wdls->{$a}{"SL"});} keys %$wdls); if (my($fromk) = $_[0]) { my $from = $wdls->{$fromk}; my $filename; foreach my $file (keys %{$$self{"want_download_filename"}{$tth};}) { my $partial = $file; $partial = $self->{"partial_prefix"} . $partial . $self->{"partial_ext"}; $partial = &Encode::encode($self->{"charset_fs"}, $file, 6) if $self->{"charset_fs"}; if (-s $partial) { $self->log("dev", "already downloading: ", $file, -s $partial); $filename = $file; last; } ; } ; $filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]; $filename //= $from->{"FN"}; $filename =~ s(^.*[/\\])[]g; my $size = $from->{"size"} || $from->{"SI"} || 0; ++$self->{"want_download"}{$tth}{$fromk}{"tries"}; $self->get($from->{"nick"} || $from->{"CID"} || $from->{"NI"}, undef, $filename, undef, undef, $size, $tth); $self->{"downloading"}{$tth} = $self->{"want_download"}{$tth}; $self->{"downloading"}{$tth}{"connect_start"} = $time; delete $self->{"want_download"}{$tth}; last; } ; } ; }
our $___work_downloader sub { my $self = shift(); return unless $self->active; return if $self->{"status"} eq "listening"; my $time = &Net::DirectConnect::time(); foreach my $tth (keys %{$$self{"downloading"};}) { if ($self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60) { $self->{"want_download"}{$tth} = $self->{"downloading"}{$tth}; delete $self->{"downloading"}{$tth}; } ; } ; foreach my $tth (keys %{$$self{"want_download"};}) { delete $self->{"want_download"}{$tth}{"connect_start"}; } ; if ($self->{"queue_download"} and @{$self->{"queue_download"};}) { my $file = shift @{$$self{"queue_download"};}; $self->search($file); } ; foreach my $tth (grep {keys %{$$self{"want_download"}{$_};};} keys %{$$self{"want_download"};}) { my $wdls = $self->{"want_download"}{$tth} || {}; local(@_) = (sort {$wdls->{$a}{"tries"} <=> $wdls->{$b}{"tries"} or ($wdls->{$b}{"slotsfree"} || $wdls->{$b}{"SL"}) <=> ($wdls->{$a}{"slotsfree"} || $wdls->{$a}{"SL"});} keys %$wdls); if (my($fromk) = $_[0]) { my $from = $wdls->{$fromk}; my $filename; foreach my $file (keys %{$$self{"want_download_filename"}{$tth};}) { my $partial = $file; $partial = $self->{"partial_prefix"} . $partial . $self->{"partial_ext"}; $partial = &Encode::encode($self->{"charset_fs"}, $file, 6) if $self->{"charset_fs"}; if (-s $partial) { $self->log("dev", "already downloading: ", $file, -s $partial); $filename = $file; last; } ; } ; $filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]; $filename //= $from->{"FN"}; $filename =~ s(^.*[/\\])[]g; my $size = $from->{"size"} || $from->{"SI"} || 0; ++$self->{"want_download"}{$tth}{$fromk}{"tries"}; $self->get($from->{"nick"} || $from->{"CID"} || $from->{"NI"}, undef, $filename, undef, undef, $size, $tth); $self->{"downloading"}{$tth} = $self->{"want_download"}{$tth}; $self->{"downloading"}{$tth}{"connect_start"} = $time; delete $self->{"want_download"}{$tth}; last; } ; } ; }
Truth table0%0/3
A ||= B
A= our $___work_downloaderB= sub { my $self = shift(); return unless $self->active; return if $self->{"status"} eq "listening"; my $time = &Net::DirectConnect::time(); foreach my $tth (keys %{$$self{"downloading"};}) { if ($self->{"downloading"}{$tth}{"connect_start"} and $self->{"downloading"}{$tth}{"connect_start"} < $time - 60) { $self->{"want_download"}{$tth} = $self->{"downloading"}{$tth}; delete $self->{"downloading"}{$tth}; } ; } ; foreach my $tth (keys %{$$self{"want_download"};}) { delete $self->{"want_download"}{$tth}{"connect_start"}; } ; if ($self->{"queue_download"} and @{$self->{"queue_download"};}) { my $file = shift @{$$self{"queue_download"};}; $self->search($file); } ; foreach my $tth (grep {keys %{$$self{"want_download"}{$_};};} keys %{$$self{"want_download"};}) { my $wdls = $self->{"want_download"}{$tth} || {}; local(@_) = (sort {$wdls->{$a}{"tries"} <=> $wdls->{$b}{"tries"} or ($wdls->{$b}{"slotsfree"} || $wdls->{$b}{"SL"}) <=> ($wdls->{$a}{"slotsfree"} || $wdls->{$a}{"SL"});} keys %$wdls); if (my($fromk) = $_[0]) { my $from = $wdls->{$fromk}; my $filename; foreach my $file (keys %{$$self{"want_download_filename"}{$tth};}) { my $partial = $file; $partial = $self->{"partial_prefix"} . $partial . $self->{"partial_ext"}; $partial = &Encode::encode($self->{"charset_fs"}, $file, 6) if $self->{"charset_fs"}; if (-s $partial) { $self->log("dev", "already downloading: ", $file, -s $partial); $filename = $file; last; } ; } ; $filename //= (sort {$self->{"want_download_filename"}{$tth}{$a} <=> $self->{"want_download_filename"}{$tth}{$b};} keys %{$$self{"want_download_filename"}{$tth};})[0]; $filename //= $from->{"FN"}; $filename =~ s(^.*[/\\])[]g; my $size = $from->{"size"} || $from->{"SI"} || 0; ++$self->{"want_download"}{$tth}{$fromk}{"tries"}; $self->get($from->{"nick"} || $from->{"CID"} || $from->{"NI"}, undef, $filename, undef, undef, $size, $tth); $self->{"downloading"}{$tth} = $self->{"want_download"}{$tth}; $self->{"downloading"}{$tth}{"connect_start"} = $time; delete $self->{"want_download"}{$tth}; last; } ; } ; }
ABresult
1X1
011
000
1273 );
1274 schedule(
1275 [ $self->{dev_auto_dump_first} || 20, $self->{dev_auto_dump_every} || 100 ],
1276 0 ▶ our $dump_sub__ ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1277 0 my $self = shift;
1278 0 $self->dumper();
1279 },
1280 $self
1281 0 ▶ ) if $self->{dev_auto_dump};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dev_auto_dump"} 0 0 0
Condition0%0/7
$self->{'dev_auto_dump_first'} || 20
l!l
00
$self->{'dev_auto_dump_every'} || 100
l!l
00
our $dump_sub__ ||= sub { my $self = shift(); $self->dumper; }
l!l&&r!l&&!r
000
MC/DC0%0/1
$self->{'dev_auto_dump_first'} || 20
$self->{'dev_auto_dump_first'}
MC/DC0%0/1
$self->{'dev_auto_dump_every'} || 100
$self->{'dev_auto_dump_every'}
MC/DC0%0/2
our $dump_sub__ ||= sub { my $self = shift(); $self->dumper; }
our $dump_sub__ sub { my $self = shift(); $self->dumper; }
Truth table0%0/2
A
A= $self->{'dev_auto_dump_first'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'dev_auto_dump_every'}
Aresult
11
00
Truth table0%0/3
A ||= B
A= our $dump_sub__B= sub { my $self = shift(); $self->dumper; }
ABresult
1X1
011
000
1282 #return
1283 0 $self->select( 1 || $self->{'work_sleep'} ); # if @{$self->{send_buffer_raw}|| []}; # maybe send
1284 #$self->log( 'dev', "work -> sleep", @params ),
1285 0 ▶ return $self->wait(@params) if @params;
Branch: 1 branch
BranchTrueFalseTotal
if @params 0 0 0
1286 return
1287 $self->select( undef, 1 )
1288 0 ▶ || $self->select( $self->{'work_sleep'} )
Condition0%0/6
$self->select(undef, 1) || $self->select($self->{'work_sleep'}) || $self->select(undef, 1)
l!l&&r!l&&!r
000
$self->select(undef, 1) or $self->select($self->{"work_sleep"})
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->select(undef, 1) || $self->select($self->{'work_sleep'}) || $self->select(undef, 1)
$self->select(undef, 1) $self->select($self->{"work_sleep"}) $self->select(undef, 1)
Truth table0%0/4
A or B || C
A= $self->select(undef, 1)B= $self->select($self->{"work_sleep"})C= $self->select(undef, 1)
ABCresult
1XX1
01X1
0011
0000
1289 || $self->select( undef, 1 ); # unless @{$self->{send_buffer_raw}|| []};
1290 #return $self->select( $self->{'work_sleep'} );
1291 }
1292  
1293 0 ▶sub dumper { #$self->{'dumper'} ||= sub {
Subroutine dumper: not called CC=5 SCAR=34.0
Pod undocumented
1294 0 my $self = shift;
1295 0 ▶ my $file = $_[0] || $self->{dev_auto_dump_file} || $0 . ( $self->{dev_auto_dump_timed} ? '.' . time : () ) . '.dump';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'dev_auto_dump_timed'} ? : 0 0 0
Condition0%0/5
$_[0] || $self->{'dev_auto_dump_file'} || $0 . ($self->{'dev_auto_dump_timed'} ? '.' . &Net::DirectConnect::time() : ()) . '.dump'
l!l
00
$_[0] or $self->{"dev_auto_dump_file"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] || $self->{'dev_auto_dump_file'} || $0 . ($self->{'dev_auto_dump_timed'} ? '.' . &Net::DirectConnect::time() : ()) . '.dump'
$_[0] $self->{"dev_auto_dump_file"}
Truth table0%0/3
A or B
A= $_[0]B= $self->{"dev_auto_dump_file"}
ABresult
1X1
011
000
1296 0 ▶ open my $fh, '>', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or return 0 0 0
1297 0 print $fh Dumper $self;
1298 0 close $fh;
1299 0 $self->log( 'dev', "Writed dump", -s $file );
1300 }
1301  
1302 0 ▶sub parser { #$self->{'parser'} ||= sub {
Subroutine parser: not called CC=30 SCAR=68.4
Pod undocumented
1303 0 my $self = shift;
1304 0 for ( local @_ = @_ ) {
1305 $self->log(
1306 'dcdmp',
1307 "rawrcv["
1308 . (
1309 $self->{'recv_hostip'}
1310 ? $self->{'recv_hostip'} . ':' . $self->{'recv_port'}
1311 0 ▶ : $self->{'host'}
Branch: 1 branch
BranchTrueFalseTotal
$self->{'recv_hostip'} ? : 0 0 0
1312 )
1313 . "]:",
1314 $_
1315 );
1316 0 my ( $dst, $cmd, @param );
1317 0 ▶ if (/^[<*]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[<*]/) 0 0 0
1318 0 ▶ $cmd = ( $self->{'status'} eq 'connected' ? 'chatline' : 'welcome' );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'status'} eq 'connected' ? : 0 0 0
1319 }
1320 0 ▶ s/^\x00*\$?([\w\-]+)\s*//, $cmd = $1 unless $cmd; # \x00 - ssl bug on recv
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
1321 #$self->log('dev',"cmd[", Dumper($cmd),"], adc=", $self->{'adc'} );
1322 0 ▶ if ( $self->{'adc'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'adc'}) { } 0 0 0
1323 0 $cmd =~ s/^([BCDEFHIU])//, $dst = $1;
1324 0 @param = ( [$dst], split / / );
1325 0 ▶ if ( $dst eq 'B'
Branch: 2 branches
BranchTrueFalseTotal
if ($dst eq 'B' or $dst eq 'F' or $dst eq 'U' or $self->{'broadcast'}) { } 0 0 0
elsif ($dst eq 'D' or $dst eq 'E') { } 0 0 0
Condition0%0/9
$dst eq "B" or $dst eq "F" or $dst eq "U" or $self->{"broadcast"}
l!l&&r!l&&!r
000
$dst eq "B" or $dst eq "F" or $dst eq "U"
l!l&&r!l&&!r
000
$dst eq "B" or $dst eq "F"
l!l&&r!l&&!r
000
MC/DC0%0/4
$dst eq "B" or $dst eq "F" or $dst eq "U" or $self->{"broadcast"}
$dst eq "B" $dst eq "F" $dst eq "U" $self->{"broadcast"}
Truth table0%0/5
A or B or C or D
A= $dst eq "B"B= $dst eq "F"C= $dst eq "U"D= $self->{"broadcast"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1326 or $dst eq 'F'
1327 or $dst eq 'U'
1328 or $self->{broadcast} )
1329 {
1330 #$self->log( 'dcdmp', "P0 $dst$cmd p=",(Dumper \@param));
1331 #push @{ $param[0] }, shift@param;
1332 0 push @{ $param[0] }, splice @param, 1, 1;
1333 #$self->log( 'dcdmp', "P0 $dst$cmd p=",(Dumper \@param));
1334 0 ▶ if ( $dst eq 'F' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst eq "F") 0 0 0
1335 #$self->log( 'dcdmp', 'feature'
1336 0 ▶ push @{ $param[0] }, splice @param, 1, 1 while $param[1] =~ /^[+\-]/;
Branch: 1 branch
BranchTrueFalseTotal
$param[1] =~ /^[+\-]/ and do { push @{$param[0];}, splice(@param, 1, 1) } 0 0 0
1337 }
1338 #$self->log( 'dcdmp', "P1 $dst$cmd p=",(Dumper \@param));
1339 ▶ } elsif ( $dst eq 'D' or $dst eq 'E' ) {
Condition0%0/3
$dst eq "D" or $dst eq "E"
l!l&&r!l&&!r
000
MC/DC0%0/2
$dst eq "D" or $dst eq "E"
$dst eq "D" $dst eq "E"
Truth table0%0/3
A or B
A= $dst eq "D"B= $dst eq "E"
ABresult
1X1
011
000
1340 #push @{ $param[0] }, shift@param, shift@param;
1341 0 push @{ $param[0] }, splice @param, 1, 2;
1342 }
1343 #elsif ( $dst eq 'I' ) { push @{ $param[0] }, undef }
1344 } else {
1345 0 @param = ($_);
1346 }
1347 #$self->log( 'dcdmp', "P3 $dst$cmd p=",(Dumper \@param));
1348 $cmd = $dst . $cmd
1349 if !exists $self->{'parse'}{$cmd}
1350 0 ▶ and exists $self->{'parse'}{ $dst . $cmd };
Branch: 1 branch
BranchTrueFalseTotal
if not exists $self->{"parse"}{$cmd} and exists $self->{"parse"}{$dst . $cmd} 0 0 0
Condition0%0/3
not exists $self->{"parse"}{$cmd} and exists $self->{"parse"}{$dst . $cmd}
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $self->{"parse"}{$cmd} and exists $self->{"parse"}{$dst . $cmd}
not exists $self->{"parse"}{$cmd} exists $self->{"parse"}{$dst . $cmd}
Truth table0%0/3
not(A) and B
A= not exists $self->{"parse"}{$cmd}B= exists $self->{"parse"}{$dst . $cmd}
ABresult
0X0
100
111
1351 #$self->log( 'dcinf', "UNKNOWN PEERCMD:[$cmd]->($_) : please add \$dc->{'parse'}{'$cmd'} = sub { ... };" ),
1352 0 ▶ $self->{'parse'}{$cmd} = sub { }, $cmd = ( $self->{'status'} eq 'connected' ? 'chatline' : 'welcome' )
Subroutine __ANON__: not called CC=1 SCAR=0.0
1353 0 ▶ if $self->{'nmdc'} and !exists $self->{'parse'}{$cmd};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"nmdc"} and not exists $self->{"parse"}{$cmd} 0 0 0
$self->{'status'} eq 'connected' ? : 0 0 0
Condition0%0/3
$self->{"nmdc"} and not exists $self->{"parse"}{$cmd}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"nmdc"} and not exists $self->{"parse"}{$cmd}
$self->{"nmdc"} not exists $self->{"parse"}{$cmd}
Truth table0%0/3
A and not(B)
A= $self->{"nmdc"}B= not exists $self->{"parse"}{$cmd}
ABresult
0X0
100
111
1354 0 ▶ if ( $cmd eq 'chatline' or $cmd eq 'welcome' or $cmd eq 'To' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq 'chatline' or $cmd eq 'welcome' or $cmd eq 'To') { } 0 0 0
Condition0%0/6
$cmd eq "chatline" or $cmd eq "welcome" or $cmd eq "To"
l!l&&r!l&&!r
000
$cmd eq "chatline" or $cmd eq "welcome"
l!l&&r!l&&!r
000
MC/DC0%0/3
$cmd eq "chatline" or $cmd eq "welcome" or $cmd eq "To"
$cmd eq "chatline" $cmd eq "welcome" $cmd eq "To"
Truth table0%0/4
A or B or C
A= $cmd eq "chatline"B= $cmd eq "welcome"C= $cmd eq "To"
ABCresult
1XX1
01X1
0011
0000
1355 #$self->log( 'dev', 'RCV pre encode', ($self->{charset_chat} ), @param, Dumper \@param);
1356 #$_ = Encode::decode(($self->{charset_chat} ), $_) for @param;
1357 #! $_ = Encode::encode $self->{charset_internal}, Encode::decode $self->{charset_chat}, $_ for @param;
1358 #$self->log( 'dev', 'RCV postencode', @param, Dumper \@param);
1359 #Encode::encode $self->{charset_console},;
1360 } else {
1361 #$_ = Encode::encode $self->{charset_internal},
1362 #TODO $_ = Encode::decode($self->{charset_protocol}, $_), for @param;
1363 }
1364 0 my ( @ret, $ret );
1365 #$self->log( 'dcinf', "parsing", $cmd, @_ ,'with',$self->{'parse'}{$cmd}, ref $self->{'parse'}{$cmd});
1366 0 my @self;
1367 #@self = $self if $self->{'adc'};
1368 0 @self = $self; #if !$self->{'nmdc'};
1369 #$self->handler( @self, $cmd . '_parse_bef_bef', @param );
1370 0 $self->handler( @self, $cmd . '_parse_bef', @param );
1371 0 ▶ if ( ref $self->{'parse'}{$cmd} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'parse'}{$cmd} eq 'CODE') { } 0 0 0
1372 0 ▶ if ( !exists $self->{'no_print'}{$cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'no_print'}{$cmd}) { } 0 0 0
1373 0 local $_ = $_;
1374 local @_ =
1375 0 map { "$_:$self->{'skip_print_'.$_}" }
1376 0 grep { $self->{ 'skip_print_' . $_ } }
1377 0 ▶ keys %{ $self->{'no_print'} || {} };
Condition0%0/2
$self->{'no_print'} || {}
l!l
00
MC/DC0%0/1
$self->{'no_print'} || {}
$self->{'no_print'}
Truth table0%0/2
A
A= $self->{'no_print'}
Aresult
11
00
1378 #$self->log( 'dcdmp', "rcv: $dst$cmd p=[",(Dumper \@param),"] ", ( @_ ? ( ' [', @_, ']' ) : () ) );
1379 #$self->log( 'dcdmp', "rcv: $dst$cmd p=[", (map {ref $_ eq 'ARRAY'?@$_:$_}@param), "] ", ( @_ ? ( ' [', @_, ']' ) : () ) );
1380 0 ▶ $self->{ 'skip_print_' . $_ } = 0 for keys %{ $self->{'no_print'} || {} };
Condition0%0/2
$self->{'no_print'} || {}
l!l
00
MC/DC0%0/1
$self->{'no_print'} || {}
$self->{'no_print'}
Truth table0%0/2
A
A= $self->{'no_print'}
Aresult
11
00
1381 } else {
1382 ++$self->{ 'skip_print_' . $cmd },
1383 0 ▶ if exists $self->{'no_print'}{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"no_print"}{$cmd} 0 0 0
1384 }
1385 #$self->handler( @self, $cmd . '_parse_bef', @param );
1386 0 @ret = $self->{'parse'}{$cmd}->( @self, @param );
1387 0 ▶ $ret = scalar @ret > 1 ? \@ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret > 1 ? : 0 0 0
1388 #$self->handler( @self, $cmd . '_parse_aft', @param, $ret );
1389 0 ++$self->{'count_parse'}{$cmd};
1390 } else {
1391 #$self->log( 'dcinf', "unknown", $cmd, @_ ,'with',$self->{'parse'}{$cmd}, ref $self->{'parse'}{$cmd}, 'run=', @self, 'unknown', $cmd,@param,);
1392 0 $self->handler( @self, 'unknown', $cmd, @param, );
1393 }
1394 #if ($self->{'parent'}{'hub'}) { }
1395 0 $self->handler( @self, $cmd, @param, $ret );
1396 #$self->handler( @self, $cmd . '_parse_aft_aft', @param, $ret );
1397 }
1398 }
1399  
1400 0 ▶sub send_can { #$self->{'send'} ||= sub {
Subroutine send_can: not called CC=5 SCAR=34.0
Pod undocumented
1401 0 my $self = shift;
1402 #$self->log( 'dev', 'send_can');
1403 0 my $size;
1404 0 my $send = $self->{send};
1405 0 ▶ eval { $size += $self->{'socket'}->$send($_) for @_ ? @_ : @{ $self->{send_buffer_raw} }; } if $self->{'socket'};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"socket"} 0 0 0
@_ ? : 0 0 0
1406 0 $self->{send_buffer_raw} = [];
1407 0 $self->{bytes_send} += $size;
1408 0 ▶ $self->log( 'err', 'send error', $@ ), $self->reconnect(), return $size if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1409 0 $self->{activity} = time;
1410 0 return $size;
1411 }
1412  
1413 0 ▶sub send { #$self->{'send'} ||= sub {
Subroutine send: not called CC=3 SCAR=24.8
Pod undocumented
1414 0 my $self = shift;
1415 0 ▶ return if $self->{'listener'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"listener"} 0 0 0
1416 # = join( '', @_ );
1417 #$self->{bytes_send} += length $_;
1418 #eval { $_ = $self->{'socket'}->send( join( '', @_ ) ); } if $self->{'socket'};
1419 0 ▶ push @{ $self->{send_buffer_raw} ||= [] }, @_;
Condition0%0/2
$self->{"send_buffer_raw"} ||= []
l!l
00
MC/DC0%0/1
$self->{"send_buffer_raw"} ||= []
$self->{"send_buffer_raw"}
Truth table0%0/2
A
A= $self->{"send_buffer_raw"}
Aresult
11
00
1420 0 $self->select();
1421  
1422 =no
1423 unless ($self->{send_can}) {
1424 $self->{send_buffer_raw} = \@_;
1425 return 0;
1426 }
1427 if ($self->{send_buffer_raw}) {
1428 unshift @_, @{$self->{send_buffer_raw}};
1429 $self->{send_buffer_raw} = undef;
1430 }
1431 =cut
1432  
1433 #return unless @_;
1434 }
1435  
1436 0 ▶sub sendcmd { #$self->{'sendcmd'} ||= sub {
Subroutine sendcmd: not called CC=13 SCAR=52.0
Pod undocumented
1437 0 my $self = shift;
1438 0 ▶ return if $self->connect_check();
Branch: 1 branch
BranchTrueFalseTotal
if $self->connect_check 0 0 0
1439 0 ▶ return if $self->{'listener'} and !$self->{'broadcast'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"listener"} and not $self->{"broadcast"} 0 0 0
Condition0%0/3
$self->{"listener"} and not $self->{"broadcast"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"listener"} and not $self->{"broadcast"}
$self->{"listener"} not $self->{"broadcast"}
Truth table0%0/3
A and not(B)
A= $self->{"listener"}B= not $self->{"broadcast"}
ABresult
0X0
100
111
1440 #$self->{'log'}->( $self,'sendcmd0', @_);
1441 local @_ = @_, $_[0] .= splice @_, 1, 1
1442 0 ▶ if $self->{'adc'} and length $_[0] == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"adc"} and length $_[0] == 1 0 0 0
Condition0%0/3
$self->{"adc"} and length $_[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"adc"} and length $_[0] == 1
$self->{"adc"} length $_[0] == 1
Truth table0%0/3
A and B
A= $self->{"adc"}B= length $_[0] == 1
ABresult
0X0
100
111
1443 0 $self->log( 'dcdmp', 'sendcmd', $self->{number}, ':', @_ );
1444 0 ▶ push @{ $self->{'send_buffer'} }, $self->{'cmd_bef'} . join( $self->{'cmd_sep'}, @_ ) . $self->{'cmd_aft'}
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1445 if @_;
1446 0 ++$self->{'count_sendcmd'}{ $_[0] };
1447 0 ▶ if ( ( $self->{'sendbuf'} and @_ )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'sendbuf'} and @_ or not @{$self->{'send_buffer'} or [];}) { } 0 0 0
Condition0%0/6
$self->{"sendbuf"} and @_ or not @{$self->{"send_buffer"} or [];}
l!l&&r!l&&!r
000
$self->{"sendbuf"} and @_
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"sendbuf"} and @_ or not @{$self->{"send_buffer"} or [];}
$self->{"sendbuf"} @_ not @{$self->{"send_buffer"} or [];}
Truth table0%0/5
A and B or not(C)
A= $self->{"sendbuf"}B= @_C= not @{$self->{"send_buffer"} or [];}
ABCresult
11X1
0X11
1011
0X00
1000
1448 0 ▶ or !@{ $self->{'send_buffer'} || [] } )
Condition0%0/2
$self->{'send_buffer'} || []
l!l
00
MC/DC0%0/1
$self->{'send_buffer'} || []
$self->{'send_buffer'}
Truth table0%0/2
A
A= $self->{'send_buffer'}
Aresult
11
00
1449 {
1450 } else {
1451 0 ▶ if ( $self->{'broadcast'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'broadcast'}) { } 0 0 0
1452 0 $self->send_udp( $self->{'host'}, $self->{'port'}, join( '', @{ $self->{'send_buffer'} }, ) ),;
1453 } else {
1454 $self->log( 'err', "ERROR! no socket to send" ), return
1455 0 ▶ unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
1456 0 $self->send( Encode::encode $self->{charset_protocol}, join( '', @{ $self->{'send_buffer'} }, ), Encode::FB_WARN );
1457 #local $_;
1458 #eval { $_ = $self->{'socket'}->send( join( '', @{ $self->{'send_buffer'} }, ) ); };
1459 #$self->log( 'err', 'send error', $@ ) if $@;
1460 }
1461 #$self->log( 'dcdmp', "we send [" . join( '', @{ $self->{'send_buffer'} } ) . "]:", $! );
1462 0 $self->{'send_buffer'} = [];
1463 0 $self->{'sendbuf'} = 0;
1464 }
1465 }
1466  
1467 0 ▶sub sendcmd_all { #$self->{'sendcmd_all'} ||= sub {
Subroutine sendcmd_all: not called CC=2 SCAR=17.9
Pod undocumented
1468 0 my $self = shift;
1469 #%{ $self->{'peers_sid'} }
1470 #eval {
1471 $_->sendcmd(@_) #, $self->wait_sleep( $self->{'cmd_recurse_sleep'} )
1472 0 for grep { $_ } values( %{ $self->{'clients'} } ); #, $self;
1473 }
1474  
1475 0 ▶sub rcmd { #$self->{'rcmd'} ||= sub {
Subroutine rcmd: not called CC=2 SCAR=17.9
Pod undocumented
1476 0 my $self = shift;
1477 0 eval {
1478 0 eval { $_->cmd(@_) }, $self->wait( $self->{'cmd_recurse_sleep'} )
1479 0 for grep { $_ } values( %{ $self->{'clients'} } ), $self;
1480 };
1481 }
1482  
1483 0 ▶sub get { #$self->{'get'} ||= sub {
Subroutine get: not called CC=26 SCAR=65.5
Pod undocumented
1484 0 my ( $self, $nick, $file, $as, $from, $to, $size, $tth ) = @_; #TODO hash
1485 #$self->log( 'dcdev', 'wantcall', $self, $nick, $file, $as, $from, $to, $size);
1486 #my $size;
1487 #$size = $to unless $from;
1488 #$from, $to
1489 0 my ( $sid, $cid );
1490 0 ▶ $sid = $nick if $nick =~ /^[A-Z0-9]{4}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $nick =~ /^[A-Z0-9]{4}$/ 0 0 0
1491 0 ▶ $cid = $nick if $nick =~ /^[A-Z0-9]{39}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $nick =~ /^[A-Z0-9]{39}$/ 0 0 0
1492 0 ▶ $cid ||= $self->{peers}{$sid}{INF}{ID};
Condition0%0/3
$cid ||= $self->{"peers"}{$sid}{"INF"}{"ID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$cid ||= $self->{"peers"}{$sid}{"INF"}{"ID"}
$cid $self->{"peers"}{$sid}{"INF"}{"ID"}
Truth table0%0/3
A ||= B
A= $cidB= $self->{"peers"}{$sid}{"INF"}{"ID"}
ABresult
1X1
011
000
1493 0 ▶ $sid ||= $self->{peers}{$cid}{SID};
Condition0%0/3
$sid ||= $self->{"peers"}{$cid}{"SID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sid ||= $self->{"peers"}{$cid}{"SID"}
$sid $self->{"peers"}{$cid}{"SID"}
Truth table0%0/3
A ||= B
A= $sidB= $self->{"peers"}{$cid}{"SID"}
ABresult
1X1
011
000
1494 0 ▶ $sid ||= $cid if $self->{broadcast};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"broadcast"} 0 0 0
Condition0%0/3
$sid ||= $cid
l!l&&r!l&&!r
000
MC/DC0%0/2
$sid ||= $cid
$sid $cid
Truth table0%0/3
A ||= B
A= $sidB= $cid
ABresult
1X1
011
000
1495 0 ▶ $file //= 'TTH/' . $tth if $tth;
Branch: 1 branch
BranchTrueFalseTotal
if $tth 0 0 0
Condition0%0/2
$file //= 'TTH/' . $tth
l!l
00
MC/DC0%0/1
$file //= 'TTH/' . $tth
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
1496 0 ▶ my $full = ( $as || $file );
Condition0%0/3
$as || $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$as || $file
$as $file
Truth table0%0/3
A || B
A= $asB= $file
ABresult
1X1
011
000
1497 0 ▶ $full = $self->{'download_to'} . $full unless $full =~ m{[/\\]};
Branch: 1 branch
BranchTrueFalseTotal
unless $full =~ m([/\\]) 0 0 0
1498 #$self->log( 'dev', "cid[$cid] sid[$sid] nick[$nick] full[$full] as,file[$as || $file]");
1499 0 my $sizenow = -s $full;
1500 0 ▶ if ($sizenow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sizenow) 0 0 0
1501 0 $self->log( 'info', "file [$_] already exists size=$sizenow must be=$size" );
1502 0 return;
1503 #return if $size and $size == $sizenow;
1504 #$from = $sizenow if $sizenow < $size;
1505 }
1506 #$to ||= $size - $from;
1507 #todo by nick
1508 0 $self->wait_clients();
1509 #$self->{'want'}{ $self->{peers}{$cid}{'INF'}{'ID'} || $nick }{$file} = $as || $file || '';
1510 #$self->log( 'dcdev', "wantid: $self->{peers}{$cid}{'INF'}{'ID'} || $self->{peers}{$sid}{'INF'}{'ID'} || $nick");
1511 0 ▶ $self->{'want'}{ $self->{peers}{$cid}{'INF'}{'ID'} || $self->{peers}{$sid}{'INF'}{'ID'} || $nick }{$file} = {
Condition0%0/11
$as || $file || ''
l!l
00
$as or $file
l!l&&r!l&&!r
000
$self->{'peers'}{$cid}{'INF'}{'ID'} || $self->{'peers'}{$sid}{'INF'}{'ID'} || $nick
l!l&&r!l&&!r
000
$self->{"peers"}{$cid}{"INF"}{"ID"} or $self->{"peers"}{$sid}{"INF"}{"ID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$as || $file || ''
$as $file
MC/DC0%0/3
$self->{'peers'}{$cid}{'INF'}{'ID'} || $self->{'peers'}{$sid}{'INF'}{'ID'} || $nick
$self->{"peers"}{$cid}{"INF"}{"ID"} $self->{"peers"}{$sid}{"INF"}{"ID"} $nick
Truth table0%0/3
A or B
A= $asB= $file
ABresult
1X1
011
000
Truth table0%0/4
A or B || C
A= $self->{"peers"}{$cid}{"INF"}{"ID"}B= $self->{"peers"}{$sid}{"INF"}{"ID"}C= $nick
ABCresult
1XX1
01X1
0011
0000
1512 'filename' => $file,
1513 'fileas' => $as || $file || '',
1514 'file_recv_to' => $to,
1515 'file_recv_from' => $from,
1516 'file_recv_size' => $size,
1517 'file_recv_tth' => $tth,
1518 #'file_recv_full' => $full
1519 };
1520 my $peer =
1521 $self->{peers}{$cid}
1522 || $self->{peers}{$sid}
1523 0 ▶ || $self->{peers}{$nick}
Condition0%0/8
$self->{'peers'}{$cid} || $self->{'peers'}{$sid} || $self->{'peers'}{$nick} || {}
l!l
00
$self->{"peers"}{$cid} or $self->{"peers"}{$sid} or $self->{"peers"}{$nick}
l!l&&r!l&&!r
000
$self->{"peers"}{$cid} or $self->{"peers"}{$sid}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{'peers'}{$cid} || $self->{'peers'}{$sid} || $self->{'peers'}{$nick} || {}
$self->{"peers"}{$cid} $self->{"peers"}{$sid} $self->{"peers"}{$nick}
Truth table0%0/4
A or B or C
A= $self->{"peers"}{$cid}B= $self->{"peers"}{$sid}C= $self->{"peers"}{$nick}
ABCresult
1XX1
01X1
0011
0000
1524 || {};
1525 0 $self->log( 'dbg', "getting [$nick] $file as $as sid=[$sid]:$self->{'myport'} p=$self->{'protocol_connect'}" ); #, Dumper $peer->{INF});
1526 0 ▶ if ( $self->{'adc'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'adc'}) { } 0 0 0
1527 #my $token = $self->make_token($nick);
1528 0 local @_;
1529 0 ▶ if ( $self->{'M'} eq 'A'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'M'} eq 'A' and $self->{'myip'} and not $self->{'passive_get'}) { } 0 0 0
Condition0%0/6
$self->{"M"} eq "A" and $self->{"myip"} and not $self->{"passive_get"}
!ll&&!rl&&r
000
$self->{"M"} eq "A" and $self->{"myip"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"M"} eq "A" and $self->{"myip"} and not $self->{"passive_get"}
$self->{"M"} eq "A" $self->{"myip"} not $self->{"passive_get"}
Truth table0%0/4
A and B and not(C)
A= $self->{"M"} eq "A"B= $self->{"myip"}C= not $self->{"passive_get"}
ABCresult
0XX0
10X0
1100
1111
1530 and $self->{'myip'}
1531 and !$self->{'passive_get'} )
1532 {
1533 0 @_ = ( 'CTM', $sid, $self->{'protocol_connect'}, $self->{'myport'}, $self->make_token($nick) );
1534 } else {
1535 0 @_ = ( 'RCM', $sid, $self->{'protocol_connect'}, $self->make_token($nick) );
1536 }
1537 0 $self->cmd( 'D', @_ );
1538 #$self->cmd( $dst, 'CTM', $peerid, $_[0], $self->{'myport'}, $_[1], )
1539 } else {
1540 0 ▶ $self->cmd( ( ( $self->{'M'} eq 'A' and $self->{'myip'} and !$self->{'passive_get'} ) ? '' : 'Rev' ) . 'ConnectToMe',
Branch: 1 branch
BranchTrueFalseTotal
$self->{'M'} eq 'A' && $self->{'myip'} && !$self->{'passive_get'} ? : 0 0 0
Condition0%0/6
$self->{"M"} eq "A" and $self->{"myip"} and not $self->{"passive_get"}
!ll&&!rl&&r
000
$self->{"M"} eq "A" and $self->{"myip"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"M"} eq "A" and $self->{"myip"} and not $self->{"passive_get"}
$self->{"M"} eq "A" $self->{"myip"} not $self->{"passive_get"}
Truth table0%0/4
A and B and not(C)
A= $self->{"M"} eq "A"B= $self->{"myip"}C= not $self->{"passive_get"}
ABCresult
0XX0
10X0
1100
1111
1541 $nick );
1542 }
1543 }
1544  
1545 0 ▶sub file_select { #$self->{'file_select'} ||= sub {
Subroutine file_select: not called CC=22 SCAR=62.3
Pod undocumented
1546 0 my $self = shift;
1547 0 ▶ return if length $self->{'filename'};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"filename"} 0 0 0
1548 0 ▶ my $peerid = $self->{'peerid'} || $self->{'peernick'};
Condition0%0/3
$self->{'peerid'} || $self->{'peernick'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'peerid'} || $self->{'peernick'}
$self->{'peerid'} $self->{'peernick'}
Truth table0%0/3
A || B
A= $self->{'peerid'}B= $self->{'peernick'}
ABresult
1X1
011
000
1549 #$self->log( 'dcdev','file_select000',$peerid, $self->{'filename'}, $self->{'fileas'}, Dumper $self->{'want'});
1550 0 for my $file ( keys %{ $self->{'want'}{$peerid} } ) {
1551 #( $self->{'filename'}, $self->{'fileas'} ) = ( $_, $self->{'want'}{$peerid}{$_} );
1552 0 $self->{$_} = $self->{'want'}{$peerid}{$file}{$_} for keys %{ $self->{'want'}{$peerid}{$file} };
1553 #$self->log( 'dcdev', 'file_select1', $self->{'filename'}, $self->{'fileas'} );
1554 0 ▶ next unless defined $self->{'filename'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"filename"} 0 0 0
1555 0 $self->{'filecurrent'} = $self->{'filename'};
1556 #delete $self->{'want'}{ $peerid }{$_} ; $self->{'filecurrent'}
1557 #$self->{'file_recv_from'}
1558 #$self->{'fileas'}
1559 0 last;
1560 }
1561 0 delete $self->{'downloading'}{ $self->{'file_recv_tth'} }{connect_start};
1562 #$self->log( 'dcdev', 'file_select2', $self->{'filename'}, $self->{'fileas'} );
1563 0 ▶ return unless defined $self->{'filename'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"filename"} 0 0 0
1564 0 ▶ unless ( $self->{'filename'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"filename"}) 0 0 0
1565 0 ▶ if ( $self->{'peers'}{$peerid}{'SUP'}{'BZIP'}
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'peers'}{$peerid}{'SUP'}{'BZIP'} or $self->{'NickList'}{$peerid}{'XmlBZList'}) { } 0 0 0
elsif ($self->{'adc'}) { } 0 0 0
elsif ($self->{'NickList'}{$peerid}{'BZList'}) { } 0 0 0
Condition0%0/3
$self->{"peers"}{$peerid}{"SUP"}{"BZIP"} or $self->{"NickList"}{$peerid}{"XmlBZList"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"peers"}{$peerid}{"SUP"}{"BZIP"} or $self->{"NickList"}{$peerid}{"XmlBZList"}
$self->{"peers"}{$peerid}{"SUP"}{"BZIP"} $self->{"NickList"}{$peerid}{"XmlBZList"}
Truth table0%0/3
A or B
A= $self->{"peers"}{$peerid}{"SUP"}{"BZIP"}B= $self->{"NickList"}{$peerid}{"XmlBZList"}
ABresult
1X1
011
000
1566 or $self->{'NickList'}->{$peerid}{'XmlBZList'} )
1567 {
1568 0 $self->{'fileext'} = '.xml.bz2';
1569 0 $self->{'filename'} = 'files' . $self->{'fileext'};
1570 } elsif ( $self->{'adc'} ) {
1571 0 $self->{'fileext'} = '.xml';
1572 0 $self->{'filename'} = 'files' . $self->{'fileext'};
1573 } elsif ( $self->{'NickList'}->{$peerid}{'BZList'} ) {
1574 0 $self->{'fileext'} = '.bz2';
1575 0 $self->{'filename'} = 'MyList' . $self->{'fileext'};
1576 } else {
1577 0 $self->{'fileext'} = '.DcLst';
1578 0 $self->{'filename'} = 'MyList' . $self->{'fileext'};
1579 }
1580 0 ▶ $self->{'fileas'} .= $self->{'fileext'} if $self->{'fileas'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fileas"} 0 0 0
1581 0 $self->{'file_recv_filelist'} = 1;
1582 }
1583 0 ▶ $self->{'file_recv_dest'} = ( $self->{'fileas'} || $self->{'filename'} );
Condition0%0/3
$self->{'fileas'} || $self->{'filename'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'fileas'} || $self->{'filename'}
$self->{'fileas'} $self->{'filename'}
Truth table0%0/3
A || B
A= $self->{'fileas'}B= $self->{'filename'}
ABresult
1X1
011
000
1584 0 $self->{'file_recv_full'} = $self->{'file_recv_dest'};
1585 $self->{'file_recv_full'} = $self->{'download_to'} . $self->{'file_recv_full'}
1586 0 ▶ unless $self->{'file_recv_full'} =~ m{[/\\]};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"file_recv_full"} =~ m([/\\]) 0 0 0
1587 #$self->log('dcdev', '1full', $self->{'file_recv_full'});
1588 #$self->{'file_recv_dest'} = Encode::encode $self->{charset_fs}, $self->{'file_recv_dest'} if $self->{charset_fs}; # ne $self->{charset_protocol};
1589 #$self->{'file_recv_dest'}
1590 #$self->log( 'dcdev', "pre enc filename [$self->{'file_recv_dest'}] [$self->{charset_fs} ne $self->{charset_protocol}]");
1591 #$self->{'file_recv_dest'} = Encode::encode $self->{charset_fs}, Encode::decode $self->{charset_protocol},
1592 #$self->log( 'dcdev', "pst enc filename [$self->{'file_recv_dest'}]");
1593 0 ▶ mkdir_rec $self->{'partial_prefix'} if $self->{'partial_prefix'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"partial_prefix"} 0 0 0
1594 $self->{'file_recv_partial'} =
1595 0 ▶ "$self->{'file_recv_dest'}" . ( $self->{'file_recv_tth'} ? '.' . $self->{'file_recv_tth'} : () ) . "$self->{'partial_ext'}";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'file_recv_tth'} ? : 0 0 0
1596 $self->{'file_recv_partial'} = $self->{'partial_prefix'} . $self->{'file_recv_partial'}
1597 0 ▶ unless $self->{'file_recv_partial'} =~ m{[/\\]};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"file_recv_partial"} =~ m([/\\]) 0 0 0
1598 $self->{'file_recv_partial'} = Encode::encode $self->{charset_fs}, $self->{'file_recv_partial'}, Encode::FB_WARN
1599 0 ▶ if $self->{charset_fs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
1600 0 $self->{'filebytes'} = $self->{'file_recv_from'} = -s $self->{'file_recv_partial'};
1601 $self->{'file_recv_to'} ||= $self->{'file_recv_size'} - $self->{'file_recv_from'}
1602 0 ▶ if $self->{'file_recv_size'} and $self->{'file_recv_from'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"file_recv_size"} and $self->{"file_recv_from"} 0 0 0
Condition0%0/6
$self->{"file_recv_size"} and $self->{"file_recv_from"}
!ll&&!rl&&r
000
$self->{"file_recv_to"} ||= $self->{"file_recv_size"} - $self->{"file_recv_from"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"file_recv_size"} and $self->{"file_recv_from"}
$self->{"file_recv_size"} $self->{"file_recv_from"}
MC/DC0%0/2
$self->{"file_recv_to"} ||= $self->{"file_recv_size"} - $self->{"file_recv_from"}
$self->{"file_recv_to"} $self->{"file_recv_size"} - $self->{"file_recv_from"}
Truth table0%0/3
A and B
A= $self->{"file_recv_size"}B= $self->{"file_recv_from"}
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $self->{"file_recv_to"}B= $self->{"file_recv_size"} - $self->{"file_recv_from"}
ABresult
1X1
011
000
1603 #$self->log('dcdev', '1part', $self->{'file_recv_partial'});
1604 #$self->log('dcdev', 'file_select3', $self->{'filename'}, $self->{'fileas'},
1605 # 'part:', $self->{'file_recv_partial'}, 'full:', $self->{'file_recv_full'},
1606 # 'from', $self->{'file_recv_from'});
1607 }
1608  
1609 0 ▶sub file_open { #$self->{'file_open'} ||= sub {
Subroutine file_open: not called CC=3 SCAR=24.8
Pod undocumented
1610 0 my $self = shift;
1611 #$self->{'fileas'}=$_[0] if !length $self->{'fileas'} or length $_[0];
1612 #$self->{'filetotal'} = $_[1]if ! $self->{'filetotal'} or $_[1];
1613 #$self->{'filetotal'} //= $self->{'file_recv_size'}
1614 #$self->log('dcdev', '2part', $self->{'file_recv_partial'});
1615 0 ▶ my $oparam = $self->{'fileas'} eq '-' ? '>-' : '>>' . $self->{'file_recv_partial'};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'fileas'} eq '-' ? : 0 0 0
1616 0 $self->handler( 'file_open_bef', $oparam );
1617 # $self->log( 'dbg', "file_open pre", $oparam, 'want bytes', $self->{'filetotal'}, 'as=', $self->{'fileas'}, 'f=', $self->{'filename'} );
1618 #$self->log( 'dcdev', "open [$oparam]" );
1619 0 ▶ open( $self->{'filehandle'}, $oparam )
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"filehandle"}, $oparam or $self->log("dcerr", "file_open error", $!, $oparam), $self->handler("file_open_error", $!, $oparam), (return 1) 0 0 0
1620 or $self->log( 'dcerr', "file_open error", $!, $oparam ),
1621 $self->handler( 'file_open_error', $!, $oparam ), return 1;
1622 0 binmode( $self->{'filehandle'} );
1623 0 $self->{'status'} = 'transfer';
1624 0 return 0;
1625 }
1626  
1627 0 ▶sub file_write { #$self->{'file_write'} ||= sub {
Subroutine file_write: not called CC=8 SCAR=42.8
Pod undocumented
1628 0 my $self = shift;
1629 0 ▶ $self->{'file_start_time'} ||= time;
Condition0%0/3
$self->{"file_start_time"} ||= &Net::DirectConnect::time()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"file_start_time"} ||= &Net::DirectConnect::time()
$self->{"file_start_time"} &Net::DirectConnect::time()
Truth table0%0/3
A ||= B
A= $self->{"file_start_time"}B= &Net::DirectConnect::time()
ABresult
1X1
011
000
1630 0 ▶ my $fh = $self->{'filehandle'}
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->{"filehandle"} or $self->log("err", "cant write, no filehandle"), return 0 0 0
1631 or $self->log( 'err', 'cant write, no filehandle' ), return;
1632 0 for my $databuf (@_) {
1633 0 $self->{'filebytes'} += length $$databuf;
1634 #$self->log( 'dcdbg', "($self->{'number'}) recv ".length($$databuf)." [$self->{'filebytes'}] of $self->{'filetotal'} file $self->{'filename'}" );
1635 #$self->log( 'dcdbg', "recv " . length($$databuf) . " [$$databuf]" ) if length $$databuf < 10;
1636 0 print $fh $$databuf;
1637 schedule(
1638 10,
1639 0 ▶ $self->{__stat_recv} ||= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1640 0 my $self = shift;
1641 0 my $recv = shift;
1642 #my $read = shift;
1643 #our ( $lastmark, $lasttime );
1644 $self->log(
1645 'dev', "recv bytes", #length $self->{'file_send_buf'},
1646 "recv=[$recv] now [", $self->{'filebytes'},
1647 "] of [$self->{'filetotal'}], now", 's=',
1648 int( ( $self->{'filebytes'} - $self->{__stat_recv_lastmark} ) /
1649 ( time - $self->{__stat_recv_lasttime} or 1 ) ),
1650 "status=[$self->{'status'}]",
1651 ),
1652 0 ▶ $self->{__stat_recv_lastmark} = $self->{'filebytes'};
Condition0%0/2
&Net::DirectConnect::time() - $self->{'__stat_recv_lasttime'} || 1
l!l
00
MC/DC0%0/1
&Net::DirectConnect::time() - $self->{'__stat_recv_lasttime'} || 1
&Net::DirectConnect::time() - $self->{'__stat_recv_lasttime'}
Truth table0%0/2
A
A= &Net::DirectConnect::time() - $self->{'__stat_recv_lasttime'}
Aresult
11
00
1653 0 $self->{__stat_recv_lasttime} = time;
1654 #if time - $lasttime > 1;
1655 },
1656 0 ▶ $self,
Condition0%0/3
$self->{"__stat_recv"} ||= sub { my $self = shift(); my $recv = shift(); $self->log("dev", "recv bytes", "recv=[$recv] now [", $self->{"filebytes"}, qq(] of [$self->{"filetotal"}], now), "s=", int(($self->{"filebytes"} - $self->{"__stat_recv_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_recv_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_recv_lastmark"} = $self->{"filebytes"}; $self->{"__stat_recv_lasttime"} = &Net::DirectConnect::time(); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"__stat_recv"} ||= sub { my $self = shift(); my $recv = shift(); $self->log("dev", "recv bytes", "recv=[$recv] now [", $self->{"filebytes"}, qq(] of [$self->{"filetotal"}], now), "s=", int(($self->{"filebytes"} - $self->{"__stat_recv_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_recv_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_recv_lastmark"} = $self->{"filebytes"}; $self->{"__stat_recv_lasttime"} = &Net::DirectConnect::time(); }
$self->{"__stat_recv"} sub { my $self = shift(); my $recv = shift(); $self->log("dev", "recv bytes", "recv=[$recv] now [", $self->{"filebytes"}, qq(] of [$self->{"filetotal"}], now), "s=", int(($self->{"filebytes"} - $self->{"__stat_recv_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_recv_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_recv_lastmark"} = $self->{"filebytes"}; $self->{"__stat_recv_lasttime"} = &Net::DirectConnect::time(); }
Truth table0%0/3
A ||= B
A= $self->{"__stat_recv"}B= sub { my $self = shift(); my $recv = shift(); $self->log("dev", "recv bytes", "recv=[$recv] now [", $self->{"filebytes"}, qq(] of [$self->{"filetotal"}], now), "s=", int(($self->{"filebytes"} - $self->{"__stat_recv_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_recv_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_recv_lastmark"} = $self->{"filebytes"}; $self->{"__stat_recv_lasttime"} = &Net::DirectConnect::time(); }
ABresult
1X1
011
000
1657 length $$databuf,
1658 );
1659 $self->log( 'err', "file download error! extra bytes ($self->{'filebytes'}/$self->{'filetotal'}) " )
1660 0 ▶ if $self->{'filebytes'} > $self->{'filetotal'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filebytes"} > $self->{"filetotal"} 0 0 0
1661 $self->log(
1662 'info',
1663 "file complete ($self->{'filebytes'}) per",
1664 $self->float( time - $self->{'file_start_time'} ),
1665 's at', $self->float( $self->{'filebytes'} / ( ( time - $self->{'file_start_time'} ) or 1 ) ), 'b/s'
1666 ),
1667 #$self->disconnect(), $self->{'status'} = 'destroy',
1668 $self->file_close(),
1669 $self->{'file_start_time'} = 0, $self->{'filename'} = '',
1670 $self->{'fileas'} = '',
1671 delete $self->{'want'}{ $self->{'peerid'} }{ $self->{'filecurrent'} },
1672 $self->{'filecurrent'} = '', $self->{'file_recv_partial'} = '',
1673 $self->{'file_recv_from'} = $self->{'file_recv_to'} = undef,
1674 #!!?$self->destroy(),
1675 0 ▶ if $self->{'filebytes'} >= $self->{'filetotal'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filebytes"} >= $self->{"filetotal"} 0 0 0
Condition0%0/2
&Net::DirectConnect::time() - $self->{'file_start_time'} || 1
l!l
00
MC/DC0%0/1
&Net::DirectConnect::time() - $self->{'file_start_time'} || 1
&Net::DirectConnect::time() - $self->{'file_start_time'}
Truth table0%0/2
A
A= &Net::DirectConnect::time() - $self->{'file_start_time'}
Aresult
11
00
1676 }
1677 }
1678  
1679 0 ▶sub file_close { #$self->{'file_close'} ||= sub {
Subroutine file_close: not called CC=15 SCAR=54.8
Pod undocumented
1680 0 my $self = shift;
1681 #$self->log( 'dcerr', 'file_close', 1);
1682 0 ▶ if ( $self->{'filehandle'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"filehandle"}) 0 0 0
1683 #$self->log( 'dcerr', 'file_close',2);
1684 0 close( $self->{'filehandle'} ), delete $self->{'filehandle'};
1685 0 ▶ if ( $self->{'filebytes'} == $self->{'filetotal'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"filebytes"} == $self->{"filetotal"}) 0 0 0
1686 0 ▶ mkdir_rec $self->{'download_to'} if $self->{'download_to'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"download_to"} 0 0 0
1687 0 ▶ if ( length $self->{'partial_ext'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"partial_ext"}) 0 0 0
1688 local $self->{'file_recv_full'} = Encode::encode $self->{charset_fs}, $self->{'file_recv_full'}, Encode::FB_WARN
1689 0 ▶ if $self->{charset_fs}; # ne $self->{charset_protocol};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
1690 #$self->log( 'dcdev', 'file_close', 3, $self->{'file_recv_partial'}, $self->{'file_recv_full'} );
1691 $self->log( 'dcerr', 'cant move finished file', $self->{'file_recv_partial'}, '=>', $self->{'file_recv_full'} )
1692 0 ▶ if !rename $self->{'file_recv_partial'}, $self->{'file_recv_full'};
Branch: 1 branch
BranchTrueFalseTotal
unless rename $self->{"file_recv_partial"}, $self->{"file_recv_full"} 0 0 0
1693 }
1694 0 delete $self->{'downloading'}{ $self->{'file_recv_tth'} };
1695 0 ▶ ( $self->{parent} || $self )->handler( 'file_recieved', $self->{'file_recv_full'}, $self->{'filename'} );
Condition0%0/3
$self->{'parent'} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'parent'} || $self
$self->{'parent'} $self
Truth table0%0/3
A || B
A= $self->{'parent'}B= $self
ABresult
1X1
011
000
1696 }
1697 }
1698 0 ▶ if ( $self->{'downloading'}{ $self->{'file_recv_tth'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"downloading"}{$self->{"file_recv_tth"}}) 0 0 0
1699 #$self->log( 'dev', "onclose: downloading [$self->{'file_recv_tth'}], b$self->{'filebytes'} <= t$self->{'filetotal'} || $self->{'file_recv_size'}" );
1700 0 ▶ if ( $self->{'filebytes'} <= $self->{'filetotal'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"filebytes"} <= $self->{"filetotal"} or $self->{"file_recv_size"}) 0 0 0
Condition0%0/3
$self->{"filebytes"} <= $self->{"filetotal"} or $self->{"file_recv_size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"filebytes"} <= $self->{"filetotal"} or $self->{"file_recv_size"}
$self->{"filebytes"} <= $self->{"filetotal"} $self->{"file_recv_size"}
Truth table0%0/3
A or B
A= $self->{"filebytes"} <= $self->{"filetotal"}B= $self->{"file_recv_size"}
ABresult
1X1
011
000
1701 || $self->{'file_recv_size'} )
1702 {
1703 0 $self->{'want_download'}{ $self->{'file_recv_tth'} } = $self->{'downloading'}{ $self->{'file_recv_tth'} };
1704 } #else { }
1705 0 delete $self->{'downloading'}{ $self->{'file_recv_tth'} };
1706 }
1707 #$self->{'select_send'}->remove( $self->{'socket'} ),
1708 close( $self->{'filehandle_send'} ), delete $self->{'filehandle_send'},
1709 #$self->{'socket'}->flush(),
1710 0 ▶ if $self->{'select_send'} and $self->{'filehandle_send'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"select_send"} and $self->{"filehandle_send"} 0 0 0
Condition0%0/3
$self->{"select_send"} and $self->{"filehandle_send"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"select_send"} and $self->{"filehandle_send"}
$self->{"select_send"} $self->{"filehandle_send"}
Truth table0%0/3
A and B
A= $self->{"select_send"}B= $self->{"filehandle_send"}
ABresult
0X0
100
111
1711 0 delete $self->{$_} for 'file_send_left', 'file_send_total', 'file_recv_filelist';
1712 0 ▶ $self->{'status'} = 'connected' if $self->{'status'} eq 'transfer';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"status"} eq "transfer" 0 0 0
1713 }
1714  
1715 0 ▶sub file_send_tth { #$self->{'file_send_tth'} ||= sub {
Subroutine file_send_tth: not called CC=2 SCAR=17.9
Pod undocumented
1716 0 my $self = shift;
1717 0 my ( $file, $start, $size, $as ) = @_;
1718 #$self->log( 'dcdev', 'my share', $self->{'share_full'}, scalar keys %{$self->{'share_full'} }, 'p share', $self->{'parent'}{'share_full'}, scalar keys %{$self->{'parent'}{'share_full'} }, );
1719 #$self->{'share_tth'} ||=$self->{'parent'}{'share_tth'};
1720 0 ▶ if ( $self->{'share_full'}{$file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'share_full'}{$file}) { } 0 0 0
1721 0 $self->{'share_full'}{$file} =~ tr{\\}{/};
1722 #$self->log( 'dcdev', 'call send', $self->{'share_full'}{$file}, $start, $size, $as );
1723 0 $self->file_send( $self->{'share_full'}{$file}, $start, $size, $as );
1724 0 $self->search_stat_update( $file, 'hit' );
1725 } else {
1726 $self->log(
1727 'dcerr', 'send', 'cant find file',
1728 $file, $self->{'share_full'}{$file},
1729 0 'from', scalar keys %{ $self->{'share_full'} }
1730 );
1731 0 return 1;
1732 }
1733 0 return undef;
1734 }
1735  
1736 0 ▶sub file_send { #$self->{'file_send'} ||= sub {
Subroutine file_send: not called CC=12 SCAR=50.5
Pod undocumented
1737 0 my $self = shift;
1738 #$self->log( 'dcdev', 'file_send', Dumper \@_ );
1739 0 my ( $file, $start, $size, $as ) = @_;
1740 0 ▶ $start //= 0;
Condition0%0/2
$start //= 0
l!l
00
MC/DC0%0/1
$start //= 0
$start
Truth table0%0/2
A
A= $start
Aresult
11
00
1741 0 my $filesize = -s $file;
1742 0 ▶ $size = $filesize - $start if $size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 0 0 0 0
1743 0 ▶ $self->log( 'dcerr', "cant find [$file]" ), $self->disconnect(), return
Branch: 1 branch
BranchTrueFalseTotal
if not -e $file or -d $file 0 0 0
Condition0%0/3
not -e $file or -d $file
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $file or -d $file
not -e $file -d $file
Truth table0%0/3
not(A) or B
A= not -e $fileB= -d $file
ABresult
1X1
011
000
1744 if !-e $file
1745 or -d $file;
1746 0 ▶ if ( open $self->{'filehandle_send'}, '<', $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $self->{'filehandle_send'}, '<', $file) { } 0 0 0
1747 0 binmode( $self->{'filehandle_send'} );
1748 0 ▶ seek( $self->{'filehandle_send'}, $start, SEEK_SET ) if $start;
Branch: 1 branch
BranchTrueFalseTotal
if $start 0 0 0
1749 0 my $name = $file;
1750 0 $name =~ s{^.*[\\/]}{}g;
1751 0 $self->{'file_send_total'} = $filesize;
1752 0 ▶ $self->{'file_send_offset'} = $start || 0;
Condition0%0/2
$start || 0
l!l
00
MC/DC0%0/1
$start || 0
$start
Truth table0%0/2
A
A= $start
Aresult
11
00
1753 0 $self->{'file_send_left'} = $size;
1754 0 $self->log( 'dev', "sendsize=$size filesize=$filesize from", $start, 'e', -e $file, $file, $self->{'file_send_total'} );
1755 #$self->{'filetotal'} = $self->{'file_send_offset'} + $self->{'file_send_left'};
1756 0 ▶ $self->file_close(), return if $start >= $self->{'file_send_total'};
Branch: 1 branch
BranchTrueFalseTotal
if $start >= $self->{"file_send_total"} 0 0 0
1757 0 ▶ if ( $self->{'adc'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'adc'}) { } 0 0 0
1758 0 ▶ $self->cmd( 'C', 'SND', 'file', $as || $name, $start, $size );
Condition0%0/3
$as || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$as || $name
$as $name
Truth table0%0/3
A || B
A= $asB= $name
ABresult
1X1
011
000
1759 } else {
1760 0 ▶ $self->cmd( 'ADCSND', 'file', $as || $name, $start, $size );
Condition0%0/3
$as || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$as || $name
$as $name
Truth table0%0/3
A || B
A= $asB= $name
ABresult
1X1
011
000
1761 }
1762 0 $self->{'status'} = 'transfer';
1763 #$self->file_send_part();
1764 #$self->{'select_send'}->add( $self->{'socket'} );
1765 } else {
1766 0 $self->file_close();
1767 }
1768 }
1769  
1770 0 ▶sub file_send_part { #$self->{'file_send_part'} ||= sub {
Subroutine file_send_part: not called CC=14 SCAR=53.5
Pod undocumented
1771 #psmisc::printlog 'call', 'file_send_part', @_;
1772 0 my $self = shift;
1773 #my ($file, $start, $size) = @_;
1774 #return unless $self->{'file_send_left'};
1775 #my $buf;
1776 #$self->disconnect(),
1777 return
1778 unless ( $self->{'socket'}
1779 and $self->{'socket'}->connected()
1780 and $self->{'filehandle_send'}
1781 0 ▶ and $self->{'file_send_left'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} and $self->{"socket"}->connected and $self->{"filehandle_send"} and $self->{"file_send_left"} 0 0 0
Condition0%0/9
$self->{"socket"} and $self->{"socket"}->connected and $self->{"filehandle_send"} and $self->{"file_send_left"}
!ll&&!rl&&r
000
$self->{"socket"} and $self->{"socket"}->connected and $self->{"filehandle_send"}
!ll&&!rl&&r
000
$self->{"socket"} and $self->{"socket"}->connected
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"socket"} and $self->{"socket"}->connected and $self->{"filehandle_send"} and $self->{"file_send_left"}
$self->{"socket"} $self->{"socket"}->connected $self->{"filehandle_send"} $self->{"file_send_left"}
Truth table0%0/5
A and B and C and D
A= $self->{"socket"}B= $self->{"socket"}->connectedC= $self->{"filehandle_send"}D= $self->{"file_send_left"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1782 0 my $read = $self->{'file_send_left'};
1783 $read = $self->{'file_send_by'}
1784 0 ▶ if $self->{'file_send_by'} < $self->{'file_send_left'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"file_send_by"} < $self->{"file_send_left"} 0 0 0
1785 0 my $sent;
1786 0 ▶ if (0) {
Branch: 2 branches
BranchTrueFalseTotal
if (do { $INC{'Sys/Sendfile.pm'} }) { } 0 0 0
elsif ($INC{'Sys/Sendfile/FreeBSD.pm'}) { } 0 0 0
1787 } elsif ( $INC{'Sys/Sendfile.pm'} ) { #works
1788 #$self->log( 'dev', 'using sys::sendfile ');
1789 0 $sent = Sys::Sendfile::sendfile( $self->{'socket'}, $self->{'filehandle_send'}, $read, $self->{'file_send_offset'} );
1790 0 ▶ $self->{'file_send_offset'} += $sent if $sent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sent > 0 0 0 0
1791 } elsif ( $INC{'Sys/Sendfile/FreeBSD.pm'} ) {
1792 #$self->log( 'dev', 'using sendfile freebsd');
1793 my $result = Sys::Sendfile::FreeBSD::sendfile(
1794 fileno( $self->{'filehandle_send'} ),
1795 fileno( $self->{'socket'} ),
1796 0 $self->{'file_send_offset'},
1797 $read, $sent
1798 );
1799 0 ▶ $self->{'file_send_offset'} += $sent if $sent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sent > 0 0 0 0
1800 #blocking
1801 #elsif ($INC{'IO/AIO.pm'}) {
1802 # $sent = IO::AIO::sendfile( fileno($self->{'socket'}), fileno($self->{'filehandle_send'}),$self->{'file_send_offset'}, $read );
1803 # $self->{'file_send_offset'} += $sent if $sent > 0;
1804 } else {
1805 #$self->log( 'dev', 'using read send');
1806 read( $self->{'filehandle_send'}, $self->{'file_send_buf'}, $read ),
1807 $self->{'file_send_offset'} = tell $self->{'filehandle_send'},
1808 0 ▶ unless length $self->{'file_send_buf'}; #$self->{'file_send_by'};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"file_send_buf"} 0 0 0
1809 #send $self->{'socket'},
1810 #$self->{'socket'}->send( buf, POSIX::BUFSIZ, $self->{'recv_flags'} )
1811 #my $sent;
1812 #$self->log( 'snd', length $self->{'file_send_buf'},
1813 0 $sent = $self->send_can( $self->{'file_send_buf'} );
1814 }
1815 schedule(
1816 10,
1817 0 ▶ $self->{__stat_} ||= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1818 0 my $self = shift;
1819 0 my $sent = shift;
1820 0 my $read = shift;
1821 #our ( $lastmark, $lasttime );
1822 $self->log(
1823 'dev', "sent bytes", #length $self->{'file_send_buf'},
1824 "sent=[$sent] of buf [", length $self->{'file_send_buf'},
1825 "] by [$read:$self->{'file_send_by'}] left $self->{'file_send_left'}, now",
1826 $self->{'file_send_offset'}, 'of',
1827 $self->{'file_send_total'}, 's=',
1828 int( ( $self->{'file_send_offset'} - $self->{__stat_lastmark} ) /
1829 ( time - $self->{__stat_lasttime} or 1 ) ),
1830 "status=[$self->{'status'}]",
1831 ),
1832 0 ▶ $self->{__stat_lastmark} = $self->{'file_send_offset'};
Condition0%0/2
&Net::DirectConnect::time() - $self->{'__stat_lasttime'} || 1
l!l
00
MC/DC0%0/1
&Net::DirectConnect::time() - $self->{'__stat_lasttime'} || 1
&Net::DirectConnect::time() - $self->{'__stat_lasttime'}
Truth table0%0/2
A
A= &Net::DirectConnect::time() - $self->{'__stat_lasttime'}
Aresult
11
00
1833 0 $self->{__stat_lasttime} = time;
1834 #if time - $lasttime > 1;
1835 },
1836 0 ▶ $self,
Condition0%0/3
$self->{"__stat_"} ||= sub { my $self = shift(); my $sent = shift(); my $read = shift(); $self->log("dev", "sent bytes", "sent=[$sent] of buf [", length $self->{"file_send_buf"}, qq(] by [${read}:$self->{"file_send_by"}] left $self->{"file_send_left"}, now), $self->{"file_send_offset"}, "of", $self->{"file_send_total"}, "s=", int(($self->{"file_send_offset"} - $self->{"__stat_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_lastmark"} = $self->{"file_send_offset"}; $self->{"__stat_lasttime"} = &Net::DirectConnect::time(); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"__stat_"} ||= sub { my $self = shift(); my $sent = shift(); my $read = shift(); $self->log("dev", "sent bytes", "sent=[$sent] of buf [", length $self->{"file_send_buf"}, qq(] by [${read}:$self->{"file_send_by"}] left $self->{"file_send_left"}, now), $self->{"file_send_offset"}, "of", $self->{"file_send_total"}, "s=", int(($self->{"file_send_offset"} - $self->{"__stat_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_lastmark"} = $self->{"file_send_offset"}; $self->{"__stat_lasttime"} = &Net::DirectConnect::time(); }
$self->{"__stat_"} sub { my $self = shift(); my $sent = shift(); my $read = shift(); $self->log("dev", "sent bytes", "sent=[$sent] of buf [", length $self->{"file_send_buf"}, qq(] by [${read}:$self->{"file_send_by"}] left $self->{"file_send_left"}, now), $self->{"file_send_offset"}, "of", $self->{"file_send_total"}, "s=", int(($self->{"file_send_offset"} - $self->{"__stat_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_lastmark"} = $self->{"file_send_offset"}; $self->{"__stat_lasttime"} = &Net::DirectConnect::time(); }
Truth table0%0/3
A ||= B
A= $self->{"__stat_"}B= sub { my $self = shift(); my $sent = shift(); my $read = shift(); $self->log("dev", "sent bytes", "sent=[$sent] of buf [", length $self->{"file_send_buf"}, qq(] by [${read}:$self->{"file_send_by"}] left $self->{"file_send_left"}, now), $self->{"file_send_offset"}, "of", $self->{"file_send_total"}, "s=", int(($self->{"file_send_offset"} - $self->{"__stat_lastmark"}) / (&Net::DirectConnect::time() - $self->{"__stat_lasttime"} || 1)), qq[status=[$self->{"status"}]]), $self->{"__stat_lastmark"} = $self->{"file_send_offset"}; $self->{"__stat_lasttime"} = &Net::DirectConnect::time(); }
ABresult
1X1
011
000
1837 $sent,
1838 $read
1839 );
1840 #$self->{activity} = time if $sent;
1841 #$self->{bytes_send} += $sent;
1842 0 $self->{'file_send_left'} -= $sent;
1843 #$self->log( 'dev', 'send end', $sent, $self->{'file_send_offset'}, $self->{'file_send_total'}, "left=[$self->{'file_send_left'}]");
1844 0 substr( $self->{'file_send_buf'}, 0, $sent ) = undef;
1845 #if (length $self->{'file_send_buf'}) { $self->log( 'info', 'sent small', $sent, 'todo', length $self->{'file_send_buf'}); }
1846 #$readed;
1847 0 ▶ if ( $self->{'file_send_left'} < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file_send_left"} < 0) 0 0 0
1848 0 $self->log( 'err', "oversend [$self->{'file_send_left'}]" );
1849 0 $self->{'file_send_left'} = 0;
1850 }
1851 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file_send_left"} <= 0) 0 0 0
1852 #$readed < $self->{'file_send_by'} or
1853 $self->{'file_send_left'} <= 0
1854 )
1855 {
1856 $self->log(
1857 0 'dev', 'file completed', "r:", length $self->{'file_send_buf'},
1858 " by:$self->{'file_send_by'} left:$self->{'file_send_left'} total:$self->{'file_send_total'}",
1859 #caller 2
1860 );
1861 0 $self->file_close();
1862 #$self->{'status'} = 'connected';
1863 #?
1864 #$self->disconnect();
1865 0 $self->destroy();
1866 }
1867 0 return $sent;
1868 }
1869  
1870 0 ▶sub file_send_parse { #$self->{'file_send_parse'} =
Subroutine file_send_parse: not called CC=7 SCAR=40.3
Pod undocumented
1871 #$self->{'ADCSND'} =
1872 #sub {
1873 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1874 #$self->log( 'cmd_adcSND', Dumper \@_);
1875 #my ( $dst, $peerid, $toid ) = @{ shift() };
1876 0 ▶ if ( $_[0] eq 'file' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_[0] eq 'file') { } 0 0 0
elsif ($_[0] eq 'list') { } 0 0 0
elsif ($_[0] eq 'tthl') { } 0 0 0
1877 0 my $file = $_[1];
1878 0 ▶ if ( $file =~ s{^TTH/}{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[^TTH/][]) { } 0 0 0
1879 0 return $self->file_send_tth( $file, $_[2], $_[3], $_[1] );
1880 } else {
1881 #$self->file_send($file, $_[2], $_[3]);
1882 0 return $self->file_send_tth( $file, $_[2], $_[3], $_[1] );
1883 }
1884 } elsif ( $_[0] eq 'list' ) {
1885 0 return $self->file_send_tth( 'files.xml.bz2', );
1886 } elsif ( $_[0] eq 'tthl' ) {
1887 #TODO!! now fake
1888 0 ( my $tth = $_[1] ) =~ s{^TTH/}{};
1889 0 eval q{
1890 use MIME::Base32 qw( RFC );
1891 $tth = MIME::Base32::decode $tth;
1892 };
1893 0 ▶ if ( $self->{'adc'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'adc'}) { } 0 0 0
1894 0 $self->cmd( 'C', 'SND', $_[0], $_[1], $_[2], length $tth );
1895 } else {
1896 0 $self->cmd( 'ADCSND', $_[0], $_[1], $_[2], length $tth );
1897 }
1898 0 $self->send($tth);
1899 } else {
1900 0 $self->log( 'dcerr', 'SND', "unknown type", @_ );
1901 0 return 2;
1902 }
1903 0 return undef;
1904 }
1905  
1906 0 ▶sub download { #$self->{'download'} ||= sub {
Subroutine download: not called CC=4 SCAR=30.0
Pod undocumented
1907 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1908 #my $self = shift;
1909 0 my ($file) = @_;
1910 #$self->log('dev', "0s=[$self]; download [$file] now $self->{'want_download'}{$file} ", Dumper \@_);
1911 0 ▶ push @{ $self->{'queue_download'} ||= [] }, $file;
Condition0%0/2
$self->{"queue_download"} ||= []
l!l
00
MC/DC0%0/1
$self->{"queue_download"} ||= []
$self->{"queue_download"}
Truth table0%0/2
A
A= $self->{"queue_download"}
Aresult
11
00
1912 #$self->log('dev', "1s=[$self]; download [$file] now $self->{'want_download'}{$file} ", Dumper \@_);
1913 0 ▶ $self->{'want_download'}{$file} ||= {};
Condition0%0/2
$self->{"want_download"}{$file} ||= {}
l!l
00
MC/DC0%0/1
$self->{"want_download"}{$file} ||= {}
$self->{"want_download"}{$file}
Truth table0%0/2
A
A= $self->{"want_download"}{$file}
Aresult
11
00
1914 }
1915  
1916 0 ▶sub get_peer_addr { #$self->{'get_peer_addr'} ||= sub () {
Subroutine get_peer_addr: not called CC=4 SCAR=30.0
Pod undocumented
1917 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1918 0 my ($recv) = @_;
1919 0 ▶ return unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
1920 0 eval {
1921 0 $self->{'port'} = $self->{'socket'}->peerport();
1922 0 $self->{'hostip'} = $self->{'socket'}->peerhost();
1923 0 ▶ $self->{'host'} ||= $self->{'hostip'};
Condition0%0/3
$self->{"host"} ||= $self->{"hostip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"host"} ||= $self->{"hostip"}
$self->{"host"} $self->{"hostip"}
Truth table0%0/3
A ||= B
A= $self->{"host"}B= $self->{"hostip"}
ABresult
1X1
011
000
1924 };
1925 0 return $self->{'hostip'};
1926  
1927 =no
1928 local @_ = socket_addr $self->{'socket'};
1929 #eval { @_ = unpack_sockaddr_in( getpeername( $self->{'socket'} ) || return ) };
1930 #return unless $_[1];
1931 #return unless $_[1] = inet_ntoa( $_[1] );
1932 $self->{'port'} = $_[0] if $_[0]; #;and !$self->{'incoming'};
1933 $self->{'hostip'} = $_[1], $self->{'host'} ||= $self->{'hostip'}
1934 if $_[1];
1935 return $self->{'hostip'};
1936 =cut
1937  
1938 }
1939  
1940 0 ▶sub get_peer_addr_recv { #$self->{'get_peer_addr_recv'} ||= sub (;$) {
Subroutine get_peer_addr_recv: not called CC=3 SCAR=24.8
Pod undocumented
1941 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1942 0 my ($recv) = @_;
1943 #return unless $self->{'socket'};
1944 0 ▶ $recv ||= $self->{'recv_addr'};
Condition0%0/3
$recv ||= $self->{"recv_addr"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$recv ||= $self->{"recv_addr"}
$recv $self->{"recv_addr"}
Truth table0%0/3
A ||= B
A= $recvB= $self->{"recv_addr"}
ABresult
1X1
011
000
1945 0 ( $self->{'recv_port'}, my $hostn ) = sockaddr_in($recv);
1946 0 $self->{'recv_host'} = gethostbyaddr( $hostn, AF_INET );
1947 0 $self->{'recv_hostip'} = inet_ntoa($hostn);
1948 0 return $self->{'hostip'};
1949 }
1950  
1951 0 ▶sub get_my_addr { #$self->{'get_my_addr'} ||= sub {
Subroutine get_my_addr: not called CC=5 SCAR=34.0
Pod undocumented
1952 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1953 #my ($self) = @_;
1954 0 ▶ return unless $self->{'socket'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"socket"} 0 0 0
1955 #$self->log('dev', 'saddr', $self->{'socket'}->sockhost(),$self->{'socket'}->sockport() );
1956 0 ▶ $self->{'myport'} ||= $self->{'socket'}->sockport();
Condition0%0/3
$self->{"myport"} ||= $self->{"socket"}->sockport
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"myport"} ||= $self->{"socket"}->sockport
$self->{"myport"} $self->{"socket"}->sockport
Truth table0%0/3
A ||= B
A= $self->{"myport"}B= $self->{"socket"}->sockport
ABresult
1X1
011
000
1957 #$self->log('dev', 'myip was:', $self->{'myip'}, '->', $self->{'socket'}->sockhost());
1958 0 ▶ return $self->{'myip'} ||= $self->{'socket'}->sockhost();
Condition0%0/3
$self->{"myip"} ||= $self->{"socket"}->sockhost
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"myip"} ||= $self->{"socket"}->sockhost
$self->{"myip"} $self->{"socket"}->sockhost
Truth table0%0/3
A ||= B
A= $self->{"myip"}B= $self->{"socket"}->sockhost
ABresult
1X1
011
000
1959  
1960 =no
1961 eval { @_ = unpack_sockaddr_in( getsockname( $self->{'socket'} ) || return ); };
1962 $self->log( 'dcerr', "cant get my ip [$@]", Dumper \@_ ) if $@;
1963 #$self->log('dcerr', "cant get my ip [0.0.0.0:$_[0]]"),
1964 return if $_[1] eq "\0\0\0\0";
1965 #$self->log('dev', "1my ip", Dumper \@_);
1966 #return unless $_[1];
1967 return unless $_[1] and $_[1] = inet_ntoa( $_[1] );
1968 #$self->log('dev', "2my ip", Dumper \@_);
1969 #return if $_[1] eq '0.0.0.0';
1970 #$self->{'log'}->('dev', "MYIP($self->{'myip'}) [$self->{'number'}] SOCKNAME $_[0],$_[1];");
1971 return $self->{'myip'} ||= $_[1];
1972 =cut
1973 }
1974  
1975 0 ▶sub info { #$self->{'info'} ||= sub {
Subroutine info: not called CC=3 SCAR=24.8
Pod undocumented
1976 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
1977 #my $self = shift;
1978 $self->log(
1979 'info',
1980 0 map( {"$_=$self->{$_}"} grep { $self->{$_} } @{ $self->{'informative'} } ),
1981 #map( { $_ . '(' . scalar( keys %{ $self->{$_} } ) . ')=' . join( ',', sort keys %{ $self->{$_} } ) }
1982 #grep { keys %{ $self->{$_} } } @{ $self->{'informative_hash'} } )
1983 0 'clients:', scalar keys %{ $self->{'clients'} },
1984 0 map { "($self->{'clients'}{$_}{'number'})$_=$self->{'clients'}{$_}{'status'}" }
1985 0 sort keys %{ $self->{'clients'} },
1986 );
1987 $self->log(
1988 'dcdbg',
1989 "protocol stat",
1990 Dumper( {
1991 0 map { $_ => $self->{$_} }
1992 0 grep { $self->{$_} } qw(count_sendcmd count_parse)
1993 }
1994 ),
1995 0 ▶ ) unless $self->{'parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parent"} 0 0 0
1996 #( ref $self->{'clients'}{$_}{info} ? $self->{'clients'}{$_}->info() : () ) for sort keys %{ $self->{'clients'} };
1997 }
1998 #sub status {
1999 #now states:
2000 #listening connecting_tcp connecting connected reconnecting transfer disconnecting disconnected destroy
2001 #need checks:
2002 #\ connected?/ \-----/
2003 #\-----------------------active?-------------------------/
2004 #}
2005 #$self->{'active'} ||= sub {
2006 0 ▶sub active {
Subroutine active: not called CC=3 SCAR=24.8
Pod undocumented
2007 #my $self = shift;
2008 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2009 #$self->log('dev', 'active=', $self->{'status'});
2010 return $self->{'status'}
2011 0 ▶ if grep { $self->{'status'} eq $_ } qw(connecting_tcp connecting connected reconnecting listening transfer working);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$self->{"status"} eq $_;} "connecting_tcp", "connecting", "connected", "reconnecting", "listening", "transfer", "working" 0 0 0
2012 0 return 0;
2013 }
2014  
2015 0 ▶sub every { #$self->{'every'} ||= sub {
Subroutine every: not called CC=3 SCAR=24.8
Pod undocumented
2016 0 my ( $self, $sec, $func ) = ( shift, shift, shift );
2017 0 ▶ if ( ( $self->{'every_list'}{$func} + $sec < time )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"every_list"}{$func} + $sec < &Net::DirectConnect::time() and ref $func eq "CODE") 0 0 0
Condition0%0/3
$self->{"every_list"}{$func} + $sec < &Net::DirectConnect::time() and ref $func eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"every_list"}{$func} + $sec < &Net::DirectConnect::time() and ref $func eq "CODE"
$self->{"every_list"}{$func} + $sec < &Net::DirectConnect::time() ref $func eq "CODE"
Truth table0%0/3
A and B
A= $self->{"every_list"}{$func} + $sec < &Net::DirectConnect::time()B= ref $func eq "CODE"
ABresult
0X0
100
111
2018 and ( ref $func eq 'CODE' ) )
2019 {
2020 0 $self->{'every_list'}{$func} = time;
2021 0 $func->(@_);
2022 }
2023 }
2024  
2025 0 ▶sub adc_make_string { #$self->{'adc_make_string'} = sub (@) {
Subroutine adc_make_string: not called CC=4 SCAR=30.0
Pod undocumented
2026 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2027 join ' ', map {
2028 0 ▶ ref $_ eq 'ARRAY' ? @$_ : ref $_ eq 'HASH' ? do {
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
2029 0 my $h = $_;
2030 0 map { "$_$h->{$_}" } keys %$h;
2031 }
2032 : $_
2033 } @_;
2034 }
2035  
2036 0 ▶sub cmd_adc { #$self->{'cmd_adc'} ||= sub {
Subroutine cmd_adc: not called CC=3 SCAR=24.8
Pod undocumented
2037 0 my ( $self, $dst, $cmd ) = ( shift, shift, shift );
2038 #$self->sendcmd( $dst, $cmd,map {ref $_ eq 'HASH'}@_);
2039 #$self->log( 'cmd_adc', $dst, $cmd, "SI[$self->{'INF'}{'SID'}]",Dumper \@_ );
2040 $self->sendcmd(
2041 $dst, $cmd,
2042 #map {ref $_ eq 'ARRAY' ? @$_:ref $_ eq 'HASH' ? each : $_) }@_
2043 ( #$self->{'broadcast'} ? $self->{'INF'}{'SID'} #$self->{'INF'}{'ID'}
2044 #:
2045 ( $dst eq 'C' or !length $self->{'INF'}{'SID'} )
2046 ? ()
2047 0 ▶ : $self->{'INF'}{'SID'}
Branch: 1 branch
BranchTrueFalseTotal
$dst eq 'C' || !length($self->{'INF'}{'SID'}) ? : 0 0 0
Condition0%0/3
$dst eq "C" or not length $self->{"INF"}{"SID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dst eq "C" or not length $self->{"INF"}{"SID"}
$dst eq "C" not length $self->{"INF"}{"SID"}
Truth table0%0/3
A or not(B)
A= $dst eq "C"B= not length $self->{"INF"}{"SID"}
ABresult
1X1
011
000
2048 ),
2049 $self->adc_make_string(@_)
2050 #( $dst eq 'D' || !length $self->{'sid'} ? () : $self->{'sid'} ),
2051 );
2052 }
2053 #sub adc_string_decode ($) {
2054 0 ▶sub adc_string_decode { #$self->{'adc_string_decode'} ||= sub ($) {
Subroutine adc_string_decode: not called CC=1 SCAR=6.9
Pod undocumented
2055 0 my $self = shift;
2056 0 local ($_) = @_;
2057 0 s{\\s}{ }g;
2058 0 s{\\n}{\x0A}g;
2059 0 s{\\\\}{\\}g;
2060 0 $_;
2061 }
2062 #sub adc_string_encode ($) {
2063 0 ▶sub adc_string_encode { #$self->{'adc_string_encode'} = sub ($) {
Subroutine adc_string_encode: not called CC=1 SCAR=6.9
Pod undocumented
2064 0 my $self = shift;
2065 0 local ($_) = @_;
2066 0 s{\\}{\\\\}g;
2067 0 s{ }{\\s}g;
2068 0 s{\x0A}{\\n}g;
2069 0 $_;
2070 }
2071  
2072 0 ▶sub adc_path_encode { #$self->{'adc_path_encode'} = sub ($) {
Subroutine adc_path_encode: not called CC=1 SCAR=6.9
Pod undocumented
2073 0 my $self = shift;
2074 0 local ($_) = @_;
2075 0 s{^(\w:)}{/${1}_}g;
2076 0 s{\\}{/}g;
2077 0 $self->adc_string_encode($_);
2078 }
2079 #sub adc_strings_decode (\@) {
2080 0 ▶sub adc_strings_decode { #$self->{'adc_strings_decode'} = sub (\@) {
Subroutine adc_strings_decode: not called CC=1 SCAR=6.9
Pod undocumented
2081 0 my $self = shift;
2082 0 map { $self->adc_string_decode($_) } @_;
2083 }
2084 #sub adc_strings_encode (\@) {
2085 0 ▶sub adc_strings_encode { #$self->{'adc_strings_encode'} = sub (\@) {
Subroutine adc_strings_encode: not called CC=1 SCAR=6.9
Pod undocumented
2086 0 my $self = shift;
2087 0 map { $self->adc_string_encode($_) } @_;
2088 }
2089  
2090 0 ▶sub adc_parse_named { #$self->{'adc_parse_named'} = sub (@) {
Subroutine adc_parse_named: not called CC=2 SCAR=17.9
Pod undocumented
2091 0 my $self = shift;
2092 #sub adc_parse_named (@) {
2093 #my ($dst,$peerid) = @{ shift() };
2094 #$self->log('dev', "p0:", @_);
2095 0 local %_;
2096 0 for ( local @_ = @_ ) {
2097 0 s/^([A-Z][A-Z0-9])//;
2098 #my $name=
2099 #print "PARSE[$1=$_]\n",
2100 0 $_{$1} = $self->adc_string_decode($_);
2101 #$self->log('dev', "p1:$1=$_{$1}");
2102 }
2103 0 return \%_;
2104 #return ($dst,$peerid)
2105 }
2106  
2107 0 ▶sub make_token { #$self->{'make_token'} = sub (;$) {
Subroutine make_token: not called CC=3 SCAR=24.8
Pod undocumented
2108 0 my $self = shift;
2109 0 my $peerid = shift;
2110 0 my $token;
2111 0 local $_;
2112 $_ = $self->{'peers'}{$peerid}{'INF'}{I4}
2113 0 ▶ if $peerid and exists $self->{'peers'}{$peerid};
Branch: 1 branch
BranchTrueFalseTotal
if $peerid and exists $self->{"peers"}{$peerid} 0 0 0
Condition0%0/3
$peerid and exists $self->{"peers"}{$peerid}
!ll&&!rl&&r
000
MC/DC0%0/2
$peerid and exists $self->{"peers"}{$peerid}
$peerid exists $self->{"peers"}{$peerid}
Truth table0%0/3
A and B
A= $peeridB= exists $self->{"peers"}{$peerid}
ABresult
0X0
100
111
2114 0 s/\D//g;
2115 0 $token += $_;
2116 0 $_ = $self->{myip};
2117 0 s/\D//g;
2118 0 return $token + $_ + int time;
2119 }
2120  
2121 0 ▶sub say { #$self->{'say'} = sub (@) {
Subroutine say: not called CC=2 SCAR=17.9
Pod undocumented
2122 0 my $self = shift;
2123 0 ▶ @_ = $_[2] if $_[0] eq 'MSG';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "MSG" 0 0 0
2124 #local $_ = Encode::encode $self->{charset_console} , join ' ', @_;print $_, "\n";
2125 0 print Encode::encode( $self->{charset_console}, join( ' ', @_ ), Encode::FB_DEFAULT ), "\n";
2126 }
2127 #local %_ = (
2128 0 ▶sub search { #'search' => sub {
Subroutine search: not called CC=5 SCAR=34.0
Pod undocumented
2129 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2130 #$self->log( 'search', @_ );
2131 0 ▶ return $self->search_tth(@_)
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] == 39 and $_[0] =~ /^[0-9A-Z]+$/ 0 0 0
Condition0%0/3
length $_[0] == 39 and $_[0] =~ /^[0-9A-Z]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
length $_[0] == 39 and $_[0] =~ /^[0-9A-Z]+$/
length $_[0] == 39 $_[0] =~ /^[0-9A-Z]+$/
Truth table0%0/3
A and B
A= length $_[0] == 39B= $_[0] =~ /^[0-9A-Z]+$/
ABresult
0X0
100
111
2132 if length $_[0] == 39 and $_[0] =~ /^[0-9A-Z]+$/;
2133 0 ▶ return $self->search_string(@_) if length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] 0 0 0
2134 }
2135  
2136 0 ▶sub search_retry { #'search_retry' => sub {
Subroutine search_retry: not called CC=3 SCAR=24.8
Pod undocumented
2137 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2138 0 unshift( @{ $self->{'search_todo'} }, $self->{'search_last'} )
2139 0 ▶ if ref $self->{'search_last'} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"search_last"} eq "ARRAY" 0 0 0
2140 0 $self->{'search_last'} = undef;
2141 }
2142  
2143 0 ▶sub search_buffer { #'search_buffer' => sub {
Subroutine search_buffer: not called CC=7 SCAR=40.3
Pod undocumented
2144 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2145 0 ▶ push( @{ $self->{'search_todo'} }, [@_] ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
2146 0 ▶ return unless @{ $self->{'search_todo'} || return };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"search_todo"} or return;} 0 0 0
Condition0%0/2
$self->{'search_todo'} || (return)
l!l
00
MC/DC0%0/1
$self->{'search_todo'} || (return)
$self->{'search_todo'}
Truth table0%0/2
A
A= $self->{'search_todo'}
Aresult
11
00
2147 #$self->log($self, 'search', Dumper \@_);
2148 #$self->log( 'dcdev', "search too fast [$self->{'search_every'}], len=", scalar @{ $self->{'search_todo'} } ) if @_ and scalar @{ $self->{'search_todo'} } > 1;
2149 return
2150 0 ▶ if time() - $self->{'search_last_time'} < $self->{'search_every'} + 2;
Branch: 1 branch
BranchTrueFalseTotal
if &Net::DirectConnect::time() - $self->{"search_last_time"} < $self->{"search_every"} + 2 0 0 0
2151 0 $self->{'search_last'} = shift( @{ $self->{'search_todo'} } );
2152 0 ▶ $self->{'search_todo'} = undef unless @{ $self->{'search_todo'} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"search_todo"};} 0 0 0
2153 0 $self->search_send();
2154 #if ( $self->{'adc'} ) {
2155 #} else {
2156 #$self->sendcmd( 'Search', $self->{'M'} eq 'P' ? 'Hub:' . $self->{'Nick'} : "$self->{'myip'}:$self->{'myport_udp'}", join '?', @{ $self->{'search_last'} } );
2157 #}
2158 0 $self->{'search_last_time'} = time();
2159 }
2160  
2161 0 ▶sub nick_generate { #'nick_generate' => sub {
Subroutine nick_generate: not called CC=4 SCAR=30.0
Pod undocumented
2162 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2163 0 ▶ $self->{'nick_base'} ||= $self->{'Nick'};
Condition0%0/3
$self->{"nick_base"} ||= $self->{"Nick"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"nick_base"} ||= $self->{"Nick"}
$self->{"nick_base"} $self->{"Nick"}
Truth table0%0/3
A ||= B
A= $self->{"nick_base"}B= $self->{"Nick"}
ABresult
1X1
011
000
2164 0 ▶ $self->{'Nick'} = $self->{'nick_base'} . int( rand( $self->{'nick_random'} || 100 ) );
Condition0%0/2
$self->{'nick_random'} || 100
l!l
00
MC/DC0%0/1
$self->{'nick_random'} || 100
$self->{'nick_random'}
Truth table0%0/2
A
A= $self->{'nick_random'}
Aresult
11
00
2165 }
2166  
2167 0 ▶sub clients_my { #'clients_my' => sub {
Subroutine clients_my: not called CC=3 SCAR=24.8
Pod undocumented
2168 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
2169 0 ▶ grep { $self->{'clients'}{$_} and $self->{'clients'}{$_}{parent} eq $self }
Condition0%0/3
$self->{'clients'}{$_} && $self->{'clients'}{$_}{'parent'} eq $self
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'clients'}{$_} && $self->{'clients'}{$_}{'parent'} eq $self
$self->{'clients'}{$_} $self->{'clients'}{$_}{'parent'} eq $self
Truth table0%0/3
A && B
A= $self->{'clients'}{$_}B= $self->{'clients'}{$_}{'parent'} eq $self
ABresult
0X0
100
111
2170 0 keys %{ $self->{'clients'} };
2171 }
2172 #);
2173 #$self->{$_} = $_{$_} for keys %_;
2174 #}
2175 #print "N:DC:CALLER=", caller, "\n";
2176 1 ▶do {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
2177 1 ▶ use lib '../';
Subroutine BEGIN: called CC=1 SCAR=0.0
2178 0 __PACKAGE__->new( auto_work => 1, @ARGV ),;
2179 } unless caller;
2180 1 1;
2181 __END__
« DirectConnect/adc.pm ↑ Summary DirectConnect/pslib/psmisc.pm »