| 1 | package IO::Socket::HappyEyeballs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: RFC 8305 Happy Eyeballs v2 connection algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Errno qw( EINPROGRESS ECONNREFUSED EISCONN ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use IO::Socket::IP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Socket qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | getaddrinfo getnameinfo pack_sockaddr_in6 unpack_sockaddr_in6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | AF_INET AF_INET6 AF_UNSPEC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | SOCK_STREAM IPPROTO_TCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | NI_NUMERICHOST NI_NUMERICSERV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | SOL_SOCKET SO_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | AI_ADDRCONFIG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | inet_pton inet_ntop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use IO::Select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use parent qw(IO::Socket::IP); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Class-level cache: { "host:port" => { family => AF_INET6|AF_INET, expires => time } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | my %_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | my $CACHE_TTL = 600; # 10 minutes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Default connection attempt delay per RFC 8305 §5: 250ms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | my $DEFAULT_DELAY = 0.250; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Last Resort Local Synthesis Delay per RFC 8305 §7.2: 2 seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | my $LAST_RESORT_DELAY = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | my $_override_active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | for my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if ($arg eq '-override') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | $class->_install_override unless $_override_active; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub _install_override { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_override: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $original_new = IO::Socket::IP->can('new'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | my $original_configure = IO::Socket::IP->can('configure'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Override configure to skip connect on already-connected sockets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # When a subclass (e.g. Net::HTTP) calls configure after Happy Eyeballs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # has already connected, IO::Socket::IP::configure must not reconnect. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | *IO::Socket::IP::configure = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | my ($self, $cnf) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if (delete ${*$self}{io_socket_happyeyeballs_connected}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | return $original_configure->($self, $cnf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | *IO::Socket::IP::new = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=15 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 11 | my ($ip_class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Only intercept TCP connections with a peer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 11 | ▶ | if (($args{PeerHost} || $args{PeerAddr}) && $args{PeerPort}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$args{"PeerHost"} || $args{"PeerAddr"} and $args{"PeerPort"}
$args{"PeerHost"} or $args{"PeerAddr"}
MC/DC66%2/3
$args{"PeerHost"} || $args{"PeerAddr"} and $args{"PeerPort"}
$args{"PeerHost"}
$args{"PeerAddr"}
$args{"PeerPort"}
Truth table60%3/5
A or B and C
A= $args{"PeerHost"}B= $args{"PeerAddr"}C= $args{"PeerPort"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | my $proto = $args{Proto} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'Proto'} || ''
MC/DC100%1/1
$args{'Proto'} || ''
$args{'Proto'}
Truth table100%2/2
A
A= $args{'Proto'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | my $type = $args{Type} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'Type'} || 0
MC/DC0%0/1
$args{'Type'} || 0
$args{'Type'}
Truth table50%1/2
A
A= $args{'Type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if (!$proto || $proto eq 'tcp' || $type == SOCK_STREAM || !$type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not $proto or $proto eq "tcp" or $type == 1 or not $type
not $proto or $proto eq "tcp" or $type == 1
not $proto or $proto eq "tcp"
MC/DC0%0/4
not $proto or $proto eq "tcp" or $type == 1 or not $type
not $proto
$proto eq "tcp"
$type == 1
not $type
Truth table40%2/5
not(A) or B or C or not(D)
A= not $protoB= $proto eq "tcp"C= $type == 1D= not $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | my $sock = IO::Socket::HappyEyeballs->_happy_connect(\%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # For subclasses (e.g. Net::HTTP): rebless and let their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # configure run for protocol-specific setup, while our | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # IO::Socket::IP::configure override skips reconnecting. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | if ($ip_class ne 'IO::Socket::IP' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$ip_class ne "IO::Socket::IP" and $ip_class ne "IO::Socket::HappyEyeballs" and $ip_class->isa("IO::Socket::IP")
$ip_class ne "IO::Socket::IP" and $ip_class ne "IO::Socket::HappyEyeballs"
MC/DC33%1/3
$ip_class ne "IO::Socket::IP" and $ip_class ne "IO::Socket::HappyEyeballs" and $ip_class->isa("IO::Socket::IP")
$ip_class ne "IO::Socket::IP"
$ip_class ne "IO::Socket::HappyEyeballs"
$ip_class->isa("IO::Socket::IP")
Truth table50%2/4
A and B and C
A= $ip_class ne "IO::Socket::IP"B= $ip_class ne "IO::Socket::HappyEyeballs"C= $ip_class->isa("IO::Socket::IP")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | && $ip_class ne 'IO::Socket::HappyEyeballs' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | && $ip_class->isa('IO::Socket::IP')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | bless $sock, $ip_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ${*$sock}{io_socket_happyeyeballs_connected} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | $sock->configure(\%args) if $sock->can('configure'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | return $original_new->($ip_class, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $_override_active = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | ▶ | sub _happy_connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_happy_connect: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | my ($class, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Use our Happy Eyeballs algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | my $peer_host = $args->{PeerHost} || $args->{PeerAddr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{'PeerHost'} || $args->{'PeerAddr'}
MC/DC0%0/2
$args->{'PeerHost'} || $args->{'PeerAddr'}
$args->{'PeerHost'}
$args->{'PeerAddr'}
Truth table66%2/3
A || B
A= $args->{'PeerHost'}B= $args->{'PeerAddr'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my $peer_port = $args->{PeerPort}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | my $delay = delete $args->{ConnectionAttemptDelay} // $DEFAULT_DELAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args->{"ConnectionAttemptDelay"} // $DEFAULT_DELAY
MC/DC0%0/2
delete $args->{"ConnectionAttemptDelay"} // $DEFAULT_DELAY
delete $args->{"ConnectionAttemptDelay"}
$DEFAULT_DELAY
Truth table33%1/3
A // B
A= delete $args->{"ConnectionAttemptDelay"}B= $DEFAULT_DELAY
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | my $timeout = $args->{Timeout} // 30; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"Timeout"} // 30
MC/DC100%1/1
$args->{"Timeout"} // 30
$args->{"Timeout"}
Truth table100%2/2
A
A= $args->{"Timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | my @addresses = _resolve($peer_host, $peer_port, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | ▶ | unless (@addresses) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $@ = "Cannot resolve host '$peer_host': no addresses found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | @addresses = _sort_addresses(\@addresses, $peer_host, $peer_port); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | my $sock = _attempt_connections(\@addresses, $delay, $timeout, $args, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $peer_host, $peer_port); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | _cache_result($peer_host, $peer_port, $sock->sockdomain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $@ = "Cannot connect to $peer_host:$peer_port: all attempts failed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | my $peer_host = $args{PeerHost} || $args{PeerAddr} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | ▶ | or croak "PeerHost or PeerAddr is required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{'PeerHost'} || $args{'PeerAddr'}
MC/DC0%0/2
$args{'PeerHost'} || $args{'PeerAddr'}
$args{'PeerHost'}
$args{'PeerAddr'}
Truth table33%1/3
A || B
A= $args{'PeerHost'}B= $args{'PeerAddr'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | my $peer_port = $args{PeerPort} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | or croak "PeerPort is required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | ▶ | my $delay = delete $args{ConnectionAttemptDelay} // $DEFAULT_DELAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{"ConnectionAttemptDelay"} // $DEFAULT_DELAY
MC/DC0%0/2
delete $args{"ConnectionAttemptDelay"} // $DEFAULT_DELAY
delete $args{"ConnectionAttemptDelay"}
$DEFAULT_DELAY
Truth table33%1/3
A // B
A= delete $args{"ConnectionAttemptDelay"}B= $DEFAULT_DELAY
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | my $timeout = $args{Timeout} // 30; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"Timeout"} // 30
MC/DC0%0/1
$args{"Timeout"} // 30
$args{"Timeout"}
Truth table50%1/2
A
A= $args{"Timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Resolve addresses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | my @addresses = _resolve($peer_host, $peer_port, \%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | ▶ | unless (@addresses) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $@ = "Cannot resolve host '$peer_host': no addresses found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Sort with interleaving per RFC 8305 §4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | @addresses = _sort_addresses(\@addresses, $peer_host, $peer_port); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Attempt connections with Happy Eyeballs algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | my $sock = _attempt_connections(\@addresses, $delay, $timeout, \%args, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | $peer_host, $peer_port); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | _cache_result($peer_host, $peer_port, $sock->sockdomain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $@ = "Cannot connect to $peer_host:$peer_port: all attempts failed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 10 | ▶ | sub _resolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 10 | my ($host, $port, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Respect GetAddrInfoFlags from IO::Socket::IP compatibility, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # default to AI_ADDRCONFIG per RFC 8305 recommendation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | my $flags = exists $args->{GetAddrInfoFlags} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ? $args->{GetAddrInfoFlags} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 10 | ▶ | : AI_ADDRCONFIG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | ▶ | my %hints = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | socktype => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | protocol => IPPROTO_TCP, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | family => AF_UNSPEC, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ($flags ? (flags => $flags) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | my ($err, @results) = getaddrinfo($host, $port, \%hints); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # If AI_ADDRCONFIG returned nothing (e.g. loopback-only interfaces), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # retry without it to avoid filtering out valid addresses. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | if (($err || !@results) && $flags) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$err || !@results and $flags
$err or not @results
MC/DC33%1/3
$err || !@results and $flags
$err
not @results
$flags
Truth table40%2/5
A or not(B) and C
A= $errB= not @resultsC= $flags
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | delete $hints{flags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ($err, @results) = getaddrinfo($host, $port, \%hints); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | $@ = "getaddrinfo failed: $err"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 17 | ▶ | sub _sort_addresses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_addresses: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 17 | my ($addresses, $host, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Check cache for preferred family | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 17 | my $cache_key = "$host:$port"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 17 | my $preferred_family; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 17 | ▶ | if (my $cached = $_cache{$cache_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 8 | ▶ | if ($cached->{expires} > time()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | $preferred_family = $cached->{family}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | delete $_cache{$cache_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # Separate by address family | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 17 | my (@ipv6, @ipv4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 17 | for my $addr (@$addresses) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 29 | ▶ | if ($addr->{family} == AF_INET6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | push @ipv6, $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 19 | push @ipv4, $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Interleave: preferred family first, then alternate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Per RFC 8305 §4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 17 | my @sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 17 | my ($primary, $secondary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 17 | ▶ | if ($preferred_family && $preferred_family == AF_INET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$preferred_family and $preferred_family == 2
MC/DC100%2/2
$preferred_family and $preferred_family == 2
$preferred_family
$preferred_family == 2
Truth table100%3/3
A and B
A= $preferred_familyB= $preferred_family == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 6 | $primary = \@ipv4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | $secondary = \@ipv6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 11 | ▶ | $primary = @ipv6 ? \@ipv6 : \@ipv4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 11 | ▶ | $secondary = @ipv6 ? \@ipv4 : \@ipv6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 17 | ▶ | while (@$primary || @$secondary) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$primary or @$secondary
MC/DC50%1/2
@$primary or @$secondary
@$primary
@$secondary
Truth table66%2/3
A or B
A= @$primaryB= @$secondary
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 21 | ▶ | push @sorted, shift @$primary if @$primary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 21 | ▶ | push @sorted, shift @$secondary if @$secondary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 17 | return @sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 9 | ▶ | sub _attempt_connections { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attempt_connections: called CC=22 SCAR=39.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 9 | my ($addresses, $delay, $timeout, $args, $host, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 9 | my @pending; # [ socket, addrinfo ] pairs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 9 | my $select = IO::Select->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | my $deadline = time() + $timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | my $next_attempt_time = 0; # start first attempt immediately | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | my $addr_idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | my $last_attempt_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 9 | my $last_resort_done = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 9 | ▶ | while ($addr_idx < @$addresses || @pending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$addr_idx < @$addresses or @pending
MC/DC50%1/2
$addr_idx < @$addresses or @pending
$addr_idx < @$addresses
@pending
Truth table66%2/3
A or B
A= $addr_idx < @$addressesB= @pending
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 9 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 9 | ▶ | last if $now >= $deadline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # RFC 8305 §7.2: Last Resort Local Synthesis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # When all initial addresses are exhausted and all pending have failed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # wait until $LAST_RESORT_DELAY seconds after last attempt, then try | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # A-record-only resolution with NAT64 synthesis. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 9 | ▶ | if (!$last_resort_done && $addr_idx >= @$addresses && !@pending | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not $last_resort_done and $addr_idx >= @$addresses and not @pending and $last_attempt_time
not $last_resort_done and $addr_idx >= @$addresses and not @pending
not $last_resort_done and $addr_idx >= @$addresses
MC/DC0%0/4
not $last_resort_done and $addr_idx >= @$addresses and not @pending and $last_attempt_time
not $last_resort_done
$addr_idx >= @$addresses
not @pending
$last_attempt_time
Truth table20%1/5
not(A) and B and not(C) and D
A= not $last_resort_doneB= $addr_idx >= @$addressesC= not @pendingD= $last_attempt_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | && $last_attempt_time) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $synth_addresses = _last_resort_synthesis( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | $host, $port, $args, $last_attempt_time, $deadline); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($synth_addresses && @$synth_addresses) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$synth_addresses and @$synth_addresses
MC/DC0%0/2
$synth_addresses and @$synth_addresses
$synth_addresses
@$synth_addresses
Truth table0%0/3
A and B
A= $synth_addressesB= @$synth_addresses
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | push @$addresses, @$synth_addresses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $last_resort_done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | next; # re-enter loop to process new addresses | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $last_resort_done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # Start a new connection attempt if it's time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | ▶ | if ($addr_idx < @$addresses && $now >= $next_attempt_time) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$addr_idx < @$addresses and $now >= $next_attempt_time
MC/DC0%0/2
$addr_idx < @$addresses and $now >= $next_attempt_time
$addr_idx < @$addresses
$now >= $next_attempt_time
Truth table33%1/3
A and B
A= $addr_idx < @$addressesB= $now >= $next_attempt_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 9 | my $addr = $addresses->[$addr_idx++]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 9 | my $sock = _start_connect($addr, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 9 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Check if already connected (localhost etc.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 9 | ▶ | if ($sock->connected) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 7 | _cleanup_pending(\@pending); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 7 | _restore_blocking($sock, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 7 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | push @pending, [ $sock, $addr ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | $select->add($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | $last_attempt_time = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | $next_attempt_time = $last_attempt_time + $delay; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | next unless @pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Calculate how long to wait | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | my $wait_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | if ($addr_idx < @$addresses) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # Wait until either a connection succeeds or it's time for the next attempt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $wait_time = $next_attempt_time - time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $wait_time = 0 if $wait_time < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # No more addresses to try, wait for remaining connections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | $wait_time = $deadline - time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 2 | ▶ | $wait_time = 0 if $wait_time < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # select() for writable (connected) sockets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | my @ready = IO::Select->select(undef, $select, undef, $wait_time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | if (@ready && $ready[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@ready and $ready[1]
MC/DC0%0/2
@ready and $ready[1]
@ready
$ready[1]
Truth table33%1/3
A and B
A= @readyB= $ready[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | for my $sock (@{$ready[1]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # Check if the connection actually succeeded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $err = $sock->sockopt(SO_ERROR); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | if ($err == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Success! Clean up all other pending sockets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my @others = grep { $_->[0] != $sock } @pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | _cleanup_pending(\@others); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | _restore_blocking($sock, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # This connection failed, remove it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | $select->remove($sock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | @pending = grep { $_->[0] != $sock } @pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # All failed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | _cleanup_pending(\@pending); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 9 | ▶ | sub _start_connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_connect: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 9 | my ($addr, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 9 | my $sock = IO::Socket::IP->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | $sock->socket($addr->{family}, $addr->{socktype}, $addr->{protocol}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 9 | ▶ | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 9 | $sock->blocking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 9 | my $rv = CORE::connect($sock, $addr->{addr}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 9 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # Connected immediately | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 9 | ▶ | if ($! == EINPROGRESS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # Connection in progress — this is the normal non-blocking case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 9 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Immediate failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 7 | ▶ | sub _restore_blocking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_blocking: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 7 | my ($sock, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 7 | ▶ | if (exists $args->{Blocking} && !$args->{Blocking}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args->{"Blocking"} and not $args->{"Blocking"}
MC/DC50%1/2
exists $args->{"Blocking"} and not $args->{"Blocking"}
exists $args->{"Blocking"}
not $args->{"Blocking"}
Truth table66%2/3
A and not(B)
A= exists $args->{"Blocking"}B= not $args->{"Blocking"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | $sock->blocking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | $sock->blocking(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 9 | ▶ | sub _cleanup_pending { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cleanup_pending: called CC=3 SCAR=16.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 9 | my ($pending) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 9 | for my $p (@$pending) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $p->[0]->close if $p->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # RFC 8305 §7.2: Last Resort Local Synthesis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # After all AAAA-based attempts fail, wait for the synthesis delay, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # then query A records and synthesize IPv6 via NAT64 if available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | sub _last_resort_synthesis { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_last_resort_synthesis: called CC=10 SCAR=33.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | my ($host, $port, $args, $last_attempt_time, $deadline) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | ▶ | return unless defined $host && defined $port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $host and defined $port
MC/DC0%0/2
defined $host and defined $port
defined $host
defined $port
Truth table33%1/3
A and B
A= defined $hostB= defined $port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # Wait until $LAST_RESORT_DELAY after last attempt fired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | my $synthesis_time = $last_attempt_time + $LAST_RESORT_DELAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | ▶ | if ($now < $synthesis_time) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | my $wait = $synthesis_time - $now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | ▶ | return if $now + $wait > $deadline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | select(undef, undef, undef, $wait); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # Query A records only (IPv4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | my ($err, @ipv4_results) = getaddrinfo($host, $port, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | socktype => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | protocol => IPPROTO_TCP, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | family => AF_INET, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | ▶ | return unless @ipv4_results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # Detect NAT64 prefix via RFC 7050 (ipv4only.arpa) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $nat64_prefix = _detect_nat64_prefix(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if ($nat64_prefix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Synthesize IPv6 addresses from IPv4 using NAT64 prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my @synthesized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | for my $r (@ipv4_results) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $synth = _synthesize_nat64_addr($r, $nat64_prefix, $port); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | push @synthesized, $synth if $synth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | return \@synthesized if @synthesized; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # No NAT64: return IPv4 addresses directly as fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return \@ipv4_results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # RFC 7050: Discovery of the IPv6 Prefix Used for IPv6 Address Synthesis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # Resolve ipv4only.arpa AAAA — if we get results, NAT64 is present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # and the prefix can be extracted from the response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | my $_nat64_prefix_cache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 11 | my $_nat64_prefix_expires = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | sub _detect_nat64_prefix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_detect_nat64_prefix: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | if ($now < $_nat64_prefix_expires) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | return $_nat64_prefix_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # The well-known IPv4 addresses for ipv4only.arpa are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # 192.0.0.170 and 192.0.0.171. If AAAA resolution returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # results, the NAT64 prefix is the first 96 bits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | my ($err, @results) = getaddrinfo('ipv4only.arpa', '443', { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | socktype => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | family => AF_INET6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | ▶ | if (!$err && @results) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $err and @results
MC/DC0%0/2
not $err and @results
not $err
@results
Truth table33%1/3
not(A) and B
A= not $errB= @results
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my ($synth_port, $synth_addr) = unpack_sockaddr_in6($results[0]{addr}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # The well-known address 192.0.0.170 = 0xC0000AA in the last 32 bits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Extract the first 12 bytes as the NAT64 prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $prefix = substr($synth_addr, 0, 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $_nat64_prefix_cache = $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $_nat64_prefix_expires = $now + 600; # cache for 10 minutes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | $_nat64_prefix_cache = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | $_nat64_prefix_expires = $now + 60; # negative cache for 1 minute | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # Synthesize an IPv6 address by combining NAT64 prefix with IPv4 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | ▶ | sub _synthesize_nat64_addr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_synthesize_nat64_addr: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | my ($ipv4_addrinfo, $nat64_prefix, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Extract the IPv4 address from the sockaddr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 2 | my $family = $ipv4_addrinfo->{family}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | ▶ | return unless $family == AF_INET; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | my ($ipv4_port, $ipv4_packed) = Socket::unpack_sockaddr_in($ipv4_addrinfo->{addr}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # Build synthesized IPv6 address: 96-bit prefix + 32-bit IPv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | my $synth_ipv6 = $nat64_prefix . $ipv4_packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | my $synth_sockaddr = pack_sockaddr_in6($ipv4_port, $synth_ipv6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | family => AF_INET6, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | socktype => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | protocol => IPPROTO_TCP, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | addr => $synth_sockaddr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 11 | ▶ | sub _cache_result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cache_result: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 11 | my ($host, $port, $family) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 11 | $_cache{"$host:$port"} = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | family => $family, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | expires => time() + $CACHE_TTL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 6 | ▶ | sub clear_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_cache: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | %_cache = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 6 | $_nat64_prefix_cache = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 6 | $_nat64_prefix_expires = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 8 | ▶ | sub last_resort_delay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_resort_delay: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 8 | my ($class, $new_delay) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 8 | ▶ | if (defined $new_delay) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 6 | $LAST_RESORT_DELAY = $new_delay; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 8 | return $LAST_RESORT_DELAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | ▶ | sub connection_attempt_delay { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection_attempt_delay: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | my ($class, $new_delay) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 4 | ▶ | if (defined $new_delay) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | $DEFAULT_DELAY = $new_delay; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | return $DEFAULT_DELAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | ▶ | sub cache_ttl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_ttl: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | my ($class, $new_ttl) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | ▶ | if (defined $new_ttl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2 | $CACHE_TTL = $new_ttl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | return $CACHE_TTL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||