Skip to content

Commit

Permalink
quiche: update for network path aware API
Browse files Browse the repository at this point in the history
Latest version of quiche requires the application to pass the peer
address of received packets, and it provides the address for outgoing
packets back.

Closes #7120
  • Loading branch information
ghedo authored and bagder committed May 24, 2021
1 parent a62e643 commit 424aa64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -2925,6 +2925,11 @@ if test X"$want_quiche" != Xno; then
CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$DIR_QUICHE"
export CURL_LIBRARY_PATH
AC_MSG_NOTICE([Added $DIR_QUICHE to CURL_LIBRARY_PATH]),
[],
[
AC_INCLUDES_DEFAULT
#include <sys/socket.h>
]
)
],
dnl not found, revert back to clean variables
Expand Down
26 changes: 19 additions & 7 deletions lib/vquic/quiche.c
Expand Up @@ -226,7 +226,7 @@ CURLcode Curl_quic_connect(struct Curl_easy *data,
quiche_config_log_keys(qs->cfg);

qs->conn = quiche_connect(conn->host.name, (const uint8_t *) qs->scid,
sizeof(qs->scid), qs->cfg);
sizeof(qs->scid), addr, addrlen, qs->cfg);
if(!qs->conn) {
failf(data, "can't create quiche connection");
return CURLE_OUT_OF_MEMORY;
Expand Down Expand Up @@ -360,24 +360,34 @@ static CURLcode process_ingress(struct Curl_easy *data, int sockfd,
ssize_t recvd;
uint8_t *buf = (uint8_t *)data->state.buffer;
size_t bufsize = data->set.buffer_size;
struct sockaddr_storage from;
socklen_t from_len;
quiche_recv_info recv_info;

DEBUGASSERT(qs->conn);

/* in case the timeout expired */
quiche_conn_on_timeout(qs->conn);

do {
recvd = recv(sockfd, buf, bufsize, 0);
from_len = sizeof(from);

recvd = recvfrom(sockfd, buf, bufsize, 0,
(struct sockaddr *)&from, &from_len);

if((recvd < 0) && ((SOCKERRNO == EAGAIN) || (SOCKERRNO == EWOULDBLOCK)))
break;

if(recvd < 0) {
failf(data, "quiche: recv() unexpectedly returned %zd "
failf(data, "quiche: recvfrom() unexpectedly returned %zd "
"(errno: %d, socket %d)", recvd, SOCKERRNO, sockfd);
return CURLE_RECV_ERROR;
}

recvd = quiche_conn_recv(qs->conn, buf, recvd);
recv_info.from = (struct sockaddr *) &from;
recv_info.from_len = from_len;

recvd = quiche_conn_recv(qs->conn, buf, recvd, &recv_info);
if(recvd == QUICHE_ERR_DONE)
break;

Expand All @@ -400,9 +410,10 @@ static CURLcode flush_egress(struct Curl_easy *data, int sockfd,
ssize_t sent;
uint8_t out[1200];
int64_t timeout_ns;
quiche_send_info send_info;

do {
sent = quiche_conn_send(qs->conn, out, sizeof(out));
sent = quiche_conn_send(qs->conn, out, sizeof(out), &send_info);
if(sent == QUICHE_ERR_DONE)
break;

Expand All @@ -411,9 +422,10 @@ static CURLcode flush_egress(struct Curl_easy *data, int sockfd,
return CURLE_SEND_ERROR;
}

sent = send(sockfd, out, sent, 0);
sent = sendto(sockfd, out, sent, 0,
(struct sockaddr *)&send_info.to, send_info.to_len);
if(sent < 0) {
failf(data, "send() returned %zd", sent);
failf(data, "sendto() returned %zd", sent);
return CURLE_SEND_ERROR;
}
} while(1);
Expand Down

0 comments on commit 424aa64

Please sign in to comment.