| 1 | package Shardcache::Client; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Digest::SipHash qw/siphash/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Algorithm::ConsistentHash::CHash; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = "0.05"; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub _read_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_bytes: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my ($sock, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my $to_read = $len; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $read; | |||||||||||||||||||||||||||||||||||||||||
| 14 | my $data; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | while ($read != $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $rb = read($sock, $buffer, $to_read); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | last if ($rb <= 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $data .= $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $read += $rb; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | $to_read -= $rb; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return ($read == $len) ? $data : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ($class, $host, $secret) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | croak("The host parameter is mandatory!") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | unless($host); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $secret = '' unless($secret); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 36 | _secret => $secret, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | _nodes => [], | ||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (ref($host) && ref($host) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $host and ref $host eq "ARRAY"
MC/DC0%0/2
ref $host and ref $host eq "ARRAY"
ref $host
ref $host eq "ARRAY"
Truth table0%0/3
A and B
A= ref $hostB= ref $host eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | foreach my $h (@$host) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($h !~ /^[a-zA-Z0-9_\.\-]+:[a-zA-Z0-9_\.\-]+(?:[:][0-9]+)?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | die "Invalid host string $h"; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($label, $addr, $port) = split(':', $h); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | push(@{$self->{_nodes}}, { | |||||||||||||||||||||||||||||||||||||||||
| 48 | label => $label, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | addr => $addr, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | port => $port | ||||||||||||||||||||||||||||||||||||||||||
| 51 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | $self->{_chash} = Algorithm::ConsistentHash::CHash->new( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ids => [map { $_->{label} } @{$self->{_nodes}} ], | |||||||||||||||||||||||||||||||||||||||||
| 55 | replicas => 200); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($host !~ /^[a-zA-Z0-9_\.\-]+(?:[:][0-9]+)?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | die "Invalid host string $host"; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my ($addr, $port) = split(':', $host); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | push(@{$self->{_nodes}}, { | |||||||||||||||||||||||||||||||||||||||||
| 62 | label => "$addr:$port", | ||||||||||||||||||||||||||||||||||||||||||
| 63 | addr => $addr, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | port => $port | ||||||||||||||||||||||||||||||||||||||||||
| 65 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _chunkize_var { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_chunkize_var: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($var) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $templ; | |||||||||||||||||||||||||||||||||||||||||
| 76 | my @vars; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $vlen = length($var); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | while ($vlen > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($vlen <= 65535) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $templ .= "na$vlen"; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | push(@vars, $vlen, $var); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $vlen = 0; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $templ .= "na65535"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $substr = substr($var, 0, 65535, ""); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $vlen = length($var); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | push(@vars, 65535, $substr); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return pack $templ, @vars; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub send_msg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_msg: not called CC=44 SCAR=75.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my ($self, $hdr, $records, $sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $templ = "C"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my @vars = ($hdr); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $key; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $records = [ $records ] unless (ref($records) && ref($records) eq "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $records and ref $records eq "ARRAY"
MC/DC0%0/2
ref $records and ref $records eq "ARRAY"
ref $records
ref $records eq "ARRAY"
Truth table0%0/3
A and B
A= ref $recordsB= ref $records eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | foreach my $record (@$records) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($cnt++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $templ .= "C"; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | push @vars, 0x80; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $key = $record; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($record) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $buf = _chunkize_var($record); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $templ .= sprintf "a%dCC", length($buf); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | push @vars, $buf, 0x00, 0x00; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $templ .= "CC"; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | push(@vars, 0x00, 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (!$cnt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $templ .= "CC"; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | push @vars, 0x00, 0x00; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $templ .= "C"; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | push @vars, 0x00; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $msg = pack $templ, @vars; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($self->{_secret}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my ($hi, $lo) = siphash($msg, pack("a16", $self->{_secret})); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $msg .= pack("LL", $hi, $lo); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $addr; | |||||||||||||||||||||||||||||||||||||||||
| 137 | my $port; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if (!$sock) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (@{$self->{_nodes}} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $addr = $self->{_nodes}->[0]->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $port = $self->{_nodes}->[0]->{port}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my ($node) = grep { $_->{label} eq $self->{_chash}->lookup($key) } @{$self->{_nodes}}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($node) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $addr = $node->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $port = $node->{port}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $index = rand() % @{$self->{_nodes}}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $addr = $self->{_nodes}->[$index]->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $port = $self->{_nodes}->[$index]->{port}; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if (!$self->{_sock}->{"$addr:$port"} || !$self->{_sock}->{"$addr:$port"}->connected || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $self->{"_sock"}{"${addr}:$port"} && $self->{"_sock"}{"${addr}:$port"}->connected or $self->{"_sock"}{"${addr}:$port"}->write("\220") != 1
$self->{'_sock'}{"${addr}:$port"} && $self->{'_sock'}{"${addr}:$port"}->connected
MC/DC0%0/3
not $self->{"_sock"}{"${addr}:$port"} && $self->{"_sock"}{"${addr}:$port"}->connected or $self->{"_sock"}{"${addr}:$port"}->write("\220") != 1
$self->{'_sock'}{"${addr}:$port"}
$self->{'_sock'}{"${addr}:$port"}->connected
$self->{"_sock"}{"${addr}:$port"}->write("\220") != 1
Truth table0%0/4
not(A && B) or C
A= $self->{'_sock'}{"${addr}:$port"}B= $self->{'_sock'}{"${addr}:$port"}->connectedC= $self->{"_sock"}{"${addr}:$port"}->write("\220") != 1
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | $self->{_sock}->{"$addr:$port"}->write(pack("C1", 0x90)) != 1) | ||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->{_sock}->{"$addr:$port"} = IO::Socket::INET->new(PeerAddr => $addr, | |||||||||||||||||||||||||||||||||||||||||
| 160 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | Proto => 'tcp'); | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $sock = $self->{_sock}->{"$addr:$port"}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | return unless $sock->write(pack("C4", 0x73, 0x68, 0x63, 0x01)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($self->{_secret}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return undef unless $sock->write(pack("C", 0xF0)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $wb = $sock->write($msg); | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # read the response | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $in; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # read the magic | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $magic = _read_bytes($sock, 4); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (!$magic) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # read the signature if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($self->{_secret}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $byte = _read_bytes($sock, 1); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if (!$byte) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if (unpack("C", $byte) != 0xF0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # read the header | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $data = _read_bytes($sock, 1); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if (!$data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if (unpack("C", $data) == 0xF0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $in .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $stop = 0; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | # read the records | ||||||||||||||||||||||||||||||||||||||||||
| 216 | my @output_records; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | while (!$stop) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | unless ($data = _read_bytes($sock, 2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my ($len) = unpack("n", $data); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | while ($len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $in .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | unless ($data = _read_bytes($sock, $len)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $in .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $out .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | unless ($data = _read_bytes($sock, 2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ($len) = unpack("n", $data); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $in .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | unless ($data = _read_bytes($sock, 1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $in .= $data; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($sep) = unpack("C", $data); | |||||||||||||||||||||||||||||||||||||||||
| 246 | # TODO - should check if it's a correct rsep (0x80) | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $stop = 1 if ($sep == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | push(@output_records, $out); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | undef($out); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ($self->{_secret}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | # now that we have the whole message, let's compute the signature | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # (we know it's 8 bytes long and is the trailer of the message | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my ($hi, $lo) = siphash(substr($in, 0, length($in)), pack("a16", $self->{_secret})); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $csig = pack("LL", $hi, $lo); | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | unless ($data = _read_bytes($sock, 8)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ($csig ne $data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | delete $self->{_sock}->{"$addr:$port"} if ($addr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | return wantarray ? @output_records : $output_records[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return $self->send_msg(0x01, $key); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub offset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offset: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my ($self, $key, $offset, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return $self->send_msg(0x06, [$key, pack("N", $offset), pack("N", $len)]); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ($self, $key, $value, $expire) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return unless $key && defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key and defined $value
MC/DC0%0/2
$key and defined $value
$key
defined $value
Truth table0%0/3
A and B
A= $keyB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my @records = ($key, $value); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | push(@records, pack("N", $expire)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | if ($expire); | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $resp = $self->send_msg(0x02, \@records); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | return (defined $resp && unpack("C", $resp) == 0x00); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $resp && unpack('C', $resp) == 0
MC/DC0%0/2
defined $resp && unpack('C', $resp) == 0
defined $resp
unpack('C', $resp) == 0
Truth table0%0/3
A && B
A= defined $respB= unpack('C', $resp) == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my ($self, $key, $value, $expire) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return unless $key && defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key and defined $value
MC/DC0%0/2
$key and defined $value
$key
defined $value
Truth table0%0/3
A and B
A= $keyB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my @records = ($key, $value); | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | push(@records, pack("N", $expire)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | if ($expire); | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $resp = $self->send_msg(0x07, \@records); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | return (defined $resp && unpack("C", $resp) == 0x00); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $resp && unpack('C', $resp) == 0
MC/DC0%0/2
defined $resp && unpack('C', $resp) == 0
defined $resp
unpack('C', $resp) == 0
Truth table0%0/3
A && B
A= defined $respB= unpack('C', $resp) == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub del { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $resp = $self->send_msg(0x03, $key); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return (unpack("C", $resp) == 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub evi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evi: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $resp = $self->send_msg(0x04, $key); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return (unpack("C", $resp) == 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub evict { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evict: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return $self->evi(@_); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub mgb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mgb: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | # TODO - nodes-list must be sent together with the MGB command | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $resp = $self->send_msg(0x22, $key); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return (unpack("C", $resp) == 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub migration_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
migration_begin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $self->mgb(@_); | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub mge { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mge: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $resp = $self->send_msg(0x23, $key); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return (unpack("C", $resp) == 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub migration_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
migration_end: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | return $self->mge(@_); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | sub mga { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mga: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return unless $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $resp = $self->send_msg(0x21, $key); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | return (unpack("C", $resp) == 0x00); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub migration_abort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
migration_abort: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return $self->mga(@_); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | sub _get_sock_key_for_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sock_key_for_node: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $addr; | |||||||||||||||||||||||||||||||||||||||||
| 367 | my $port; | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if (@{$self->{_nodes}} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $addr = $self->{_nodes}->[0]->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $port = $self->{_nodes}->[0]->{port}; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($node) = grep { $_->{label} eq $node } @{$self->{_nodes}}; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | if ($node) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $addr = $node->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $port = $node->{port}; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | return "$addr:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | sub _get_sock_for_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sock_for_node: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $sock_key = $self->_get_sock_key_for_node($node); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (!$self->{_sock}->{$sock_key} || !$self->{_sock}->{$sock_key}->connected || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $self->{"_sock"}{$sock_key} && $self->{"_sock"}{$sock_key}->connected or $self->{"_sock"}{$sock_key}->write("\220") != 1
$self->{'_sock'}{$sock_key} && $self->{'_sock'}{$sock_key}->connected
MC/DC0%0/3
not $self->{"_sock"}{$sock_key} && $self->{"_sock"}{$sock_key}->connected or $self->{"_sock"}{$sock_key}->write("\220") != 1
$self->{'_sock'}{$sock_key}
$self->{'_sock'}{$sock_key}->connected
$self->{"_sock"}{$sock_key}->write("\220") != 1
Truth table0%0/4
not(A && B) or C
A= $self->{'_sock'}{$sock_key}B= $self->{'_sock'}{$sock_key}->connectedC= $self->{"_sock"}{$sock_key}->write("\220") != 1
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | $self->{_sock}->{$sock_key}->write(pack("C1", 0x90)) != 1) | ||||||||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my ($addr, $port) = split(':', $sock_key); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->{_sock}->{$sock_key} = IO::Socket::INET->new( | |||||||||||||||||||||||||||||||||||||||||
| 394 | PeerAddr => $addr, | ||||||||||||||||||||||||||||||||||||||||||
| 395 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 396 | Proto => 'tcp'); | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | return $self->{_sock}->{$sock_key}; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub _delete_sock_for_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete_sock_for_node: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my $sock_key = $self->_get_sock_key_for_node($node); | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | delete $self->{_sock}->{$sock_key}; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | sub index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my %index; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | my @nodes = $node | ||||||||||||||||||||||||||||||||||||||||||
| 416 | ? ($node) | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | : map { $_->{label} } @{$self->{_nodes}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | foreach my $n (@nodes) { | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $sock = $self->_get_sock_for_node($n); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | return unless $sock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $resp = $self->send_msg(0x41, undef, $sock); | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | while (length($resp)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $ksize = unpack("N", $resp); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $resp = substr($resp, 4); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $kdata = unpack("a$ksize", $resp); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $resp = substr($resp, $ksize); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $vlen = unpack("N", $resp); | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $resp = substr($resp, 4); | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | $index{$kdata} = $vlen | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ksize and $kdata
MC/DC0%0/2
$ksize and $kdata
$ksize
$kdata
Truth table0%0/3
A and B
A= $ksizeB= $kdata
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | if ($ksize && $kdata); | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | return wantarray ? %index : \%index; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $sock = $self->_get_sock_for_node($node); | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | return unless $sock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $resp = $self->send_msg(0x31, undef, $sock); | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | $self->_delete_sock_for_node($node) unless $resp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | return $resp ? (unpack("C", $resp) == 0x00) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub chk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chk: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 454 | # XXX - deprecated | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | return $self->check(@_); | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $sock = $self->_get_sock_for_node($node); | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | return unless $sock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $resp = $self->send_msg(0x32, undef, $sock); | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | $self->_delete_sock_for_node($node) unless $resp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return $resp; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub sts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sts: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 473 | # XXX - deprecated | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return $self->status(@_); | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 478 | __END__ | ||||||||||||||||||||||||||||||||||||||||||