TT#24097 Rework perl code flow

- Avoid comma-separated statements.
- Avoid mixed boolean operators, and use proper code flow keywords.

Change-Id: Iec4c85a3d39fe94ba7b9f293dc158892ae7d9577
changes/16/16716/4
Guillem Jover 8 years ago
parent cff9d296fd
commit 0bdc116387

@ -596,17 +596,17 @@ sub stun_handler_binding_success {
sub check_to_nominate { sub check_to_nominate {
my ($self) = @_; my ($self) = @_;
$self->{controlling} or return; return unless $self->{controlling};
$self->{start_nominating} && time() < $self->{start_nominating} and return; return if $self->{start_nominating} && time() < $self->{start_nominating};
$self->{nominate} and return; return if $self->{nominate};
@{$self->{triggered_checks}} and return; return if @{$self->{triggered_checks}};
my @succeeded; my @succeeded;
for my $pair (values(%{$self->{candidate_pairs}})) { for my $pair (values(%{$self->{candidate_pairs}})) {
my @comps = @{$pair->{components}}; my @comps = @{$pair->{components}};
my @succeeded_comps = grep {$_->{state} eq 'succeeded'} @comps; my @succeeded_comps = grep {$_->{state} eq 'succeeded'} @comps;
@succeeded_comps < $self->{components} and next; next if @succeeded_comps < $self->{components};
$self->debug("got fully succeeded pair $pair->{foundation}\n"); $self->debug("got fully succeeded pair $pair->{foundation}\n");
push(@succeeded, $pair); push(@succeeded, $pair);
} }
@ -753,7 +753,8 @@ sub timer {
# run checks # run checks
defined($self->{other_ufrag}) && defined($self->{other_pwd}) or return; # not enough info # not enough info
return if !defined($self->{other_ufrag}) || !defined($self->{other_pwd});
if (my $pair = shift(@{$self->{triggered_checks}})) { if (my $pair = shift(@{$self->{triggered_checks}})) {
$pair->debug("running triggered check\n"); $pair->debug("running triggered check\n");

@ -62,7 +62,10 @@ sub send_rcv {
recv($recvfd, $inc, length($pkt), 0); recv($recvfd, $inc, length($pkt), 0);
alarm(0); alarm(0);
} }
$inc eq $pkt or print("NOT received packed ok\n"), return; if ($inc ne $pkt) {
print("NOT received packed ok\n");
return;
}
print("received packet ok\n"); print("received packet ok\n");
} }

@ -65,7 +65,10 @@ sub send_rcv {
$addr = recv($recvfd, $inc, length($pkt), 0); $addr = recv($recvfd, $inc, length($pkt), 0);
alarm(0); alarm(0);
} }
$inc eq $pkt or print("did NOT receive packet\n"), return; if ($inc ne $pkt) {
print("did NOT receive packet\n");
return;
}
my ($port, $ip) = sockaddr_in($addr); my ($port, $ip) = sockaddr_in($addr);
$laddr = getsockname($recvfd); $laddr = getsockname($recvfd);
($lport, $lip) = sockaddr_in($laddr); ($lport, $lip) = sockaddr_in($laddr);

@ -50,7 +50,7 @@ local $SIG{ALRM} = sub { print "alarm!\n"; };
setrlimit(RLIMIT_NOFILE, 8000, 8000); setrlimit(RLIMIT_NOFILE, 8000, 8000);
$PROTOS and $PROTOS = [split(/\s*[,;:]+\s*/, $PROTOS)]; $PROTOS and $PROTOS = [split(/\s*[,;:]+\s*/, $PROTOS)];
$PROTOS && @$PROTOS == 1 and $$PROTOS[1] = $$PROTOS[0]; $$PROTOS[1] = $$PROTOS[0] if $PROTOS && @$PROTOS == 1;
$DEST and $DEST = [$DEST =~ /^(?:([a-z.-]+)(?::(\d+))?|([\d.]+)(?::(\d+))?|([\da-f:]+)|\[([\da-f:]+)\]:(\d+))$/si]; $DEST and $DEST = [$DEST =~ /^(?:([a-z.-]+)(?::(\d+))?|([\d.]+)(?::(\d+))?|([\da-f:]+)|\[([\da-f:]+)\]:(\d+))$/si];
my $dest_host = $$DEST[0] || $$DEST[2] || $$DEST[4] || $$DEST[5] || 'localhost'; my $dest_host = $$DEST[0] || $$DEST[2] || $$DEST[4] || $$DEST[5] || 'localhost';
my $dest_port = $$DEST[1] || $$DEST[3] || $$DEST[6] || 2223; my $dest_port = $$DEST[1] || $$DEST[3] || $$DEST[6] || 2223;
@ -86,8 +86,14 @@ sub msg {
my @dests = getaddrinfo($dest_host, $dest_port, AF_UNSPEC, SOCK_DGRAM); my @dests = getaddrinfo($dest_host, $dest_port, AF_UNSPEC, SOCK_DGRAM);
while (@dests >= 5) { while (@dests >= 5) {
my ($fam, $type, $prot, $addr, $canon, @dests) = @dests; my ($fam, $type, $prot, $addr, $canon, @dests) = @dests;
socket($fd, $fam, $type, $prot) or undef($fd), next; if (!socket($fd, $fam, $type, $prot)) {
connect($fd, $addr) or undef($fd), next; undef($fd);
next;
}
if (!connect($fd, $addr)) {
undef($fd);
next;
}
last; last;
} }
$fd or die($!); $fd or die($!);
@ -106,7 +112,7 @@ sub send_receive {
alarm(1); alarm(1);
recv($receive_fd, $x, 0xffff, 0) or $err = "$!"; recv($receive_fd, $x, 0xffff, 0) or $err = "$!";
alarm(0); alarm(0);
$err && $err !~ /interrupt/i and die $err; die $err if $err && $err !~ /interrupt/i;
return $x; return $x;
} }
@ -403,7 +409,7 @@ sub do_rtp {
$KEEPGOING or undef($c); $KEEPGOING or undef($c);
} }
$NOENC and $repl = $expect; $NOENC and $repl = $expect;
!$repl && $KEEPGOING and next; next if !$repl && $KEEPGOING;
$repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTP port $$outputs[$j][0]"; $repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTP port $$outputs[$j][0]";
$rtcp or next; $rtcp or next;
@ -421,7 +427,7 @@ sub do_rtp {
$dst = $$pr{sockaddr}($dstport, $addr); $dst = $$pr{sockaddr}($dstport, $addr);
$repl = send_receive($sendfd, $expfd, $payload, $dst); $repl = send_receive($sendfd, $expfd, $payload, $dst);
$NOENC and $repl = $expect; $NOENC and $repl = $expect;
!$repl && $KEEPGOING and next; next if !$repl && $KEEPGOING;
$repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTCP"; $repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTCP";
} }
} }
@ -614,12 +620,12 @@ c=IN $$pr{family_str} $$ips_t[0]
t=0 0 t=0 0
SDP SDP
my $ul = $$A{num_streams}; my $ul = $$A{num_streams};
$op eq 'answer' && $$A{streams_seen} < $$A{num_streams} $ul = $$A{streams_seen} if $op eq 'answer' && $$A{streams_seen} < $$A{num_streams};
and $ul = $$A{streams_seen};
$$A{want_bundle} && $op eq 'offer' and if ($$A{want_bundle} && $op eq 'offer') {
$$A{bundle} = 1, $$A{bundle} = 1;
$sdp .= "a=group:BUNDLE " . join(' ', (0 .. $ul)) . "\n"; $sdp .= "a=group:BUNDLE " . join(' ', (0 .. $ul)) . "\n";
}
for my $i (0 .. $ul) { for my $i (0 .. $ul) {
my $bi = $i; my $bi = $i;
@ -628,8 +634,7 @@ SDP
my $p = $$ports_t[$bi]; my $p = $$ports_t[$bi];
my $cp = $p + 1; my $cp = $p + 1;
$$A{bundle} && $$A{want_rtcpmux} && $op eq 'offer' $cp = $p if $$A{bundle} && $$A{want_rtcpmux} && $op eq 'offer';
and $cp = $p;
$sdp .= <<"SDP"; $sdp .= <<"SDP";
m=audio $p $$tr{name} 0 8 111 m=audio $p $$tr{name} 0 8 111
@ -749,7 +754,10 @@ sub answer {
} }
for my $iter (1 .. $NUM) { for my $iter (1 .. $NUM) {
($iter % 10 == 0) and print("$iter calls established\n"), do_rtp(); if ($iter % 10 == 0) {
print("$iter calls established\n");
do_rtp();
}
my $c = {}; my $c = {};
offer($c, 0, 1); offer($c, 0, 1);

@ -75,7 +75,7 @@ sub do_rtp {
alarm(1); alarm(1);
recv($$fds[$b], $x, 0xffff, 0) or $err = "$!"; recv($$fds[$b], $x, 0xffff, 0) or $err = "$!";
alarm(0); alarm(0);
$err && $err !~ /interrupt/i and die $err; die $err if $err && $err !~ /interrupt/i;
if (($x || '') ne $payload) { if (($x || '') ne $payload) {
warn("no rtp reply received, ports $$outputs[$b][0] and $$outputs[$a][0]"); warn("no rtp reply received, ports $$outputs[$b][0] and $$outputs[$a][0]");
$KEEPGOING or undef($c); $KEEPGOING or undef($c);
@ -162,7 +162,10 @@ sub update_lookup {
} }
for my $iter (1 .. $NUM) { for my $iter (1 .. $NUM) {
($iter % 10 == 0) and print("$iter\n"), do_rtp(); if ($iter % 10 == 0) {
print("$iter\n");
do_rtp();
}
my $c = []; my $c = [];
update_lookup($c, 0); update_lookup($c, 0);
@ -200,7 +203,7 @@ if (!$NODEL) {
for my $c (@calls) { for my $c (@calls) {
$c or next; $c or next;
my ($tags, $callid) = @$c[3,5]; my ($tags, $callid) = @$c[3,5];
$BRANCHES && rand() < .3 and $callid =~ s/;.*//; $callid =~ s/;.*// if $BRANCHES && rand() < .3;
msg("D $callid $$tags[0] $$tags[1]"); msg("D $callid $$tags[0] $$tags[1]");
} }
} }

@ -13,8 +13,14 @@ my $fd;
my @dests = getaddrinfo($ip, $port, AF_UNSPEC, SOCK_DGRAM); my @dests = getaddrinfo($ip, $port, AF_UNSPEC, SOCK_DGRAM);
while (@dests >= 5) { while (@dests >= 5) {
my ($fam, $type, $prot, $addr, $canon, @dests) = @dests; my ($fam, $type, $prot, $addr, $canon, @dests) = @dests;
socket($fd, $fam, $type, $prot) or undef($fd), next; if (!socket($fd, $fam, $type, $prot)) {
connect($fd, $addr) or undef($fd), next; undef($fd);
next;
}
if (!connect($fd, $addr)) {
undef($fd);
next;
}
last; last;
} }
$fd or die($!); $fd or die($!);

@ -54,14 +54,29 @@ while (1) {
} }
next; next;
} }
$cmd == 1 or print("not stun request\n"), next; if ($cmd != 1) {
length($attrs) == $len or print("length mismatch\n"), next; print("not stun request\n")
next;
}
if (length($attrs) != $len) {
print("length mismatch\n")
next;
}
my ($list, $hash) = unpack_attrs($attrs); my ($list, $hash) = unpack_attrs($attrs);
$$list[$#$list]{name} eq 'fingerprint' or print("last attr not fingerprint\n"), next; if ($$list[$#$list]{name} ne 'fingerprint') {
$$list[$#$list-1]{name} eq 'message-integrity' or print("last but one attr not MI\n"), next; print("last attr not fingerprint\n");
$$hash{username} or print("no username\n"), next; next;
}
if ($$list[$#$list-1]{name} ne 'message-integrity') {
print("last but one attr not MI\n")
next;
}
unless ($$hash{username}) {
print("no username\n")
next;
}
$$hash{controlling} and print("is controlling\n"); $$hash{controlling} and print("is controlling\n");
$$hash{controlled} and print("is controlled\n"); $$hash{controlled} and print("is controlled\n");

@ -62,8 +62,8 @@ for my $x (split(/,/, 'origin,session connection')) {
defined($options{'replace-' . $x}) and push(@{$packet{replace}}, $x); defined($options{'replace-' . $x}) and push(@{$packet{replace}}, $x);
} }
for my $x (split(/,/, 'rtcp-mux,SDES')) { for my $x (split(/,/, 'rtcp-mux,SDES')) {
defined($options{$x}) && ref($options{$x}) eq 'ARRAY' $packet{$x} = $options{$x}
and $packet{$x} = $options{$x}; if defined($options{$x}) && ref($options{$x}) eq 'ARRAY';
} }
if (defined($options{direction})) { if (defined($options{direction})) {
$options{direction} =~ /(.*),(.*)/ or die; $options{direction} =~ /(.*),(.*)/ or die;

Loading…
Cancel
Save