Net-QUIC
view release on metacpan or search on metacpan
lib/Net/QUIC/Endpoint.pm view on Meta::CPAN
croak "session_ticket and early_data cannot be used together"
if defined $session_ticket;
($session_ticket, $early_transport) =
Net::QUIC::Connection->_decode_early_data_state($early_data);
}
if (defined $session_ticket) {
my $ticket_version;
($session_ticket, $ticket_version) =
Net::QUIC::Connection->_decode_session_ticket($session_ticket);
$saved_version = $ticket_version;
}
if (defined $address_token) {
my $token_version;
($address_token, $token_version) =
Net::QUIC::Connection->_decode_address_token($address_token);
croak "saved session and address token QUIC versions do not match"
if defined($saved_version)
&& $saved_version != $token_version;
$saved_version = $token_version;
}
my $version = $class->_quic_version(
$version_arg,
'version',
defined($saved_version) ? $saved_version : 1,
);
croak "saved QUIC state belongs to version $saved_version, not version $version"
if defined($saved_version) && $version != $saved_version;
my $version_locked = defined($saved_version) ? 1 : 0;
my $connection = Net::QUIC::Connection->_client_new(
$args{local},
$args{peer},
$args{alpn},
$args{server_name},
$ca_file,
$transport,
$session_ticket,
$early_transport,
$address_token,
$version,
$version_locked,
);
return bless {
mode => 'client',
connection => $connection,
}, $class;
}
sub server {
my ($class, %args) = @_;
for my $name (qw(alpn certificate_file private_key_file)) {
croak "missing required $name argument"
if !defined $args{$name};
}
my $server_tls = Net::QUIC::_ServerTLS->_new(
$args{certificate_file},
$args{private_key_file},
$args{accept_early_data} ? 1 : 0,
);
my $transport = $class->_transport_config(delete $args{transport});
my $preferred_address = delete $args{preferred_address};
my $preferred_version = delete $args{preferred_version};
$preferred_version = $class->_quic_version(
$preferred_version,
'preferred_version',
undef,
) if defined $preferred_version;
$class->_require_concrete_local($preferred_address)
if defined $preferred_address;
return bless {
mode => 'server',
alpn => $args{alpn},
server_tls => $server_tls,
cid_length => $class->_server_cid_length,
server_secret => $class->_server_secret,
validate_address => $args{validate_address} ? 1 : 0,
preferred_address => $preferred_address,
preferred_version => $preferred_version,
transport => $transport,
stateless_tx => [],
routes => {},
connections => [],
pending_connections => [],
tx_cursor => 0,
}, $class;
}
sub _sync_server_routes {
my ($self, $connection) = @_;
while (my $event = $connection->_take_cid_event) {
my ($add, $cid) = @$event;
if ($add) {
$self->{routes}{$cid} = $connection;
} else {
delete $self->{routes}{$cid};
}
}
return;
}
sub _retire_server_connections {
my ($self) = @_;
my %retired;
for my $connection (@{$self->{connections}}) {
next if !$connection->_retired;
$retired{refaddr($connection)} = 1;
}
return if !%retired;
lib/Net/QUIC/Endpoint.pm view on Meta::CPAN
address_token => $saved_address_token
Attempt 0-RTT early data:
early_data => $saved_early_data_state
C<early_data> already contains its matching session ticket, so it cannot be
combined with C<session_ticket>.
Saved session, address-token, and early-data values are opaque. Net::QUIC
remembers the QUIC version inside them and automatically uses the correct
version.
0-RTT data can be replayed. Only send operations that are safe to repeat.
=head3 Transport limits
Client and server both accept:
transport => {
handshake_timeout => 10,
idle_timeout => 30,
connection_window => 1024 * 1024,
stream_window => 256 * 1024,
max_bidi_streams => 100,
max_uni_streams => 100,
max_datagram_frame_size => 0,
}
These are the defaults.
C<handshake_timeout> is how long the initial connection setup may take.
C<idle_timeout> is how long an otherwise established connection may stay idle.
A value of zero disables the advertised idle timeout.
C<connection_window> is the starting receive allowance for the whole
connection.
C<stream_window> is the starting receive allowance for each Stream.
C<max_bidi_streams> and C<max_uni_streams> are the initial numbers of
peer-created streams that may exist at once.
C<max_datagram_frame_size> advertises this endpoint's RFC 9221 QUIC DATAGRAM
receive limit. Zero disables QUIC DATAGRAM receive support. A value such as
65535 enables it while the actual sendable payload is still limited by the
peer and the current network path.
See L<Net::QUIC::Connection/QUIC DATAGRAM>.
The Stream values are flow-control starting values, not lifetime byte or
stream limits.
=head2 server
my $endpoint = Net::QUIC::Endpoint->server(
alpn => 'my-protocol',
certificate_file => 'server-cert.pem',
private_key_file => 'server-key.pem',
);
Creates a server Endpoint.
One server Endpoint can manage many QUIC Connections.
Required options are:
alpn
certificate_file
private_key_file
=head3 Address validation
To require a new client to prove that it can receive packets at its source
address:
validate_address => 1
A new client may receive QUIC Retry before a full Connection is created.
After a validated handshake, Net::QUIC can issue NEW_TOKEN so a returning
client can prove the same address without another Retry round trip.
The client exposes that opaque value through
L<Net::QUIC::Connection/address_token>.
=head3 0-RTT
To allow replayable early data:
accept_early_data => 1
Only enable this when the application knows how to handle operations that may
be repeated.
=head3 QUIC version preference
A server accepts QUIC v1 and v2.
To prefer v2 when a compatible client starts with v1:
preferred_version => 2
If this option is omitted, the server keeps the client's chosen supported
version.
=head3 Preferred server address
A server can advertise another address for the same Connection:
preferred_address => $packed_server_address
The client validates that path before switching to it.
The UDP integration must actually be able to send and receive on the advertised
address.
=head2 connection
my $connection = $endpoint->connection;
Client only.
Returns the client's Connection.
A server manages many Connections, so server code uses
L</next_connection> instead.
=head2 next_connection
( run in 1.201 second using v1.01-cache-2.11-cpan-036bef1c656 )