2022-04-11 00:21:37 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2022-04-11 00:21:37 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2022-04-11 00:21:37 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "curl_setup.h"
|
|
|
|
|
|
|
|
#ifdef USE_MSH3
|
|
|
|
|
|
|
|
#include "urldata.h"
|
2024-03-27 22:01:06 +08:00
|
|
|
#include "hash.h"
|
2022-04-11 00:21:37 +08:00
|
|
|
#include "timeval.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "sendf.h"
|
2023-08-03 23:32:25 +08:00
|
|
|
#include "curl_trc.h"
|
2022-12-30 16:14:55 +08:00
|
|
|
#include "cfilters.h"
|
2023-01-02 21:08:16 +08:00
|
|
|
#include "cf-socket.h"
|
2022-04-11 00:21:37 +08:00
|
|
|
#include "connect.h"
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
#include "progress.h"
|
2023-04-14 17:38:14 +08:00
|
|
|
#include "http1.h"
|
2023-01-06 02:23:21 +08:00
|
|
|
#include "curl_msh3.h"
|
2023-01-02 21:08:16 +08:00
|
|
|
#include "socketpair.h"
|
2023-10-26 17:27:42 +08:00
|
|
|
#include "vtls/vtls.h"
|
2023-01-11 17:30:42 +08:00
|
|
|
#include "vquic/vquic.h"
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2022-08-12 20:22:03 +08:00
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
2023-11-02 18:40:59 +08:00
|
|
|
#ifdef CURL_DISABLE_SOCKETPAIR
|
|
|
|
#error "MSH3 cannot be build with CURL_DISABLE_SOCKETPAIR set"
|
|
|
|
#endif
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
#define H3_STREAM_WINDOW_SIZE (128 * 1024)
|
|
|
|
#define H3_STREAM_CHUNK_SIZE (16 * 1024)
|
|
|
|
#define H3_STREAM_RECV_CHUNKS \
|
|
|
|
(H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE)
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define msh3_lock CRITICAL_SECTION
|
|
|
|
#define msh3_lock_initialize(lock) InitializeCriticalSection(lock)
|
|
|
|
#define msh3_lock_uninitialize(lock) DeleteCriticalSection(lock)
|
|
|
|
#define msh3_lock_acquire(lock) EnterCriticalSection(lock)
|
|
|
|
#define msh3_lock_release(lock) LeaveCriticalSection(lock)
|
|
|
|
#else /* !_WIN32 */
|
|
|
|
#include <pthread.h>
|
|
|
|
#define msh3_lock pthread_mutex_t
|
|
|
|
#define msh3_lock_initialize(lock) do { \
|
|
|
|
pthread_mutexattr_t attr; \
|
|
|
|
pthread_mutexattr_init(&attr); \
|
|
|
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
|
|
|
|
pthread_mutex_init(lock, &attr); \
|
|
|
|
pthread_mutexattr_destroy(&attr); \
|
|
|
|
}while(0)
|
|
|
|
#define msh3_lock_uninitialize(lock) pthread_mutex_destroy(lock)
|
|
|
|
#define msh3_lock_acquire(lock) pthread_mutex_lock(lock)
|
|
|
|
#define msh3_lock_release(lock) pthread_mutex_unlock(lock)
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static void MSH3_CALL msh3_conn_connected(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext);
|
|
|
|
static void MSH3_CALL msh3_conn_shutdown_complete(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext);
|
|
|
|
static void MSH3_CALL msh3_conn_new_request(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext,
|
|
|
|
MSH3_REQUEST *Request);
|
2022-04-11 00:21:37 +08:00
|
|
|
static void MSH3_CALL msh3_header_received(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext,
|
|
|
|
const MSH3_HEADER *Header);
|
2023-01-08 23:23:21 +08:00
|
|
|
static bool MSH3_CALL msh3_data_received(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext, uint32_t *Length,
|
2022-04-11 00:21:37 +08:00
|
|
|
const uint8_t *Data);
|
|
|
|
static void MSH3_CALL msh3_complete(MSH3_REQUEST *Request, void *IfContext,
|
|
|
|
bool Aborted, uint64_t AbortError);
|
2023-01-08 23:23:21 +08:00
|
|
|
static void MSH3_CALL msh3_shutdown_complete(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext);
|
|
|
|
static void MSH3_CALL msh3_data_sent(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext, void *SendContext);
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
|
|
|
|
void Curl_msh3_ver(char *p, size_t len)
|
|
|
|
{
|
|
|
|
uint32_t v[4];
|
|
|
|
MsH3Version(v);
|
|
|
|
(void)msnprintf(p, len, "msh3/%d.%d.%d.%d", v[0], v[1], v[2], v[3]);
|
|
|
|
}
|
|
|
|
|
2023-01-02 21:08:16 +08:00
|
|
|
#define SP_LOCAL 0
|
|
|
|
#define SP_REMOTE 1
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
struct cf_msh3_ctx {
|
|
|
|
MSH3_API *api;
|
|
|
|
MSH3_CONNECTION *qconn;
|
2023-01-02 21:08:16 +08:00
|
|
|
struct Curl_sockaddr_ex addr;
|
|
|
|
curl_socket_t sock[2]; /* fake socket pair until we get support in msh3 */
|
|
|
|
char l_ip[MAX_IPADR_LEN]; /* local IP as string */
|
|
|
|
int l_port; /* local port number */
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data call_data;
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
struct curltime connect_started; /* time the current attempt started */
|
|
|
|
struct curltime handshake_at; /* time connect handshake finished */
|
2024-03-27 22:01:06 +08:00
|
|
|
struct Curl_hash streams; /* hash `data->id` to `stream_ctx` */
|
2023-01-08 23:23:21 +08:00
|
|
|
/* Flags written by msh3/msquic thread */
|
|
|
|
bool handshake_complete;
|
|
|
|
bool handshake_succeeded;
|
|
|
|
bool connected;
|
|
|
|
/* Flags written by curl thread */
|
|
|
|
BIT(verbose);
|
2023-01-02 21:08:16 +08:00
|
|
|
BIT(active);
|
2022-04-11 00:21:37 +08:00
|
|
|
};
|
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
static struct cf_msh3_ctx *h3_get_msh3_ctx(struct Curl_easy *data);
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
/* How to access `call_data` from a cf_msh3 filter */
|
2023-05-09 18:10:40 +08:00
|
|
|
#undef CF_CTX_CALL_DATA
|
2023-03-30 19:00:51 +08:00
|
|
|
#define CF_CTX_CALL_DATA(cf) \
|
|
|
|
((struct cf_msh3_ctx *)(cf)->ctx)->call_data
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All about the H3 internals of a stream
|
|
|
|
*/
|
|
|
|
struct stream_ctx {
|
|
|
|
struct MSH3_REQUEST *req;
|
|
|
|
struct bufq recvbuf; /* h3 response */
|
|
|
|
#ifdef _WIN32
|
|
|
|
CRITICAL_SECTION recv_lock;
|
|
|
|
#else /* !_WIN32 */
|
|
|
|
pthread_mutex_t recv_lock;
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
uint64_t error3; /* HTTP/3 stream error code */
|
|
|
|
int status_code; /* HTTP status code */
|
|
|
|
CURLcode recv_error;
|
|
|
|
bool closed;
|
|
|
|
bool reset;
|
|
|
|
bool upload_done;
|
|
|
|
bool firstheader; /* FALSE until headers arrive */
|
|
|
|
bool recv_header_complete;
|
|
|
|
};
|
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
#define H3_STREAM_CTX(ctx,data) ((struct stream_ctx *)((data && ctx)? \
|
|
|
|
Curl_hash_offt_get(&(ctx)->streams, (data)->id) : NULL))
|
|
|
|
|
|
|
|
static void h3_stream_ctx_free(struct stream_ctx *stream)
|
|
|
|
{
|
|
|
|
Curl_bufq_free(&stream->recvbuf);
|
|
|
|
free(stream);
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
static void h3_stream_hash_free(void *stream)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(stream);
|
|
|
|
h3_stream_ctx_free((struct stream_ctx *)stream);
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
static CURLcode h3_data_setup(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
if(stream)
|
|
|
|
return CURLE_OK;
|
|
|
|
|
|
|
|
stream = calloc(1, sizeof(*stream));
|
|
|
|
if(!stream)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
stream->req = ZERO_NULL;
|
|
|
|
msh3_lock_initialize(&stream->recv_lock);
|
|
|
|
Curl_bufq_init2(&stream->recvbuf, H3_STREAM_CHUNK_SIZE,
|
|
|
|
H3_STREAM_RECV_CHUNKS, BUFQ_OPT_SOFT_LIMIT);
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "data setup");
|
2024-03-27 22:01:06 +08:00
|
|
|
|
|
|
|
if(!Curl_hash_offt_set(&ctx->streams, data->id, stream)) {
|
|
|
|
h3_stream_ctx_free(stream);
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
(void)cf;
|
|
|
|
if(stream) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "easy handle is done");
|
2024-03-27 22:01:06 +08:00
|
|
|
Curl_hash_offt_remove(&ctx->streams, data->id);
|
2023-03-30 19:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:04:46 +08:00
|
|
|
static void drain_stream_from_other_thread(struct Curl_easy *data,
|
|
|
|
struct stream_ctx *stream)
|
|
|
|
{
|
2023-04-26 00:04:46 +08:00
|
|
|
unsigned char bits;
|
2023-04-21 18:04:46 +08:00
|
|
|
|
|
|
|
/* risky */
|
|
|
|
bits = CURL_CSELECT_IN;
|
|
|
|
if(stream && !stream->upload_done)
|
|
|
|
bits |= CURL_CSELECT_OUT;
|
2023-12-13 18:25:20 +08:00
|
|
|
if(data->state.select_bits != bits) {
|
|
|
|
data->state.select_bits = bits;
|
2023-04-21 18:04:46 +08:00
|
|
|
/* cannot expire from other thread */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drain_stream(struct Curl_cfilter *cf,
|
2023-03-30 19:00:51 +08:00
|
|
|
struct Curl_easy *data)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-04-26 00:04:46 +08:00
|
|
|
unsigned char bits;
|
2023-04-21 18:04:46 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
(void)cf;
|
2023-04-21 18:04:46 +08:00
|
|
|
bits = CURL_CSELECT_IN;
|
|
|
|
if(stream && !stream->upload_done)
|
|
|
|
bits |= CURL_CSELECT_OUT;
|
2023-12-13 18:25:20 +08:00
|
|
|
if(data->state.select_bits != bits) {
|
|
|
|
data->state.select_bits = bits;
|
2023-03-30 19:00:51 +08:00
|
|
|
Curl_expire(data, 0, EXPIRE_RUN_NOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static const MSH3_CONNECTION_IF msh3_conn_if = {
|
|
|
|
msh3_conn_connected,
|
|
|
|
msh3_conn_shutdown_complete,
|
|
|
|
msh3_conn_new_request
|
|
|
|
};
|
|
|
|
|
|
|
|
static void MSH3_CALL msh3_conn_connected(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext)
|
|
|
|
{
|
2023-03-30 19:00:51 +08:00
|
|
|
struct Curl_cfilter *cf = IfContext;
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct Curl_easy *data = CF_DATA_CURRENT(cf);
|
2023-01-08 23:23:21 +08:00
|
|
|
(void)Connection;
|
2023-03-30 19:00:51 +08:00
|
|
|
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "[MSH3] connected");
|
2023-01-08 23:23:21 +08:00
|
|
|
ctx->handshake_succeeded = true;
|
|
|
|
ctx->connected = true;
|
|
|
|
ctx->handshake_complete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MSH3_CALL msh3_conn_shutdown_complete(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext)
|
|
|
|
{
|
2023-03-30 19:00:51 +08:00
|
|
|
struct Curl_cfilter *cf = IfContext;
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct Curl_easy *data = CF_DATA_CURRENT(cf);
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
(void)Connection;
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "[MSH3] shutdown complete");
|
2023-01-08 23:23:21 +08:00
|
|
|
ctx->connected = false;
|
|
|
|
ctx->handshake_complete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MSH3_CALL msh3_conn_new_request(MSH3_CONNECTION *Connection,
|
|
|
|
void *IfContext,
|
|
|
|
MSH3_REQUEST *Request)
|
|
|
|
{
|
|
|
|
(void)Connection;
|
|
|
|
(void)IfContext;
|
|
|
|
(void)Request;
|
|
|
|
}
|
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
static const MSH3_REQUEST_IF msh3_request_if = {
|
|
|
|
msh3_header_received,
|
|
|
|
msh3_data_received,
|
|
|
|
msh3_complete,
|
2023-01-08 23:23:21 +08:00
|
|
|
msh3_shutdown_complete,
|
|
|
|
msh3_data_sent
|
2022-04-11 00:21:37 +08:00
|
|
|
};
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
/* Decode HTTP status code. Returns -1 if no valid status code was
|
|
|
|
decoded. (duplicate from http2.c) */
|
|
|
|
static int decode_status_code(const char *value, size_t len)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-03-30 19:00:51 +08:00
|
|
|
int i;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if(len != 3) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = 0;
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
for(i = 0; i < 3; ++i) {
|
|
|
|
char c = value[i];
|
|
|
|
|
|
|
|
if(c < '0' || c > '9') {
|
|
|
|
return -1;
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
res *= 10;
|
|
|
|
res += c - '0';
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
return res;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
/*
|
|
|
|
* write_resp_raw() copies response data in raw format to the `data`'s
|
|
|
|
* receive buffer. If not enough space is available, it appends to the
|
|
|
|
* `data`'s overflow buffer.
|
|
|
|
*/
|
|
|
|
static CURLcode write_resp_raw(struct Curl_easy *data,
|
|
|
|
const void *mem, size_t memlen)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
ssize_t nwritten;
|
|
|
|
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream)
|
|
|
|
return CURLE_RECV_ERROR;
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
nwritten = Curl_bufq_write(&stream->recvbuf, mem, memlen, &result);
|
|
|
|
if(nwritten < 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((size_t)nwritten < memlen) {
|
|
|
|
/* This MUST not happen. Our recbuf is dimensioned to hold the
|
|
|
|
* full max_stream_window and then some for this very reason. */
|
|
|
|
DEBUGASSERT(0);
|
|
|
|
return CURLE_RECV_ERROR;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
return result;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MSH3_CALL msh3_header_received(MSH3_REQUEST *Request,
|
2023-03-30 19:00:51 +08:00
|
|
|
void *userp,
|
|
|
|
const MSH3_HEADER *hd)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-03-30 19:00:51 +08:00
|
|
|
struct Curl_easy *data = userp;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
CURLcode result;
|
2022-04-11 00:21:37 +08:00
|
|
|
(void)Request;
|
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
DEBUGF(infof(data, "[MSH3] header received, stream=%d", !!stream));
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream || stream->recv_header_complete) {
|
2022-04-11 00:21:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msh3_lock_acquire(&stream->recv_lock);
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
if((hd->NameLength == 7) &&
|
2023-04-14 17:38:14 +08:00
|
|
|
!strncmp(HTTP_PSEUDO_STATUS, (char *)hd->Name, 7)) {
|
2023-03-30 19:00:51 +08:00
|
|
|
char line[14]; /* status line is always 13 characters long */
|
|
|
|
size_t ncopy;
|
|
|
|
|
|
|
|
DEBUGASSERT(!stream->firstheader);
|
|
|
|
stream->status_code = decode_status_code(hd->Value, hd->ValueLength);
|
|
|
|
DEBUGASSERT(stream->status_code != -1);
|
|
|
|
ncopy = msnprintf(line, sizeof(line), "HTTP/3 %03d \r\n",
|
|
|
|
stream->status_code);
|
|
|
|
result = write_resp_raw(data, line, ncopy);
|
|
|
|
if(result)
|
|
|
|
stream->recv_error = result;
|
|
|
|
stream->firstheader = TRUE;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-03-30 19:00:51 +08:00
|
|
|
/* store as an HTTP1-style header */
|
|
|
|
DEBUGASSERT(stream->firstheader);
|
|
|
|
result = write_resp_raw(data, hd->Name, hd->NameLength);
|
|
|
|
if(!result)
|
|
|
|
result = write_resp_raw(data, ": ", 2);
|
|
|
|
if(!result)
|
|
|
|
result = write_resp_raw(data, hd->Value, hd->ValueLength);
|
|
|
|
if(!result)
|
|
|
|
result = write_resp_raw(data, "\r\n", 2);
|
|
|
|
if(result) {
|
|
|
|
stream->recv_error = result;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:04:46 +08:00
|
|
|
drain_stream_from_other_thread(data, stream);
|
2022-04-11 00:21:37 +08:00
|
|
|
msh3_lock_release(&stream->recv_lock);
|
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static bool MSH3_CALL msh3_data_received(MSH3_REQUEST *Request,
|
2023-03-30 19:00:51 +08:00
|
|
|
void *IfContext, uint32_t *buflen,
|
|
|
|
const uint8_t *buf)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-01-02 21:08:16 +08:00
|
|
|
struct Curl_easy *data = IfContext;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
CURLcode result;
|
|
|
|
bool rv = FALSE;
|
|
|
|
|
|
|
|
/* TODO: we would like to limit the amount of data we are buffer here.
|
|
|
|
* There seems to be no mechanism in msh3 to adjust flow control and
|
|
|
|
* it is undocumented what happens if we return FALSE here or less
|
|
|
|
* length (buflen is an inout parameter).
|
|
|
|
*/
|
2022-04-11 00:21:37 +08:00
|
|
|
(void)Request;
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
msh3_lock_acquire(&stream->recv_lock);
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
if(!stream->recv_header_complete) {
|
2023-03-30 19:00:51 +08:00
|
|
|
result = write_resp_raw(data, "\r\n", 2);
|
|
|
|
if(result) {
|
|
|
|
stream->recv_error = result;
|
|
|
|
goto out;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
stream->recv_header_complete = true;
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
result = write_resp_raw(data, buf, *buflen);
|
|
|
|
if(result) {
|
|
|
|
stream->recv_error = result;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
rv = TRUE;
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
out:
|
2022-04-11 00:21:37 +08:00
|
|
|
msh3_lock_release(&stream->recv_lock);
|
2023-03-30 19:00:51 +08:00
|
|
|
return rv;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MSH3_CALL msh3_complete(MSH3_REQUEST *Request, void *IfContext,
|
2023-03-30 19:00:51 +08:00
|
|
|
bool aborted, uint64_t error)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-01-02 21:08:16 +08:00
|
|
|
struct Curl_easy *data = IfContext;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
(void)Request;
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream)
|
|
|
|
return;
|
2022-04-11 00:21:37 +08:00
|
|
|
msh3_lock_acquire(&stream->recv_lock);
|
2023-03-30 19:00:51 +08:00
|
|
|
stream->closed = TRUE;
|
2022-04-11 00:21:37 +08:00
|
|
|
stream->recv_header_complete = true;
|
2023-03-30 19:00:51 +08:00
|
|
|
if(error)
|
|
|
|
stream->error3 = error;
|
|
|
|
if(aborted)
|
|
|
|
stream->reset = TRUE;
|
2022-04-11 00:21:37 +08:00
|
|
|
msh3_lock_release(&stream->recv_lock);
|
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static void MSH3_CALL msh3_shutdown_complete(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-01-02 21:08:16 +08:00
|
|
|
struct Curl_easy *data = IfContext;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-04-13 17:03:50 +08:00
|
|
|
|
|
|
|
if(!stream)
|
|
|
|
return;
|
2022-04-11 00:21:37 +08:00
|
|
|
(void)Request;
|
|
|
|
(void)stream;
|
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static void MSH3_CALL msh3_data_sent(MSH3_REQUEST *Request,
|
|
|
|
void *IfContext, void *SendContext)
|
2022-12-21 22:13:40 +08:00
|
|
|
{
|
2023-01-02 21:08:16 +08:00
|
|
|
struct Curl_easy *data = IfContext;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data);
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream)
|
|
|
|
return;
|
2022-12-21 22:13:40 +08:00
|
|
|
(void)Request;
|
|
|
|
(void)stream;
|
|
|
|
(void)SendContext;
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
static ssize_t recv_closed_stream(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
CURLcode *err)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
ssize_t nread = -1;
|
|
|
|
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream) {
|
|
|
|
*err = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
(void)cf;
|
|
|
|
if(stream->reset) {
|
|
|
|
failf(data, "HTTP/3 stream reset by server");
|
|
|
|
*err = CURLE_PARTIAL_FILE;
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_recv, was reset -> %d", *err);
|
2023-03-30 19:00:51 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else if(stream->error3) {
|
|
|
|
failf(data, "HTTP/3 stream was not closed cleanly: (error %zd)",
|
|
|
|
(ssize_t)stream->error3);
|
|
|
|
*err = CURLE_HTTP3;
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_recv, closed uncleanly -> %d", *err);
|
2023-03-30 19:00:51 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_recv, closed ok -> %d", *err);
|
2023-03-30 19:00:51 +08:00
|
|
|
}
|
|
|
|
*err = CURLE_OK;
|
|
|
|
nread = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_quic_expire(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
/* we have no indication from msh3 when it would be a good time
|
|
|
|
* to juggle the connection again. So, we compromise by calling
|
|
|
|
* us again every some milliseconds. */
|
|
|
|
(void)cf;
|
|
|
|
if(stream && stream->req && !stream->closed) {
|
|
|
|
Curl_expire(data, 10, EXPIRE_QUIC);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Curl_expire(data, 50, EXPIRE_QUIC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
static ssize_t cf_msh3_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|
|
|
char *buf, size_t len, CURLcode *err)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
ssize_t nread = -1;
|
|
|
|
struct cf_call_data save;
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_recv(len=%zu), stream=%d", len, !!stream);
|
2023-04-13 17:03:50 +08:00
|
|
|
if(!stream) {
|
|
|
|
*err = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_SAVE(save, cf, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
msh3_lock_acquire(&stream->recv_lock);
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
if(stream->recv_error) {
|
|
|
|
failf(data, "request aborted");
|
|
|
|
*err = stream->recv_error;
|
2023-03-30 19:00:51 +08:00
|
|
|
goto out;
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
|
|
|
|
2023-01-02 21:08:16 +08:00
|
|
|
*err = CURLE_OK;
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
if(!Curl_bufq_is_empty(&stream->recvbuf)) {
|
|
|
|
nread = Curl_bufq_read(&stream->recvbuf,
|
|
|
|
(unsigned char *)buf, len, err);
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "read recvbuf(len=%zu) -> %zd, %d",
|
|
|
|
len, nread, *err);
|
2023-03-30 19:00:51 +08:00
|
|
|
if(nread < 0)
|
|
|
|
goto out;
|
2023-04-21 18:04:46 +08:00
|
|
|
if(stream->closed)
|
2023-04-29 00:07:33 +08:00
|
|
|
drain_stream(cf, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
else if(stream->closed) {
|
|
|
|
nread = recv_closed_stream(cf, data, err);
|
|
|
|
goto out;
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "req: nothing here, call again");
|
2023-01-02 21:08:16 +08:00
|
|
|
*err = CURLE_AGAIN;
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
out:
|
2022-12-30 16:14:55 +08:00
|
|
|
msh3_lock_release(&stream->recv_lock);
|
2023-03-30 19:00:51 +08:00
|
|
|
set_quic_expire(cf, data);
|
|
|
|
CF_DATA_RESTORE(cf, save);
|
|
|
|
return nread;
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cf_msh3_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|
|
|
const void *buf, size_t len, CURLcode *err)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2022-12-30 16:14:55 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-04-14 17:38:14 +08:00
|
|
|
struct h1_req_parser h1;
|
|
|
|
struct dynhds h2_headers;
|
|
|
|
MSH3_HEADER *nva = NULL;
|
|
|
|
size_t nheader, i;
|
2023-03-30 19:00:51 +08:00
|
|
|
ssize_t nwritten = -1;
|
|
|
|
struct cf_call_data save;
|
2023-04-14 17:38:14 +08:00
|
|
|
bool eos;
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
CF_DATA_SAVE(save, cf, data);
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2023-05-19 00:22:57 +08:00
|
|
|
Curl_h1_req_parse_init(&h1, H1_PARSE_DEFAULT_MAX_LINE_LEN);
|
2023-04-14 17:38:14 +08:00
|
|
|
Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST);
|
|
|
|
|
2022-09-21 16:36:41 +08:00
|
|
|
/* Sizes must match for cast below to work" */
|
2023-04-13 17:03:50 +08:00
|
|
|
DEBUGASSERT(stream);
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "req: send %zu bytes", len);
|
2022-09-21 16:36:41 +08:00
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
if(!stream->req) {
|
2022-12-28 00:02:56 +08:00
|
|
|
/* The first send on the request contains the headers and possibly some
|
|
|
|
data. Parse out the headers and create the request, then if there is
|
|
|
|
any data left over go ahead and send it too. */
|
2023-04-14 17:38:14 +08:00
|
|
|
nwritten = Curl_h1_req_parse_read(&h1, buf, len, NULL, 0, err);
|
|
|
|
if(nwritten < 0)
|
|
|
|
goto out;
|
|
|
|
DEBUGASSERT(h1.done);
|
|
|
|
DEBUGASSERT(h1.req);
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2023-04-14 17:38:14 +08:00
|
|
|
*err = Curl_http_req_to_h2(&h2_headers, h1.req, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
if(*err) {
|
2023-04-14 17:38:14 +08:00
|
|
|
nwritten = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
nheader = Curl_dynhds_count(&h2_headers);
|
|
|
|
nva = malloc(sizeof(MSH3_HEADER) * nheader);
|
|
|
|
if(!nva) {
|
|
|
|
*err = CURLE_OUT_OF_MEMORY;
|
|
|
|
nwritten = -1;
|
2023-03-30 19:00:51 +08:00
|
|
|
goto out;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2022-12-28 00:02:56 +08:00
|
|
|
|
2023-04-14 17:38:14 +08:00
|
|
|
for(i = 0; i < nheader; ++i) {
|
|
|
|
struct dynhds_entry *e = Curl_dynhds_getn(&h2_headers, i);
|
|
|
|
nva[i].Name = e->name;
|
|
|
|
nva[i].NameLength = e->namelen;
|
|
|
|
nva[i].Value = e->value;
|
|
|
|
nva[i].ValueLength = e->valuelen;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(data->state.httpreq) {
|
|
|
|
case HTTPREQ_POST:
|
|
|
|
case HTTPREQ_POST_FORM:
|
|
|
|
case HTTPREQ_POST_MIME:
|
|
|
|
case HTTPREQ_PUT:
|
|
|
|
/* known request body size or -1 */
|
|
|
|
eos = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* there is not request body */
|
|
|
|
eos = TRUE;
|
|
|
|
stream->upload_done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "req: send %zu headers", nheader);
|
2023-01-02 21:08:16 +08:00
|
|
|
stream->req = MsH3RequestOpen(ctx->qconn, &msh3_request_if, data,
|
2023-04-14 17:38:14 +08:00
|
|
|
nva, nheader,
|
|
|
|
eos ? MSH3_REQUEST_FLAG_FIN :
|
2022-12-30 16:14:55 +08:00
|
|
|
MSH3_REQUEST_FLAG_NONE);
|
2022-04-11 00:21:37 +08:00
|
|
|
if(!stream->req) {
|
|
|
|
failf(data, "request open failed");
|
2022-12-30 16:14:55 +08:00
|
|
|
*err = CURLE_SEND_ERROR;
|
2023-03-30 19:00:51 +08:00
|
|
|
goto out;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
*err = CURLE_OK;
|
2023-03-30 19:00:51 +08:00
|
|
|
nwritten = len;
|
|
|
|
goto out;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
else {
|
|
|
|
/* request is open */
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "req: send %zu body bytes", len);
|
2023-03-30 19:00:51 +08:00
|
|
|
if(len > 0xFFFFFFFF) {
|
|
|
|
len = 0xFFFFFFFF;
|
|
|
|
}
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
if(!MsH3RequestSend(stream->req, MSH3_REQUEST_FLAG_NONE, buf,
|
|
|
|
(uint32_t)len, stream)) {
|
|
|
|
*err = CURLE_SEND_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2022-12-28 00:02:56 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
/* TODO - msh3/msquic will hold onto this memory until the send complete
|
|
|
|
event. How do we make sure curl doesn't free it until then? */
|
|
|
|
*err = CURLE_OK;
|
|
|
|
nwritten = len;
|
2022-12-28 00:02:56 +08:00
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
out:
|
|
|
|
set_quic_expire(cf, data);
|
2023-04-14 17:38:14 +08:00
|
|
|
free(nva);
|
|
|
|
Curl_h1_req_parse_free(&h1);
|
|
|
|
Curl_dynhds_free(&h2_headers);
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_RESTORE(cf, save);
|
|
|
|
return nwritten;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
lib: introduce struct easy_poll_set for poll information
Connection filter had a `get_select_socks()` method, inspired by the
various `getsocks` functions involved during the lifetime of a
transfer. These, depending on transfer state (CONNECT/DO/DONE/ etc.),
return sockets to monitor and flag if this shall be done for POLLIN
and/or POLLOUT.
Due to this design, sockets and flags could only be added, not
removed. This led to problems in filters like HTTP/2 where flow control
prohibits the sending of data until the peer increases the flow
window. The general transfer loop wants to write, adds POLLOUT, the
socket is writeable but no data can be written.
This leads to cpu busy loops. To prevent that, HTTP/2 did set the
`SEND_HOLD` flag of such a blocked transfer, so the transfer loop cedes
further attempts. This works if only one such filter is involved. If a
HTTP/2 transfer goes through a HTTP/2 proxy, two filters are
setting/clearing this flag and may step on each other's toes.
Connection filters `get_select_socks()` is replaced by
`adjust_pollset()`. They get passed a `struct easy_pollset` that keeps
up to `MAX_SOCKSPEREASYHANDLE` sockets and their `POLLIN|POLLOUT`
flags. This struct is initialized in `multi_getsock()` by calling the
various `getsocks()` implementations based on transfer state, as before.
After protocol handlers/transfer loop have set the sockets and flags
they want, the `easy_pollset` is *always* passed to the filters. Filters
"higher" in the chain are called first, starting at the first
not-yet-connection one. Each filter may add sockets and/or change
flags. When all flags are removed, the socket itself is removed from the
pollset.
Example:
* transfer wants to send, adds POLLOUT
* http/2 filter has a flow control block, removes POLLOUT and adds
POLLIN (it is waiting on a WINDOW_UPDATE from the server)
* TLS filter is connected and changes nothing
* h2-proxy filter also has a flow control block on its tunnel stream,
removes POLLOUT and adds POLLIN also.
* socket filter is connected and changes nothing
* The resulting pollset is then mixed together with all other transfers
and their pollsets, just as before.
Use of `SEND_HOLD` is no longer necessary in the filters.
All filters are adapted for the changed method. The handling in
`multi.c` has been adjusted, but its state handling the the protocol
handlers' `getsocks` method are untouched.
The most affected filters are http/2, ngtcp2, quiche and h2-proxy. TLS
filters needed to be adjusted for the connecting handshake read/write
handling.
No noticeable difference in performance was detected in local scorecard
runs.
Closes #11833
2023-09-04 18:06:07 +08:00
|
|
|
static void cf_msh3_adjust_pollset(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
struct easy_pollset *ps)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
2024-03-27 22:01:06 +08:00
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_SAVE(save, cf, data);
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
if(stream && ctx->sock[SP_LOCAL] != CURL_SOCKET_BAD) {
|
2023-01-02 21:08:16 +08:00
|
|
|
if(stream->recv_error) {
|
lib: introduce struct easy_poll_set for poll information
Connection filter had a `get_select_socks()` method, inspired by the
various `getsocks` functions involved during the lifetime of a
transfer. These, depending on transfer state (CONNECT/DO/DONE/ etc.),
return sockets to monitor and flag if this shall be done for POLLIN
and/or POLLOUT.
Due to this design, sockets and flags could only be added, not
removed. This led to problems in filters like HTTP/2 where flow control
prohibits the sending of data until the peer increases the flow
window. The general transfer loop wants to write, adds POLLOUT, the
socket is writeable but no data can be written.
This leads to cpu busy loops. To prevent that, HTTP/2 did set the
`SEND_HOLD` flag of such a blocked transfer, so the transfer loop cedes
further attempts. This works if only one such filter is involved. If a
HTTP/2 transfer goes through a HTTP/2 proxy, two filters are
setting/clearing this flag and may step on each other's toes.
Connection filters `get_select_socks()` is replaced by
`adjust_pollset()`. They get passed a `struct easy_pollset` that keeps
up to `MAX_SOCKSPEREASYHANDLE` sockets and their `POLLIN|POLLOUT`
flags. This struct is initialized in `multi_getsock()` by calling the
various `getsocks()` implementations based on transfer state, as before.
After protocol handlers/transfer loop have set the sockets and flags
they want, the `easy_pollset` is *always* passed to the filters. Filters
"higher" in the chain are called first, starting at the first
not-yet-connection one. Each filter may add sockets and/or change
flags. When all flags are removed, the socket itself is removed from the
pollset.
Example:
* transfer wants to send, adds POLLOUT
* http/2 filter has a flow control block, removes POLLOUT and adds
POLLIN (it is waiting on a WINDOW_UPDATE from the server)
* TLS filter is connected and changes nothing
* h2-proxy filter also has a flow control block on its tunnel stream,
removes POLLOUT and adds POLLIN also.
* socket filter is connected and changes nothing
* The resulting pollset is then mixed together with all other transfers
and their pollsets, just as before.
Use of `SEND_HOLD` is no longer necessary in the filters.
All filters are adapted for the changed method. The handling in
`multi.c` has been adjusted, but its state handling the the protocol
handlers' `getsocks` method are untouched.
The most affected filters are http/2, ngtcp2, quiche and h2-proxy. TLS
filters needed to be adjusted for the connecting handshake read/write
handling.
No noticeable difference in performance was detected in local scorecard
runs.
Closes #11833
2023-09-04 18:06:07 +08:00
|
|
|
Curl_pollset_add_in(data, ps, ctx->sock[SP_LOCAL]);
|
2023-04-21 18:04:46 +08:00
|
|
|
drain_stream(cf, data);
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
else if(stream->req) {
|
lib: introduce struct easy_poll_set for poll information
Connection filter had a `get_select_socks()` method, inspired by the
various `getsocks` functions involved during the lifetime of a
transfer. These, depending on transfer state (CONNECT/DO/DONE/ etc.),
return sockets to monitor and flag if this shall be done for POLLIN
and/or POLLOUT.
Due to this design, sockets and flags could only be added, not
removed. This led to problems in filters like HTTP/2 where flow control
prohibits the sending of data until the peer increases the flow
window. The general transfer loop wants to write, adds POLLOUT, the
socket is writeable but no data can be written.
This leads to cpu busy loops. To prevent that, HTTP/2 did set the
`SEND_HOLD` flag of such a blocked transfer, so the transfer loop cedes
further attempts. This works if only one such filter is involved. If a
HTTP/2 transfer goes through a HTTP/2 proxy, two filters are
setting/clearing this flag and may step on each other's toes.
Connection filters `get_select_socks()` is replaced by
`adjust_pollset()`. They get passed a `struct easy_pollset` that keeps
up to `MAX_SOCKSPEREASYHANDLE` sockets and their `POLLIN|POLLOUT`
flags. This struct is initialized in `multi_getsock()` by calling the
various `getsocks()` implementations based on transfer state, as before.
After protocol handlers/transfer loop have set the sockets and flags
they want, the `easy_pollset` is *always* passed to the filters. Filters
"higher" in the chain are called first, starting at the first
not-yet-connection one. Each filter may add sockets and/or change
flags. When all flags are removed, the socket itself is removed from the
pollset.
Example:
* transfer wants to send, adds POLLOUT
* http/2 filter has a flow control block, removes POLLOUT and adds
POLLIN (it is waiting on a WINDOW_UPDATE from the server)
* TLS filter is connected and changes nothing
* h2-proxy filter also has a flow control block on its tunnel stream,
removes POLLOUT and adds POLLIN also.
* socket filter is connected and changes nothing
* The resulting pollset is then mixed together with all other transfers
and their pollsets, just as before.
Use of `SEND_HOLD` is no longer necessary in the filters.
All filters are adapted for the changed method. The handling in
`multi.c` has been adjusted, but its state handling the the protocol
handlers' `getsocks` method are untouched.
The most affected filters are http/2, ngtcp2, quiche and h2-proxy. TLS
filters needed to be adjusted for the connecting handshake read/write
handling.
No noticeable difference in performance was detected in local scorecard
runs.
Closes #11833
2023-09-04 18:06:07 +08:00
|
|
|
Curl_pollset_add_out(data, ps, ctx->sock[SP_LOCAL]);
|
2023-04-21 18:04:46 +08:00
|
|
|
drain_stream(cf, data);
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
static bool cf_msh3_data_pending(struct Curl_cfilter *cf,
|
|
|
|
const struct Curl_easy *data)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
|
|
|
bool pending = FALSE;
|
|
|
|
|
|
|
|
CF_DATA_SAVE(save, cf, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
|
|
|
|
(void)cf;
|
2023-04-13 17:03:50 +08:00
|
|
|
if(stream && stream->req) {
|
2023-03-30 19:00:51 +08:00
|
|
|
msh3_lock_acquire(&stream->recv_lock);
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF((struct Curl_easy *)data, cf, "data pending = %zu",
|
|
|
|
Curl_bufq_len(&stream->recvbuf));
|
2023-03-30 19:00:51 +08:00
|
|
|
pending = !Curl_bufq_is_empty(&stream->recvbuf);
|
|
|
|
msh3_lock_release(&stream->recv_lock);
|
2023-04-21 18:04:46 +08:00
|
|
|
if(pending)
|
|
|
|
drain_stream(cf, (struct Curl_easy *)data);
|
2023-03-30 19:00:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CF_DATA_RESTORE(cf, save);
|
|
|
|
return pending;
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
|
|
|
|
2023-04-24 19:28:12 +08:00
|
|
|
static CURLcode h3_data_pause(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
bool pause)
|
|
|
|
{
|
|
|
|
if(!pause) {
|
|
|
|
drain_stream(cf, data);
|
|
|
|
Curl_expire(data, 0, EXPIRE_RUN_NOW);
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
static CURLcode cf_msh3_data_event(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
int event, int arg1, void *arg2)
|
|
|
|
{
|
2024-03-27 22:01:06 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
struct stream_ctx *stream = H3_STREAM_CTX(ctx, data);
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
2022-12-30 16:14:55 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_SAVE(save, cf, data);
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
(void)arg1;
|
|
|
|
(void)arg2;
|
|
|
|
switch(event) {
|
|
|
|
case CF_CTRL_DATA_SETUP:
|
2023-03-30 19:00:51 +08:00
|
|
|
result = h3_data_setup(cf, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
break;
|
2023-04-24 19:28:12 +08:00
|
|
|
case CF_CTRL_DATA_PAUSE:
|
|
|
|
result = h3_data_pause(cf, data, (arg1 != 0));
|
|
|
|
break;
|
2022-12-30 16:14:55 +08:00
|
|
|
case CF_CTRL_DATA_DONE:
|
2023-03-30 19:00:51 +08:00
|
|
|
h3_data_done(cf, data);
|
2022-12-30 16:14:55 +08:00
|
|
|
break;
|
|
|
|
case CF_CTRL_DATA_DONE_SEND:
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "req: send done");
|
2023-04-13 17:03:50 +08:00
|
|
|
if(stream) {
|
|
|
|
stream->upload_done = TRUE;
|
|
|
|
if(stream->req) {
|
|
|
|
char buf[1];
|
|
|
|
if(!MsH3RequestSend(stream->req, MSH3_REQUEST_FLAG_FIN,
|
|
|
|
buf, 0, data)) {
|
|
|
|
result = CURLE_SEND_ERROR;
|
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
|
|
|
|
CF_DATA_RESTORE(cf, save);
|
2022-12-30 16:14:55 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode cf_connect_start(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
|
|
|
{
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
2023-10-26 17:27:42 +08:00
|
|
|
struct ssl_primary_config *conn_config;
|
2023-01-08 23:23:21 +08:00
|
|
|
MSH3_ADDR addr = {0};
|
2023-03-30 19:00:51 +08:00
|
|
|
CURLcode result;
|
2023-10-26 17:27:42 +08:00
|
|
|
bool verify;
|
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
Curl_hash_offt_init(&ctx->streams, 63, h3_stream_hash_free);
|
2023-10-26 17:27:42 +08:00
|
|
|
conn_config = Curl_ssl_cf_get_primary_config(cf);
|
|
|
|
if(!conn_config)
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
verify = !!conn_config->verifypeer;
|
2023-03-30 19:00:51 +08:00
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
memcpy(&addr, &ctx->addr.sa_addr, ctx->addr.addrlen);
|
|
|
|
MSH3_SET_PORT(&addr, (uint16_t)cf->conn->remote_port);
|
2023-01-02 21:08:16 +08:00
|
|
|
|
2023-10-26 17:27:42 +08:00
|
|
|
if(verify && (conn_config->CAfile || conn_config->CApath)) {
|
2023-01-08 23:23:21 +08:00
|
|
|
/* TODO: need a way to provide trust anchors to MSH3 */
|
2023-01-02 21:08:16 +08:00
|
|
|
#ifdef DEBUGBUILD
|
|
|
|
/* we need this for our test cases to run */
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "non-standard CA not supported, "
|
|
|
|
"switching off verifypeer in DEBUG mode");
|
2023-01-02 21:08:16 +08:00
|
|
|
verify = 0;
|
|
|
|
#else
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "non-standard CA not supported, "
|
|
|
|
"attempting with built-in verification");
|
2023-01-02 21:08:16 +08:00
|
|
|
#endif
|
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "connecting to %s:%d (verify=%d)",
|
|
|
|
cf->conn->host.name, (int)cf->conn->remote_port, verify);
|
2022-12-30 16:14:55 +08:00
|
|
|
|
|
|
|
ctx->api = MsH3ApiOpen();
|
|
|
|
if(!ctx->api) {
|
|
|
|
failf(data, "can't create msh3 api");
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->qconn = MsH3ConnectionOpen(ctx->api,
|
2023-01-08 23:23:21 +08:00
|
|
|
&msh3_conn_if,
|
2023-03-30 19:00:51 +08:00
|
|
|
cf,
|
2022-12-30 16:14:55 +08:00
|
|
|
cf->conn->host.name,
|
2023-01-08 23:23:21 +08:00
|
|
|
&addr,
|
2023-01-02 21:08:16 +08:00
|
|
|
!verify);
|
2022-12-30 16:14:55 +08:00
|
|
|
if(!ctx->qconn) {
|
|
|
|
failf(data, "can't create msh3 connection");
|
|
|
|
if(ctx->api) {
|
|
|
|
MsH3ApiClose(ctx->api);
|
|
|
|
ctx->api = NULL;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
result = h3_data_setup(cf, data);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode cf_msh3_connect(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
bool blocking, bool *done)
|
|
|
|
{
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
2022-12-30 16:14:55 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
(void)blocking;
|
|
|
|
if(cf->connected) {
|
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_SAVE(save, cf, data);
|
|
|
|
|
2023-01-02 21:08:16 +08:00
|
|
|
if(ctx->sock[SP_LOCAL] == CURL_SOCKET_BAD) {
|
2024-06-02 02:26:11 +08:00
|
|
|
if(Curl_socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx->sock[0], FALSE) < 0) {
|
2023-01-02 21:08:16 +08:00
|
|
|
ctx->sock[SP_LOCAL] = CURL_SOCKET_BAD;
|
|
|
|
ctx->sock[SP_REMOTE] = CURL_SOCKET_BAD;
|
|
|
|
return CURLE_COULDNT_CONNECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
*done = FALSE;
|
|
|
|
if(!ctx->qconn) {
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
ctx->connect_started = Curl_now();
|
2022-12-30 16:14:55 +08:00
|
|
|
result = cf_connect_start(cf, data);
|
|
|
|
if(result)
|
|
|
|
goto out;
|
|
|
|
}
|
2022-04-11 00:21:37 +08:00
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
if(ctx->handshake_complete) {
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
ctx->handshake_at = Curl_now();
|
2023-01-08 23:23:21 +08:00
|
|
|
if(ctx->handshake_succeeded) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "handshake succeeded");
|
2023-01-08 23:23:21 +08:00
|
|
|
cf->conn->bits.multiplex = TRUE; /* at least potentially multiplexed */
|
|
|
|
cf->conn->httpversion = 30;
|
|
|
|
cf->conn->bundle->multiuse = BUNDLE_MULTIPLEX;
|
|
|
|
cf->connected = TRUE;
|
|
|
|
cf->conn->alpn = CURL_HTTP_VERSION_3;
|
|
|
|
*done = TRUE;
|
|
|
|
connkeep(cf->conn, "HTTP/3 default");
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
Curl_pgrsTime(data, TIMER_APPCONNECT);
|
2023-01-08 23:23:21 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "failed to connect, handshake failed");
|
|
|
|
result = CURLE_COULDNT_CONNECT;
|
|
|
|
}
|
2022-12-30 16:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_RESTORE(cf, save);
|
2022-12-30 16:14:55 +08:00
|
|
|
return result;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:21 +08:00
|
|
|
static void cf_msh3_close(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-01-02 21:08:16 +08:00
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
2023-01-02 21:08:16 +08:00
|
|
|
|
|
|
|
(void)data;
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_SAVE(save, cf, data);
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
if(ctx) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "destroying");
|
2023-03-30 19:00:51 +08:00
|
|
|
if(ctx->qconn) {
|
2022-12-30 16:14:55 +08:00
|
|
|
MsH3ConnectionClose(ctx->qconn);
|
2023-03-30 19:00:51 +08:00
|
|
|
ctx->qconn = NULL;
|
|
|
|
}
|
|
|
|
if(ctx->api) {
|
2022-12-30 16:14:55 +08:00
|
|
|
MsH3ApiClose(ctx->api);
|
2023-03-30 19:00:51 +08:00
|
|
|
ctx->api = NULL;
|
|
|
|
}
|
2024-03-27 22:01:06 +08:00
|
|
|
Curl_hash_destroy(&ctx->streams);
|
2023-01-02 21:08:16 +08:00
|
|
|
|
|
|
|
if(ctx->active) {
|
|
|
|
/* We share our socket at cf->conn->sock[cf->sockindex] when active.
|
|
|
|
* If it is no longer there, someone has stolen (and hopefully
|
|
|
|
* closed it) and we just forget about it.
|
|
|
|
*/
|
2023-03-30 19:00:51 +08:00
|
|
|
ctx->active = FALSE;
|
2023-01-02 21:08:16 +08:00
|
|
|
if(ctx->sock[SP_LOCAL] == cf->conn->sock[cf->sockindex]) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_msh3_close(%d) active",
|
|
|
|
(int)ctx->sock[SP_LOCAL]);
|
2023-01-02 21:08:16 +08:00
|
|
|
cf->conn->sock[cf->sockindex] = CURL_SOCKET_BAD;
|
|
|
|
}
|
|
|
|
else {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "cf_socket_close(%d) no longer at "
|
|
|
|
"conn->sock[], discarding", (int)ctx->sock[SP_LOCAL]);
|
2023-01-02 21:08:16 +08:00
|
|
|
ctx->sock[SP_LOCAL] = CURL_SOCKET_BAD;
|
|
|
|
}
|
|
|
|
if(cf->sockindex == FIRSTSOCKET)
|
|
|
|
cf->conn->remote_addr = NULL;
|
|
|
|
}
|
|
|
|
if(ctx->sock[SP_LOCAL] != CURL_SOCKET_BAD) {
|
|
|
|
sclose(ctx->sock[SP_LOCAL]);
|
|
|
|
}
|
|
|
|
if(ctx->sock[SP_REMOTE] != CURL_SOCKET_BAD) {
|
|
|
|
sclose(ctx->sock[SP_REMOTE]);
|
|
|
|
}
|
|
|
|
ctx->sock[SP_LOCAL] = CURL_SOCKET_BAD;
|
|
|
|
ctx->sock[SP_REMOTE] = CURL_SOCKET_BAD;
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
2023-03-30 19:00:51 +08:00
|
|
|
CF_DATA_RESTORE(cf, save);
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
static void cf_msh3_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2022-04-11 00:21:37 +08:00
|
|
|
{
|
2023-03-30 19:00:51 +08:00
|
|
|
struct cf_call_data save;
|
|
|
|
|
|
|
|
CF_DATA_SAVE(save, cf, data);
|
2023-01-08 23:23:21 +08:00
|
|
|
cf_msh3_close(cf, data);
|
|
|
|
free(cf->ctx);
|
2022-12-30 16:14:55 +08:00
|
|
|
cf->ctx = NULL;
|
2023-03-30 19:00:51 +08:00
|
|
|
/* no CF_DATA_RESTORE(cf, save); its gone */
|
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
}
|
|
|
|
|
2023-01-02 21:08:16 +08:00
|
|
|
static CURLcode cf_msh3_query(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
int query, int *pres1, void *pres2)
|
2023-01-02 21:08:16 +08:00
|
|
|
{
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
|
|
|
|
switch(query) {
|
|
|
|
case CF_QUERY_MAX_CONCURRENT: {
|
|
|
|
/* TODO: we do not have access to this so far, fake it */
|
|
|
|
(void)ctx;
|
|
|
|
*pres1 = 100;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2023-03-04 00:54:44 +08:00
|
|
|
case CF_QUERY_TIMER_CONNECT: {
|
|
|
|
struct curltime *when = pres2;
|
|
|
|
/* we do not know when the first byte arrived */
|
|
|
|
if(cf->connected)
|
|
|
|
*when = ctx->handshake_at;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
case CF_QUERY_TIMER_APPCONNECT: {
|
|
|
|
struct curltime *when = pres2;
|
|
|
|
if(cf->connected)
|
|
|
|
*when = ctx->handshake_at;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2023-01-02 21:08:16 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return cf->next?
|
|
|
|
cf->next->cft->query(cf->next, data, query, pres1, pres2) :
|
|
|
|
CURLE_UNKNOWN_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cf_msh3_conn_is_alive(struct Curl_cfilter *cf,
|
2023-03-06 19:44:45 +08:00
|
|
|
struct Curl_easy *data,
|
|
|
|
bool *input_pending)
|
2023-01-02 21:08:16 +08:00
|
|
|
{
|
|
|
|
struct cf_msh3_ctx *ctx = cf->ctx;
|
|
|
|
|
|
|
|
(void)data;
|
2023-03-06 19:44:45 +08:00
|
|
|
*input_pending = FALSE;
|
2023-01-08 23:23:21 +08:00
|
|
|
return ctx && ctx->sock[SP_LOCAL] != CURL_SOCKET_BAD && ctx->qconn &&
|
|
|
|
ctx->connected;
|
2023-01-02 21:08:16 +08:00
|
|
|
}
|
|
|
|
|
2023-01-11 17:30:42 +08:00
|
|
|
struct Curl_cftype Curl_cft_http3 = {
|
|
|
|
"HTTP/3",
|
2022-12-30 16:14:55 +08:00
|
|
|
CF_TYPE_IP_CONNECT | CF_TYPE_SSL | CF_TYPE_MULTIPLEX,
|
2023-01-11 17:30:42 +08:00
|
|
|
0,
|
2022-12-30 16:14:55 +08:00
|
|
|
cf_msh3_destroy,
|
|
|
|
cf_msh3_connect,
|
|
|
|
cf_msh3_close,
|
|
|
|
Curl_cf_def_get_host,
|
lib: introduce struct easy_poll_set for poll information
Connection filter had a `get_select_socks()` method, inspired by the
various `getsocks` functions involved during the lifetime of a
transfer. These, depending on transfer state (CONNECT/DO/DONE/ etc.),
return sockets to monitor and flag if this shall be done for POLLIN
and/or POLLOUT.
Due to this design, sockets and flags could only be added, not
removed. This led to problems in filters like HTTP/2 where flow control
prohibits the sending of data until the peer increases the flow
window. The general transfer loop wants to write, adds POLLOUT, the
socket is writeable but no data can be written.
This leads to cpu busy loops. To prevent that, HTTP/2 did set the
`SEND_HOLD` flag of such a blocked transfer, so the transfer loop cedes
further attempts. This works if only one such filter is involved. If a
HTTP/2 transfer goes through a HTTP/2 proxy, two filters are
setting/clearing this flag and may step on each other's toes.
Connection filters `get_select_socks()` is replaced by
`adjust_pollset()`. They get passed a `struct easy_pollset` that keeps
up to `MAX_SOCKSPEREASYHANDLE` sockets and their `POLLIN|POLLOUT`
flags. This struct is initialized in `multi_getsock()` by calling the
various `getsocks()` implementations based on transfer state, as before.
After protocol handlers/transfer loop have set the sockets and flags
they want, the `easy_pollset` is *always* passed to the filters. Filters
"higher" in the chain are called first, starting at the first
not-yet-connection one. Each filter may add sockets and/or change
flags. When all flags are removed, the socket itself is removed from the
pollset.
Example:
* transfer wants to send, adds POLLOUT
* http/2 filter has a flow control block, removes POLLOUT and adds
POLLIN (it is waiting on a WINDOW_UPDATE from the server)
* TLS filter is connected and changes nothing
* h2-proxy filter also has a flow control block on its tunnel stream,
removes POLLOUT and adds POLLIN also.
* socket filter is connected and changes nothing
* The resulting pollset is then mixed together with all other transfers
and their pollsets, just as before.
Use of `SEND_HOLD` is no longer necessary in the filters.
All filters are adapted for the changed method. The handling in
`multi.c` has been adjusted, but its state handling the the protocol
handlers' `getsocks` method are untouched.
The most affected filters are http/2, ngtcp2, quiche and h2-proxy. TLS
filters needed to be adjusted for the connecting handshake read/write
handling.
No noticeable difference in performance was detected in local scorecard
runs.
Closes #11833
2023-09-04 18:06:07 +08:00
|
|
|
cf_msh3_adjust_pollset,
|
2022-12-30 16:14:55 +08:00
|
|
|
cf_msh3_data_pending,
|
|
|
|
cf_msh3_send,
|
|
|
|
cf_msh3_recv,
|
|
|
|
cf_msh3_data_event,
|
2023-01-02 21:08:16 +08:00
|
|
|
cf_msh3_conn_is_alive,
|
2022-12-30 16:14:55 +08:00
|
|
|
Curl_cf_def_conn_keep_alive,
|
2023-01-02 21:08:16 +08:00
|
|
|
cf_msh3_query,
|
2022-12-30 16:14:55 +08:00
|
|
|
};
|
|
|
|
|
2024-03-27 22:01:06 +08:00
|
|
|
static struct cf_msh3_ctx *h3_get_msh3_ctx(struct Curl_easy *data)
|
|
|
|
{
|
|
|
|
if(data && data->conn) {
|
|
|
|
struct Curl_cfilter *cf = data->conn->cfilter[FIRSTSOCKET];
|
|
|
|
while(cf) {
|
|
|
|
if(cf->cft == &Curl_cft_http3)
|
|
|
|
return cf->ctx;
|
|
|
|
cf = cf->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEBUGF(infof(data, "no filter context found"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:14:55 +08:00
|
|
|
CURLcode Curl_cf_msh3_create(struct Curl_cfilter **pcf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
|
|
|
const struct Curl_addrinfo *ai)
|
2022-04-12 18:10:46 +08:00
|
|
|
{
|
2022-12-30 16:14:55 +08:00
|
|
|
struct cf_msh3_ctx *ctx = NULL;
|
|
|
|
struct Curl_cfilter *cf = NULL;
|
|
|
|
CURLcode result;
|
|
|
|
|
2022-04-12 18:10:46 +08:00
|
|
|
(void)data;
|
2022-12-30 16:14:55 +08:00
|
|
|
(void)conn;
|
|
|
|
(void)ai; /* TODO: msh3 resolves itself? */
|
2023-11-08 07:22:58 +08:00
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
2022-12-30 16:14:55 +08:00
|
|
|
if(!ctx) {
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
2023-01-02 21:08:16 +08:00
|
|
|
Curl_sock_assign_addr(&ctx->addr, ai, TRNSPRT_QUIC);
|
|
|
|
ctx->sock[SP_LOCAL] = CURL_SOCKET_BAD;
|
|
|
|
ctx->sock[SP_REMOTE] = CURL_SOCKET_BAD;
|
2022-12-30 16:14:55 +08:00
|
|
|
|
2023-01-11 17:30:42 +08:00
|
|
|
result = Curl_cf_create(&cf, &Curl_cft_http3, ctx);
|
2022-12-30 16:14:55 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
*pcf = (!result)? cf : NULL;
|
|
|
|
if(result) {
|
|
|
|
Curl_safefree(cf);
|
|
|
|
Curl_safefree(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Curl_conn_is_msh3(const struct Curl_easy *data,
|
|
|
|
const struct connectdata *conn,
|
|
|
|
int sockindex)
|
|
|
|
{
|
|
|
|
struct Curl_cfilter *cf = conn? conn->cfilter[sockindex] : NULL;
|
|
|
|
|
|
|
|
(void)data;
|
|
|
|
for(; cf; cf = cf->next) {
|
2023-01-11 17:30:42 +08:00
|
|
|
if(cf->cft == &Curl_cft_http3)
|
2022-12-30 16:14:55 +08:00
|
|
|
return TRUE;
|
|
|
|
if(cf->cft->flags & CF_TYPE_IP_CONNECT)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2022-04-12 18:10:46 +08:00
|
|
|
}
|
|
|
|
|
2022-04-11 00:21:37 +08:00
|
|
|
#endif /* USE_MSH3 */
|