| 1 | package Unblock::HTTP::QUIC; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Scalar::Util qw(refaddr blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | sub client { return shift->_new('Client', @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | sub server { return shift->_new('Server', @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=18 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | my ($class, $role, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | croak 'client()/server(): expected named arguments' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | my %option = @args; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | my $on_ready = delete $option{on_ready}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | croak 'on_ready must be a coderef' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_ready and ref $on_ready ne "CODE"
MC/DC0%0/2
defined $on_ready and ref $on_ready ne "CODE"
defined $on_ready
ref $on_ready ne "CODE"
Truth table66%2/3
A and B
A= defined $on_readyB= ref $on_ready ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | if defined($on_ready) && ref($on_ready) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | my ($server, $http3); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | if ($role eq 'Server') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | $server = delete $option{server}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | croak 'server(): server must be a reusable Unblock::HTTP::Server' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($server) and $server->isa("Unblock::HTTP::Server")
MC/DC50%1/2
builtin::blessed($server) and $server->isa("Unblock::HTTP::Server")
builtin::blessed($server)
$server->isa("Unblock::HTTP::Server")
Truth table66%2/3
A and B
A= builtin::blessed($server)B= $server->isa("Unblock::HTTP::Server")
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | unless blessed($server) && $server->isa('Unblock::HTTP::Server'); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | croak 'server(): HTTP/3 is disabled on the Server definition' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | unless $server->supports('h3'); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | for my $reserved (qw(http3 on_headers on_request on_body on_request_end on_error)) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | croak "server(): configure $reserved on the Server definition" | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | if exists $option{$reserved}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $http3 = {}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | croak 'client(): server is not a client option' if exists $option{server}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | $http3 = exists($option{http3}) ? delete $option{http3} : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | croak 'http3 must be a hash reference' unless ref($http3) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | $http3 = { %$http3 }; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | for my $reserved (qw(quic transport protocol alpn)) { | |||||||||||||||||||||||||||||||||||||||||
| 40 | croak "http3 option '$reserved' is managed by Unblock::HTTP::QUIC" | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | ▶ | if exists $http3->{$reserved}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $alpn = delete $option{alpn}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | croak "Only the h3 ALPN is supported by Unblock::HTTP::QUIC" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $alpn and $alpn ne "h3"
MC/DC50%1/2
defined $alpn and $alpn ne "h3"
defined $alpn
$alpn ne "h3"
Truth table66%2/3
A and B
A= defined $alpnB= $alpn ne "h3"
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if defined($alpn) && $alpn ne 'h3'; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | $option{alpn} = 'h3'; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | require Net::QUIC::Driver; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | my $driver = $role eq 'Client' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | ? Net::QUIC::Driver->client(%option) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | : Net::QUIC::Driver->server(%option); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 56 | role => $role, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | driver => $driver, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | http3 => $http3, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | server => $server, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | on_ready => $on_ready, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | sessions => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | client_id => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | sub driver { return $_[0]{driver}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
driver: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | $self->{driver}->start; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | $self->_progress; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | sub receive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
receive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | $self->{driver}->receive(@arg); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | $self->_progress; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | sub timeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | $self->{driver}->timeout; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | $self->_progress; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | sub writable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | $self->{driver}->writable; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | $self->_progress; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | sub session { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | croak 'session(): only valid for a client QUIC manager' | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | ▶ | unless $self->{role} eq 'Client'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my $id = $self->{client_id}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | return defined($id) && exists($self->{sessions}{$id}) | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | ▶ | ? $self->{sessions}{$id}{http} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $id and exists $self->{"sessions"}{$id}
MC/DC50%1/2
defined $id and exists $self->{"sessions"}{$id}
defined $id
exists $self->{"sessions"}{$id}
Truth table66%2/3
A and B
A= defined $idB= exists $self->{"sessions"}{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | ▶ | sub sessions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sessions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | return grep { defined $_ } map { $_->{http} } values %{ $self->{sessions} }; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | ▶ | sub _remember { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remember: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | my ($self, $quic) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | ▶ | return unless defined $quic; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 8 | my $id = refaddr($quic); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | $self->{sessions}{$id} ||= { quic => $quic, http => undef }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"sessions"}{$id} ||= {"quic", $quic, "http", undef}
MC/DC100%1/1
$self->{"sessions"}{$id} ||= {"quic", $quic, "http", undef}
$self->{"sessions"}{$id}
Truth table100%2/2
A
A= $self->{"sessions"}{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | $self->{client_id} = $id if $self->{role} eq 'Client'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | ▶ | sub _progress { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_progress: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | my $driver = $self->{driver}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 | ▶ | if ($self->{role} eq 'Client') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $self->_remember($driver->connection); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | ▶ | while (my $quic = $driver->next_connection) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | $self->_remember($quic); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | for my $id (keys %{ $self->{sessions} }) { | |||||||||||||||||||||||||||||||||||||||||
| 132 | 21 | my $record = $self->{sessions}{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 21 | my $quic = $record->{quic}; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 21 | ▶ | if ($quic->closed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | delete $self->{sessions}{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 19 | ▶ | next if $record->{http} || $record->{attaching} || !$quic->ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$record->{"http"} or $record->{"attaching"} or not $quic->ready
$record->{"http"} or $record->{"attaching"}
MC/DC100%3/3
$record->{"http"} or $record->{"attaching"} or not $quic->ready
$record->{"http"}
$record->{"attaching"}
not $quic->ready
Truth table100%4/4
A or B or not(C)
A= $record->{"http"}B= $record->{"attaching"}C= not $quic->ready
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | local $record->{attaching} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | my $http; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | if ($self->{role} eq 'Server') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | $http = $self->{server}->attach_quic(connection => $quic); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | require Unblock::HTTP::_EngineFactory; | |||||||||||||||||||||||||||||||||||||||||
| 146 | $http = Unblock::HTTP::_EngineFactory->create( | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | 'Client', 'h3', quic => $quic, %{ $self->{http3} }, | |||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $http->start; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | ▶ | if ($quic->closed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | delete $self->{sessions}{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | $record->{http} = $http; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | $self->{on_ready}->($http, $self) if $self->{on_ready}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | __END__ | ||||||||||||||||||||||||||||||||||||||||||