src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_cid.h
src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn.c
src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn.h
+src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_info.c
+src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_info.h
src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_stat.h
src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conv.c
src/contrib/libngtcp2/ngtcp2/lib/ngtcp2_conv.h
contrib/libngtcp2/ngtcp2/lib/ngtcp2_cid.h \
contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn.c \
contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn.h \
+ contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_info.c \
+ contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_info.h \
contrib/libngtcp2/ngtcp2/lib/ngtcp2_conn_stat.h \
contrib/libngtcp2/ngtcp2/lib/ngtcp2_conv.c \
contrib/libngtcp2/ngtcp2/lib/ngtcp2_conv.h \
bbr->full_bw_reached = 1;
- ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_CCA,
- "bbr reached full bandwidth, full_bw=%" PRIu64, bbr->full_bw);
+ ngtcp2_log_infof(bbr->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "bbr reached full bandwidth, full_bw=%" PRIu64,
+ bbr->full_bw);
}
static void bbr_check_startup_high_loss(ngtcp2_cc_bbr *bbr) {
bbr->min_rtt = bbr->probe_rtt_min_delay;
bbr->min_rtt_stamp = bbr->probe_rtt_min_stamp;
- ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_CCA,
- "bbr update min_rtt=%" PRIu64, bbr->min_rtt);
+ ngtcp2_log_infof(bbr->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "bbr update min_rtt=%" PRIu64, bbr->min_rtt);
}
}
if (cstat->cwnd < cstat->ssthresh) {
cstat->cwnd += pkt->pktlen;
- ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
- "pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
- pkt->pkt_num, cstat->cwnd);
+ ngtcp2_log_infof(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
+ pkt->pkt_num, cstat->cwnd);
return;
}
reno->pending_add = 0;
- ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
- "reduce cwnd because of packet loss cwnd=%" PRIu64,
- cstat->cwnd);
+ ngtcp2_log_infof(reno->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "reduce cwnd because of packet loss cwnd=%" PRIu64,
+ cstat->cwnd);
}
void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *cc,
cstat->cwnd += ack->bytes_delivered;
}
- ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
- "%" PRIu64 " bytes acked, slow start cwnd=%" PRIu64,
- ack->bytes_delivered, cstat->cwnd);
+ ngtcp2_log_infof(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "%" PRIu64 " bytes acked, slow start cwnd=%" PRIu64,
+ ack->bytes_delivered, cstat->cwnd);
}
if (round_start) {
cstat->cwnd += m / cstat->cwnd;
}
- ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
- "%" PRIu64 " bytes acked, cubic-ca cwnd=%" PRIu64
- " k_m=%" PRIu64 " target=%" PRIu64 " w_est=%" PRIu64,
- ack->bytes_delivered, cstat->cwnd, cubic->current.k_m, target,
- cubic->current.w_est);
+ ngtcp2_log_infof(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "%" PRIu64 " bytes acked, cubic-ca cwnd=%" PRIu64
+ " k_m=%" PRIu64 " target=%" PRIu64 " w_est=%" PRIu64,
+ ack->bytes_delivered, cstat->cwnd, cubic->current.k_m,
+ target, cubic->current.w_est);
}
void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
cubic->current.k_m =
ngtcp2_cbrt((cwnd_delta << 30) * 10 / 4 / cstat->max_tx_udp_payload_size);
- ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
- "reduce cwnd because of packet loss cwnd=%" PRIu64,
- cstat->cwnd);
+ ngtcp2_log_infof(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "reduce cwnd because of packet loss cwnd=%" PRIu64,
+ cstat->cwnd);
}
void ngtcp2_cc_cubic_cc_on_spurious_congestion(ngtcp2_cc *cc,
cstat->cwnd = cubic->undo.cwnd;
cstat->ssthresh = cubic->undo.ssthresh;
- ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
- "spurious congestion is detected and congestion state is "
- "restored cwnd=%" PRIu64,
- cstat->cwnd);
+ ngtcp2_log_infof(cubic->cc.log, NGTCP2_LOG_EVENT_CCA,
+ "spurious congestion is detected and congestion state is "
+ "restored cwnd=%" PRIu64,
+ cstat->cwnd);
}
cubic_vars_reset(&cubic->undo.v);
#include "ngtcp2_callbacks.h"
#include "ngtcp2_tstamp.h"
#include "ngtcp2_frame_chain.h"
+#include "ngtcp2_conn_info.h"
/* NGTCP2_FLOW_WINDOW_RTT_FACTOR is the factor of RTT when flow
control window auto-tuning is triggered. */
pktns->tx.skip_pkt.next_pkt_num = pktns->tx.last_pkt_num + gap;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "next skip pkn=%" PRId64,
- pktns->tx.skip_pkt.next_pkt_num);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON, "next skip pkn=%" PRId64,
+ pktns->tx.skip_pkt.next_pkt_num);
}
static int conn_handle_skip_pkt(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
uint64_t cwnd = conn->cstat.cwnd;
if (bytes_in_flight >= cwnd) {
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_LDC,
- "cwnd limited bytes_in_flight=%lu cwnd=%lu",
- bytes_in_flight, cwnd);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_LDC,
+ "cwnd limited bytes_in_flight=%lu cwnd=%lu",
+ bytes_in_flight, cwnd);
}
return bytes_in_flight >= cwnd;
conn->tx.pacing.pktlen += (size_t)spktlen;
+ ++conn->cstat.pkt_sent;
+ conn->cstat.bytes_sent += (uint64_t)spktlen;
+
ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat);
++pktns->tx.last_pkt_num;
(rtb_entry_flags & NGTCP2_RTB_ENTRY_FLAG_ACK_ELICITING)) {
--pktns->rtb.probe_pkt_left;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "probe pkt size=%td",
- nwrite);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON, "probe pkt size=%td",
+ nwrite);
}
conn_update_keep_alive_last_ts(conn, ts);
conn->tx.pacing.pktlen += (size_t)nwrite;
+ ++conn->cstat.pkt_sent;
+ conn->cstat.bytes_sent += (uint64_t)nwrite;
+
ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat);
++pktns->tx.last_pkt_num;
ngtcp2_path_eq(&conn->dcid.current.ps.path, path)) {
--pktns->rtb.probe_pkt_left;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "probe pkt size=%td",
- nwrite);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON, "probe pkt size=%td",
+ nwrite);
}
}
} else if (pi && conn->tx.ecn.state == NGTCP2_ECN_STATE_CAPABLE) {
conn->tx.pacing.pktlen += (size_t)nwrite;
}
+ ++conn->cstat.pkt_sent;
+ conn->cstat.bytes_sent += (uint64_t)nwrite;
+
ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat);
++pktns->tx.last_pkt_num;
return 0;
}
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "sending PMTUD probe packet len=%zu", probelen);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "sending PMTUD probe packet len=%zu", probelen);
lfr.type = NGTCP2_FRAME_PING;
uint8_t cidbuf[sizeof(retry.odcid.data) * 2 + 1];
uint8_t *token;
- if (!in_pktns || conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY) {
- return 0;
+ if (!in_pktns || (conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY)) {
+ return NGTCP2_ERR_DISCARD_PKT;
}
in_rtb = &in_pktns->rtb;
return rv;
}
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, "odcid=0x%s",
- (const char *)ngtcp2_encode_hex(cidbuf, retry.odcid.data,
- retry.odcid.datalen));
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT, "odcid=0x%s",
+ (const char *)ngtcp2_encode_hex(cidbuf, retry.odcid.data,
+ retry.odcid.datalen));
if (retry.tokenlen == 0) {
return NGTCP2_ERR_PROTO;
return 0;
}
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "buffering 1RTT packet len=%zu", pktlen);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "buffering 1RTT packet len=%zu", pktlen);
rv =
conn_buffer_pkt(conn, &conn->pktns, path, pi, pkt, pktlen, dgramlen, ts);
}
/* Buffer re-ordered 0-RTT packet. */
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "buffering 0-RTT packet len=%zu", pktlen);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "buffering 0-RTT packet len=%zu", pktlen);
rv = conn_buffer_pkt(conn, conn->in_pktns, path, pi, pkt, pktlen, dgramlen,
ts);
if (conn->server) {
if (dgramlen < NGTCP2_MAX_UDP_PAYLOAD_SIZE) {
- ngtcp2_log_info(
+ ngtcp2_log_infof(
&conn->log, NGTCP2_LOG_EVENT_PKT,
"Initial packet was ignored because it is included in UDP datagram "
- "less than %zu bytes: %zu bytes",
+ "less than %d bytes: %zu bytes",
NGTCP2_MAX_UDP_PAYLOAD_SIZE, dgramlen);
return NGTCP2_ERR_DISCARD_PKT;
}
"Handshake packet at this point is unexpected and discarded");
return (ngtcp2_ssize)pktlen;
}
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "buffering Handshake packet len=%zu", pktlen);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "buffering Handshake packet len=%zu", pktlen);
rv = conn_buffer_pkt(conn, conn->hs_pktns, path, pi, pkt, pktlen,
dgramlen, ts);
hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->acktr.max_pkt_num, hd.pkt_num,
hd.pkt_numlen);
if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) {
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
- "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
return NGTCP2_ERR_DISCARD_PKT;
}
!conn->negotiated_version) {
conn->negotiated_version = hd.version;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "the negotiated version is 0x%08x",
- conn->negotiated_version);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "the negotiated version is 0x%08x",
+ conn->negotiated_version);
}
payload = conn->crypto.decrypt_buf.base;
ngtcp2_vec_len(fr->stream.data, fr->stream.datacnt)) {
conn->negotiated_version = hd.version;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "the negotiated version is 0x%08x",
- conn->negotiated_version);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "the negotiated version is 0x%08x",
+ conn->negotiated_version);
}
rv = conn_recv_crypto(conn, encryption_level, crypto, &fr->stream, ts);
}
break;
case NGTCP2_FRAME_PING:
+ ++conn->cstat.ping_recv;
require_ack = 1;
break;
default:
return nread;
}
+ ++conn->cstat.pkt_discarded;
+
/* If server discards first Initial, then drop connection
state. This is because SCID in packet might be corrupted
and the current connection state might wrongly discard
unrecoverable, therefore drop connection. */
return nread;
}
+
+ ++conn->cstat.pkt_discarded;
+
return (ngtcp2_ssize)dgramlen;
}
}
if (nread == NGTCP2_ERR_DISCARD_PKT) {
+ ++conn->cstat.pkt_discarded;
return (ngtcp2_ssize)dgramlen;
}
pkt += nread;
pktlen -= (size_t)nread;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
- "read packet %td left %zu", nread, pktlen);
+ ++conn->cstat.pkt_recv;
+ conn->cstat.bytes_recv += (uint64_t)nread;
+
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "read packet %td left %zu", nread, pktlen);
}
return (ngtcp2_ssize)dgramlen;
return rv;
}
break;
- case NGTCP2_FRAME_CRYPTO:
case NGTCP2_FRAME_PING:
+ ++conn->cstat.ping_recv;
+ /* fall through */
+ case NGTCP2_FRAME_CRYPTO:
require_ack = 1;
break;
default:
break;
default:
ngtcp2_log_rx_pkt_hd(&conn->log, &hd);
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
- "packet type 0x%02x was ignored", hd.type);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "packet type 0x%02x was ignored", hd.type);
return (ngtcp2_ssize)pktlen;
}
} else {
hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->acktr.max_pkt_num, hd.pkt_num,
hd.pkt_numlen);
if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) {
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
- "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num);
return NGTCP2_ERR_DISCARD_PKT;
}
conn->rx.preferred_addr.pkt_num < hd.pkt_num &&
ngtcp2_sockaddr_eq((const ngtcp2_sockaddr *)&conn->hs_local_addr,
path->local.addr)) {
- ngtcp2_log_info(
+ ngtcp2_log_infof(
&conn->log, NGTCP2_LOG_EVENT_PKT,
"pkt=%" PRId64
" is discarded because it was received on handshake local "
}
break;
case NGTCP2_FRAME_PING:
+ ++conn->cstat.ping_recv;
non_probing_pkt = 1;
break;
case NGTCP2_FRAME_PATH_CHALLENGE:
*ppc = next;
if (nread < 0) {
if (nread == NGTCP2_ERR_DISCARD_PKT) {
+ ++conn->cstat.pkt_discarded;
continue;
}
return (int)nread;
*ppc = next;
if (nread < 0) {
if (nread == NGTCP2_ERR_DISCARD_PKT) {
+ ++conn->cstat.pkt_discarded;
continue;
}
return (int)nread;
}
}
if (nread == NGTCP2_ERR_DISCARD_PKT) {
+ ++conn->cstat.pkt_discarded;
return 0;
}
return (int)nread;
pkt += nread;
pktlen -= (size_t)nread;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
- "read packet %td left %zu", nread, pktlen);
+ ++conn->cstat.pkt_recv;
+ conn->cstat.bytes_recv += (uint64_t)nread;
+
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_PKT,
+ "read packet %td left %zu", nread, pktlen);
}
return 0;
if ((size_t)nread < pktlen) {
/* We have 1RTT packet and application rx key, but the
handshake has not completed yet. */
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "buffering 1RTT packet len=%zu",
- pktlen - (size_t)nread);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "buffering 1RTT packet len=%zu",
+ pktlen - (size_t)nread);
rv = conn_buffer_pkt(conn, &conn->pktns, path, pi, pkt + nread,
pktlen - (size_t)nread, pktlen, ts);
conn_update_timestamp(conn, ts);
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "recv packet len=%zu",
- pktlen);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON, "recv packet len=%zu",
+ pktlen);
if (pktlen == 0) {
return 0;
!ngtcp2_dcidtr_check_path_retired(&conn->dcid.dtr, path)) {
ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
"ignore packet from unknown path");
+ ++conn->cstat.pkt_discarded;
+
return 0;
}
conn->local.transport_params.version_info.chosen_version =
conn->negotiated_version;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "the negotiated version is 0x%08x",
- conn->negotiated_version);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "the negotiated version is 0x%08x",
+ conn->negotiated_version);
} else {
rv = conn_client_validate_transport_params(conn, params);
if (rv != 0) {
}
if (conn->pktns.rtb.probe_pkt_left) {
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON,
- "transmit probe pkt left=%zu",
- conn->pktns.rtb.probe_pkt_left);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_CON,
+ "transmit probe pkt left=%zu",
+ conn->pktns.rtb.probe_pkt_left);
nwrite = conn_write_pkt(conn, pi, dest, destlen, (size_t)res, vmsg,
NGTCP2_PKT_1RTT, wflags, ts);
rtt < cstat->min_rtt + ack_delay) {
/* Ignore RTT sample if adjusting ack_delay causes the sample
less than min_rtt before handshake confirmation. */
- ngtcp2_log_info(
+ ngtcp2_log_infof(
&conn->log, NGTCP2_LOG_EVENT_LDC,
"ignore rtt sample because ack_delay is too large latest_rtt=%" PRIu64
" min_rtt=%" PRIu64 " ack_delay=%" PRIu64,
cstat->smoothed_rtt = (cstat->smoothed_rtt * 7 + rtt) / 8;
}
- ngtcp2_log_info(
+ ngtcp2_log_infof(
&conn->log, NGTCP2_LOG_EVENT_LDC,
"latest_rtt=%" PRIu64 " min_rtt=%" PRIu64 " smoothed_rtt=%" PRIu64
" rttvar=%" PRIu64 " ack_delay=%" PRIu64,
void ngtcp2_conn_get_conn_info_versioned(ngtcp2_conn *conn,
int conn_info_version,
ngtcp2_conn_info *cinfo) {
- const ngtcp2_conn_stat *cstat = &conn->cstat;
- (void)conn_info_version;
-
- cinfo->latest_rtt = cstat->latest_rtt;
- cinfo->min_rtt = cstat->min_rtt;
- cinfo->smoothed_rtt = cstat->smoothed_rtt;
- cinfo->rttvar = cstat->rttvar;
- cinfo->cwnd = cstat->cwnd;
- cinfo->ssthresh = cstat->ssthresh;
- cinfo->bytes_in_flight = cstat->bytes_in_flight;
+ ngtcp2_conn_info_init_versioned(conn_info_version, cinfo, &conn->cstat);
}
static void conn_get_loss_time_and_pktns(ngtcp2_conn *conn,
if (earliest_loss_time != UINT64_MAX) {
cstat->loss_detection_timer = earliest_loss_time;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_LDC,
- "loss_detection_timer=%" PRIu64 " nonzero crypto loss time",
- cstat->loss_detection_timer);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_LDC,
+ "loss_detection_timer=%" PRIu64
+ " nonzero crypto loss time",
+ cstat->loss_detection_timer);
return;
}
timeout =
cstat->loss_detection_timer > ts ? cstat->loss_detection_timer - ts : 0;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_LDC,
- "loss_detection_timer=%" PRIu64 " timeout=%" PRIu64,
- cstat->loss_detection_timer, timeout / NGTCP2_MILLISECONDS);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_LDC,
+ "loss_detection_timer=%" PRIu64 " timeout=%" PRIu64,
+ cstat->loss_detection_timer, timeout / NGTCP2_MILLISECONDS);
}
void ngtcp2_conn_cancel_loss_detection_timer(ngtcp2_conn *conn) {
++cstat->pto_count;
- ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_LDC, "pto_count=%zu",
- cstat->pto_count);
+ ngtcp2_log_infof(&conn->log, NGTCP2_LOG_EVENT_LDC, "pto_count=%zu",
+ cstat->pto_count);
ngtcp2_conn_set_loss_detection_timer(conn, ts);
return nwrite;
}
+ngtcp2_tstamp ngtcp2_conn_get_timestamp(const ngtcp2_conn *conn) {
+ return conn->log.last_ts;
+}
+
const ngtcp2_path_history_entry *
ngtcp2_conn_find_path_history(ngtcp2_conn *conn, const ngtcp2_path *path,
ngtcp2_tstamp ts) {
unreceived data. */
#define NGTCP2_MAX_REORDERED_CRYPTO_DATA 65536
-/* NGTCP2_MAX_RETRIES is the number of Retry packet which client can
- accept. */
-#define NGTCP2_MAX_RETRIES 3
-
/* NGTCP2_MAX_SCID_POOL_SIZE is the maximum number of source
connection ID the local endpoint provides to the remote endpoint.
The chosen value was described in old draft. Now a remote endpoint
--- /dev/null
+/*
+ * ngtcp2
+ *
+ * Copyright (c) 2025 ngtcp2 contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "ngtcp2_conn_info.h"
+#include "ngtcp2_conn_stat.h"
+
+void ngtcp2_conn_info_init_versioned(int conn_info_version,
+ ngtcp2_conn_info *cinfo,
+ const ngtcp2_conn_stat *cstat) {
+ cinfo->latest_rtt = cstat->latest_rtt;
+ cinfo->min_rtt = cstat->min_rtt;
+ cinfo->smoothed_rtt = cstat->smoothed_rtt;
+ cinfo->rttvar = cstat->rttvar;
+ cinfo->cwnd = cstat->cwnd;
+ cinfo->ssthresh = cstat->ssthresh;
+ cinfo->bytes_in_flight = cstat->bytes_in_flight;
+
+ switch (conn_info_version) {
+ case NGTCP2_CONN_INFO_V2:
+ cinfo->pkt_sent = cstat->pkt_sent;
+ cinfo->bytes_sent = cstat->bytes_sent;
+ cinfo->pkt_recv = cstat->pkt_recv;
+ cinfo->bytes_recv = cstat->bytes_recv;
+ cinfo->pkt_lost = cstat->pkt_lost;
+ cinfo->bytes_lost = cstat->bytes_lost;
+ cinfo->ping_recv = cstat->ping_recv;
+ cinfo->pkt_discarded = cstat->pkt_discarded;
+ }
+}
--- /dev/null
+/*
+ * ngtcp2
+ *
+ * Copyright (c) 2025 ngtcp2 contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef NGTCP2_CONN_INFO_H
+#define NGTCP2_CONN_INFO_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* defined(HAVE_CONFIG_H) */
+
+#include <ngtcp2/ngtcp2.h>
+
+typedef struct ngtcp2_conn_stat ngtcp2_conn_stat;
+
+/*
+ * ngtcp2_conn_info_init_versioned initializes |cinfo| of version
+ * |conn_info_version| from |cstat|. This function only fills the
+ * fields of |cinfo| that are available in the specified version.
+ */
+void ngtcp2_conn_info_init_versioned(int conn_info_version,
+ ngtcp2_conn_info *cinfo,
+ const ngtcp2_conn_stat *cstat);
+
+#endif /* !defined(NGTCP2_CONN_INFO_H) */
#include <ngtcp2/ngtcp2.h>
+#include "ngtcp2_pktns_id.h"
+
/**
* @struct
*
* scheduled and transmitted together.
*/
size_t send_quantum;
+ /*
+ * pkt_sent is the number of QUIC packets sent.
+ */
+ uint64_t pkt_sent;
+ /*
+ * bytes_sent is the number of bytes (the sum of QUIC packet length)
+ * sent.
+ */
+ uint64_t bytes_sent;
+ /*
+ * pkt_recv is the number of QUIC packets received, excluding
+ * discarded ones.
+ */
+ uint64_t pkt_recv;
+ /*
+ * bytes_recv is the number of bytes (the sum of QUIC packet length)
+ * received, excluding discarded ones.
+ */
+ uint64_t bytes_recv;
+ /*
+ * pkt_lost is the number of QUIC packets that are considered lost,
+ * excluding PMTUD packets.
+ */
+ uint64_t pkt_lost;
+ /*
+ * bytes_lost is the number of bytes (the sum of QUIC packet length)
+ * lost, excluding PMTUD packets.
+ */
+ uint64_t bytes_lost;
+ /*
+ * ping_recv is the number of PING frames received.
+ */
+ uint64_t ping_recv;
+ /*
+ * pkt_discarded is the number of QUIC packets discarded.
+ */
+ uint64_t pkt_discarded;
} ngtcp2_conn_stat;
#endif /* !defined(NGTCP2_CONN_STAT_H) */
* Frame type in hex string.
*/
-#define NGTCP2_LOG_BUFLEN 4096
+#define NGTCP2_LOG_PKT "%s %" PRId64 " %s"
+#define NGTCP2_LOG_TP "remote transport_parameters"
-/* TODO Split second and remaining fraction with comma */
-#define NGTCP2_LOG_HD "I%08" PRIu64 " 0x%s %s"
-#define NGTCP2_LOG_PKT NGTCP2_LOG_HD " %s %" PRId64 " %s"
-#define NGTCP2_LOG_TP NGTCP2_LOG_HD " remote transport_parameters"
-
-#define NGTCP2_LOG_FRM_HD_FIELDS(DIR) \
- timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "frm", \
- (DIR), hd->pkt_num, strpkttype(hd)
-
-#define NGTCP2_LOG_PKT_HD_FIELDS(DIR) \
- timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "pkt", \
- (DIR), hd->pkt_num, strpkttype(hd)
-
-#define NGTCP2_LOG_TP_HD_FIELDS \
- timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "cry"
+#define NGTCP2_LOG_PKT_HD_FIELDS(DIR) (DIR), hd->pkt_num, strpkttype(hd)
static const char *strerrorcode(uint64_t error_code) {
switch (error_code) {
}
static const char *strpkttype_type_flags(uint8_t type, uint8_t flags) {
- ngtcp2_pkt_hd hd = {0};
-
- hd.type = type;
- hd.flags = flags;
-
- return strpkttype(&hd);
-}
-
-static const char *strevent(ngtcp2_log_event ev) {
- switch (ev) {
- case NGTCP2_LOG_EVENT_CON:
- return "con";
- case NGTCP2_LOG_EVENT_PKT:
- return "pkt";
- case NGTCP2_LOG_EVENT_FRM:
- return "frm";
- case NGTCP2_LOG_EVENT_LDC:
- return "ldc";
- case NGTCP2_LOG_EVENT_CRY:
- return "cry";
- case NGTCP2_LOG_EVENT_PTV:
- return "ptv";
- case NGTCP2_LOG_EVENT_CCA:
- return "cca";
- case NGTCP2_LOG_EVENT_NONE:
- default:
- return "non";
- }
+ return strpkttype(&(ngtcp2_pkt_hd){
+ .type = type,
+ .flags = flags,
+ });
}
-static uint64_t timestamp_cast(uint64_t ns) { return ns / NGTCP2_MILLISECONDS; }
-
static void log_fr_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_stream *fr, const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
- " fin=%d offset=%" PRIu64 " len=%" PRIu64 " uni=%d"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type | fr->flags, fr->stream_id, fr->fin,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
+ " fin=%d offset=%" PRIu64 " len=%" PRIu64 " uni=%d",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type | fr->flags, fr->stream_id, fr->fin,
fr->offset, ngtcp2_vec_len(fr->data, fr->datacnt),
(fr->stream_id & 0x2) != 0);
}
int64_t largest_ack, min_ack;
size_t i;
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") largest_ack=%" PRId64
- " ack_delay=%" PRIu64 "(%" PRIu64 ") ack_range_count=%zu"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->largest_ack,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") largest_ack=%" PRId64
+ " ack_delay=%" PRIu64 "(%" PRIu64 ") ack_range_count=%zu",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->largest_ack,
fr->ack_delay_unscaled / NGTCP2_MILLISECONDS, fr->ack_delay, fr->rangecnt);
largest_ack = fr->largest_ack;
min_ack = fr->largest_ack - (int64_t)fr->first_ack_range;
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
- "..%" PRId64 "] len=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack, min_ack,
- fr->first_ack_range);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
+ "..%" PRId64 "] len=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, largest_ack,
+ min_ack, fr->first_ack_range);
for (i = 0; i < fr->rangecnt; ++i) {
const ngtcp2_ack_range *range = &fr->ranges[i];
largest_ack = min_ack - (int64_t)range->gap - 2;
min_ack = largest_ack - (int64_t)range->len;
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
- "..%" PRId64 "] gap=%" PRIu64
- " len=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack,
- min_ack, range->gap, range->len);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") range=[%" PRId64
+ "..%" PRId64 "] gap=%" PRIu64
+ " len=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, largest_ack,
+ min_ack, range->gap, range->len);
}
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") ect0=%" PRIu64
- " ect1=%" PRIu64 " ce=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->ecn.ect0,
- fr->ecn.ect1, fr->ecn.ce);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " ACK(0x%02" PRIx64 ") ect0=%" PRIu64
+ " ect1=%" PRIu64 " ce=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->ecn.ect0,
+ fr->ecn.ect1, fr->ecn.ce);
}
}
static void log_fr_padding(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_padding *fr, const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " PADDING(0x%02" PRIx64 ") len=%zu"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->len);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " PADDING(0x%02" PRIx64 ") len=%zu",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->len);
}
static void log_fr_reset_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_reset_stream *fr,
const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " RESET_STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
- " app_error_code=%s(0x%" PRIx64 ") final_size=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " RESET_STREAM(0x%02" PRIx64 ") id=0x%" PRIx64
+ " app_error_code=%s(0x%" PRIx64 ") final_size=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->stream_id,
strapperrorcode(fr->app_error_code), fr->app_error_code, fr->final_size);
}
char reason[256];
size_t reasonlen = ngtcp2_min_size(sizeof(reason) - 1, fr->reasonlen);
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " CONNECTION_CLOSE(0x%02" PRIx64
- ") error_code=%s(0x%" PRIx64 ") "
- "frame_type=%" PRIx64 " reason_len=%zu reason=[%s]"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " CONNECTION_CLOSE(0x%02" PRIx64 ") error_code=%s(0x%" PRIx64
+ ") "
+ "frame_type=%" PRIx64 " reason_len=%zu reason=[%s]",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type,
fr->type == NGTCP2_FRAME_CONNECTION_CLOSE ? strerrorcode(fr->error_code)
: strapperrorcode(fr->error_code),
fr->error_code, fr->frame_type, fr->reasonlen,
static void log_fr_max_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_max_data *fr, const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " MAX_DATA(0x%02" PRIx64 ") max_data=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_data);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " MAX_DATA(0x%02" PRIx64
+ ") max_data=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->max_data);
}
static void log_fr_max_stream_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_max_stream_data *fr,
const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " MAX_STREAM_DATA(0x%02" PRIx64
- ") id=0x%" PRIx64
- " max_stream_data=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
- fr->max_stream_data);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " MAX_STREAM_DATA(0x%02" PRIx64
+ ") id=0x%" PRIx64
+ " max_stream_data=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->stream_id,
+ fr->max_stream_data);
}
static void log_fr_max_streams(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_max_streams *fr, const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " MAX_STREAMS(0x%02" PRIx64 ") max_streams=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams);
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " MAX_STREAMS(0x%02" PRIx64 ") max_streams=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->max_streams);
}
static void log_fr_ping(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_ping *fr, const char *dir) {
- log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PING(0x%02" PRIx64 ")"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " PING(0x%02" PRIx64 ")",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type);
}
static void log_fr_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_data_blocked *fr,
const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " DATA_BLOCKED(0x%02" PRIx64 ") offset=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " DATA_BLOCKED(0x%02" PRIx64
+ ") offset=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->offset);
}
static void log_fr_stream_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_stream_data_blocked *fr,
const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " STREAM_DATA_BLOCKED(0x%02" PRIx64
- ") id=0x%" PRIx64 " offset=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
- fr->offset);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " STREAM_DATA_BLOCKED(0x%02" PRIx64
+ ") id=0x%" PRIx64 " offset=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->stream_id,
+ fr->offset);
}
static void log_fr_streams_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_streams_blocked *fr,
const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " STREAMS_BLOCKED(0x%02" PRIx64 ") max_streams=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams);
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " STREAMS_BLOCKED(0x%02" PRIx64 ") max_streams=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->max_streams);
}
static void log_fr_new_connection_id(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
uint8_t buf[sizeof(fr->stateless_reset_token) * 2 + 1];
uint8_t cid[sizeof(fr->cid.data) * 2 + 1];
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " NEW_CONNECTION_ID(0x%02" PRIx64 ") seq=%" PRIu64
- " cid=0x%s retire_prior_to=%" PRIu64
- " stateless_reset_token=0x%s"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " NEW_CONNECTION_ID(0x%02" PRIx64 ") seq=%" PRIu64
+ " cid=0x%s retire_prior_to=%" PRIu64
+ " stateless_reset_token=0x%s",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->seq,
(const char *)ngtcp2_encode_hex(cid, fr->cid.data, fr->cid.datalen),
fr->retire_prior_to,
(const char *)ngtcp2_encode_hex(buf, fr->stateless_reset_token,
static void log_fr_stop_sending(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_stop_sending *fr,
const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " STOP_SENDING(0x%02" PRIx64 ") id=0x%" PRIx64
- " app_error_code=%s(0x%" PRIx64 ")"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id,
- strapperrorcode(fr->app_error_code), fr->app_error_code);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " STOP_SENDING(0x%02" PRIx64
+ ") id=0x%" PRIx64
+ " app_error_code=%s(0x%" PRIx64 ")",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->stream_id,
+ strapperrorcode(fr->app_error_code), fr->app_error_code);
}
static void log_fr_path_challenge(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const char *dir) {
uint8_t buf[sizeof(fr->data) * 2 + 1];
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " PATH_CHALLENGE(0x%02" PRIx64 ") data=0x%s"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " PATH_CHALLENGE(0x%02" PRIx64 ") data=0x%s",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type,
(const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data)));
}
const char *dir) {
uint8_t buf[sizeof(fr->data) * 2 + 1];
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " PATH_RESPONSE(0x%02" PRIx64 ") data=0x%s"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " PATH_RESPONSE(0x%02" PRIx64 ") data=0x%s",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type,
(const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data)));
}
static void log_fr_crypto(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_stream *fr, const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " CRYPTO(0x%02" PRIx64 ") offset=%" PRIu64 " len=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset,
- ngtcp2_vec_len(fr->data, fr->datacnt));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " CRYPTO(0x%02" PRIx64 ") offset=%" PRIu64
+ " len=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->offset,
+ ngtcp2_vec_len(fr->data, fr->datacnt));
}
static void log_fr_new_token(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
} else {
p = ngtcp2_encode_hex(buf, fr->token, fr->tokenlen);
}
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " NEW_TOKEN(0x%02" PRIx64 ") token=0x%s len=%zu"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, (const char *)p, fr->tokenlen);
+
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " NEW_TOKEN(0x%02" PRIx64 ") token=0x%s len=%zu",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, (const char *)p, fr->tokenlen);
}
static void log_fr_retire_connection_id(ngtcp2_log *log,
const ngtcp2_pkt_hd *hd,
const ngtcp2_retire_connection_id *fr,
const char *dir) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_PKT " RETIRE_CONNECTION_ID(0x%02" PRIx64 ") seq=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " RETIRE_CONNECTION_ID(0x%02" PRIx64
+ ") seq=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type, fr->seq);
}
static void log_fr_handshake_done(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_handshake_done *fr,
const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " HANDSHAKE_DONE(0x%02" PRIx64 ")"),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " HANDSHAKE_DONE(0x%02" PRIx64 ")",
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type);
}
static void log_fr_datagram(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
const ngtcp2_datagram *fr, const char *dir) {
- log->log_printf(log->user_data,
- (NGTCP2_LOG_PKT " DATAGRAM(0x%02" PRIx64 ") len=%" PRIu64),
- NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type,
- ngtcp2_vec_len(fr->data, fr->datacnt));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_FRM,
+ NGTCP2_LOG_PKT " DATAGRAM(0x%02" PRIx64 ") len=%" PRIu64,
+ NGTCP2_LOG_PKT_HD_FIELDS(dir), fr->type,
+ ngtcp2_vec_len(fr->data, fr->datacnt));
}
static void log_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
}
for (i = 0; i < nsv; ++i) {
- log->log_printf(log->user_data, (NGTCP2_LOG_PKT " v=0x%08x"),
- NGTCP2_LOG_PKT_HD_FIELDS("rx"), sv[i]);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_PKT, NGTCP2_LOG_PKT " v=0x%08x",
+ NGTCP2_LOG_PKT_HD_FIELDS("rx"), sv[i]);
}
}
.type = NGTCP2_PKT_STATELESS_RESET,
};
- log->log_printf(
- log->user_data, (NGTCP2_LOG_PKT " token=0x%s randlen=%zu"),
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_PKT, NGTCP2_LOG_PKT " token=0x%s randlen=%zu",
NGTCP2_LOG_PKT_HD_FIELDS("rx"),
(const char *)ngtcp2_encode_hex(buf, sr->stateless_reset_token,
sizeof(sr->stateless_reset_token)),
}
if (params->stateless_reset_token_present) {
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " stateless_reset_token=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY, NGTCP2_LOG_TP " stateless_reset_token=0x%s",
(const char *)ngtcp2_encode_hex(token, params->stateless_reset_token,
sizeof(params->stateless_reset_token)));
}
if (params->preferred_addr.ipv4_present) {
sa_in = ¶ms->preferred_addr.ipv4;
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv4_addr=%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
- (const char *)ngtcp2_encode_ipv4(
- addr, (const uint8_t *)&sa_in->sin_addr));
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"),
- NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in->sin_port));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " preferred_address.ipv4_addr=%s",
+ (const char *)ngtcp2_encode_ipv4(
+ addr, (const uint8_t *)&sa_in->sin_addr));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " preferred_address.ipv4_port=%u",
+ ngtcp2_ntohs(sa_in->sin_port));
}
if (params->preferred_addr.ipv6_present) {
sa_in6 = ¶ms->preferred_addr.ipv6;
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv6_addr=%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
- (const char *)ngtcp2_encode_ipv6(
- addr, (const uint8_t *)&sa_in6->sin6_addr));
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"),
- NGTCP2_LOG_TP_HD_FIELDS, ngtcp2_ntohs(sa_in6->sin6_port));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " preferred_address.ipv6_addr=%s",
+ (const char *)ngtcp2_encode_ipv6(
+ addr, (const uint8_t *)&sa_in6->sin6_addr));
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " preferred_address.ipv6_port=%u",
+ ngtcp2_ntohs(sa_in6->sin6_port));
}
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " preferred_address.cid=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY, NGTCP2_LOG_TP " preferred_address.cid=0x%s",
(const char *)ngtcp2_encode_hex(cid, params->preferred_addr.cid.data,
params->preferred_addr.cid.datalen));
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " preferred_address.stateless_reset_token=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " preferred_address.stateless_reset_token=0x%s",
(const char *)ngtcp2_encode_hex(
token, params->preferred_addr.stateless_reset_token,
sizeof(params->preferred_addr.stateless_reset_token)));
}
if (params->original_dcid_present) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " original_destination_connection_id=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " original_destination_connection_id=0x%s",
(const char *)ngtcp2_encode_hex(cid, params->original_dcid.data,
params->original_dcid.datalen));
}
if (params->retry_scid_present) {
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " retry_source_connection_id=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " retry_source_connection_id=0x%s",
(const char *)ngtcp2_encode_hex(cid, params->retry_scid.data,
params->retry_scid.datalen));
}
if (params->initial_scid_present) {
- log->log_printf(
- log->user_data, (NGTCP2_LOG_TP " initial_source_connection_id=0x%s"),
- NGTCP2_LOG_TP_HD_FIELDS,
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " initial_source_connection_id=0x%s",
(const char *)ngtcp2_encode_hex(cid, params->initial_scid.data,
params->initial_scid.datalen));
}
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " initial_max_stream_data_bidi_local=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_bidi_local);
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " initial_max_stream_data_bidi_remote=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_bidi_remote);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " initial_max_stream_data_uni=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_uni);
- log->log_printf(log->user_data, (NGTCP2_LOG_TP " initial_max_data=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_data);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " initial_max_streams_bidi=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_streams_bidi);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " initial_max_streams_uni=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_streams_uni);
- log->log_printf(log->user_data, (NGTCP2_LOG_TP " max_idle_timeout=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS,
- params->max_idle_timeout / NGTCP2_MILLISECONDS);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " max_udp_payload_size=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->max_udp_payload_size);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " ack_delay_exponent=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->ack_delay_exponent);
- log->log_printf(log->user_data, (NGTCP2_LOG_TP " max_ack_delay=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS,
- params->max_ack_delay / NGTCP2_MILLISECONDS);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " active_connection_id_limit=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->active_connection_id_limit);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " disable_active_migration=%d"),
- NGTCP2_LOG_TP_HD_FIELDS, params->disable_active_migration);
- log->log_printf(log->user_data,
- (NGTCP2_LOG_TP " max_datagram_frame_size=%" PRIu64),
- NGTCP2_LOG_TP_HD_FIELDS, params->max_datagram_frame_size);
- log->log_printf(log->user_data, (NGTCP2_LOG_TP " grease_quic_bit=%d"),
- NGTCP2_LOG_TP_HD_FIELDS, params->grease_quic_bit);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP
+ " initial_max_stream_data_bidi_local=%" PRIu64,
+ params->initial_max_stream_data_bidi_local);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP
+ " initial_max_stream_data_bidi_remote=%" PRIu64,
+ params->initial_max_stream_data_bidi_remote);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " initial_max_stream_data_uni=%" PRIu64,
+ params->initial_max_stream_data_uni);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " initial_max_data=%" PRIu64,
+ params->initial_max_data);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " initial_max_streams_bidi=%" PRIu64,
+ params->initial_max_streams_bidi);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " initial_max_streams_uni=%" PRIu64,
+ params->initial_max_streams_uni);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " max_idle_timeout=%" PRIu64,
+ params->max_idle_timeout / NGTCP2_MILLISECONDS);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " max_udp_payload_size=%" PRIu64,
+ params->max_udp_payload_size);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " ack_delay_exponent=%" PRIu64,
+ params->ack_delay_exponent);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " max_ack_delay=%" PRIu64,
+ params->max_ack_delay / NGTCP2_MILLISECONDS);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " active_connection_id_limit=%" PRIu64,
+ params->active_connection_id_limit);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " disable_active_migration=%d",
+ params->disable_active_migration);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " max_datagram_frame_size=%" PRIu64,
+ params->max_datagram_frame_size);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " grease_quic_bit=%d",
+ params->grease_quic_bit);
if (params->version_info_present) {
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " version_information.chosen_version=0x%08x"),
- NGTCP2_LOG_TP_HD_FIELDS, params->version_info.chosen_version);
+ ngtcp2_log_infof_raw(log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP
+ " version_information.chosen_version=0x%08x",
+ params->version_info.chosen_version);
assert(!(params->version_info.available_versionslen & 0x3));
i += sizeof(uint32_t)) {
p = ngtcp2_get_uint32be(&version, p);
- log->log_printf(
- log->user_data,
- (NGTCP2_LOG_TP " version_information.available_versions[%zu]=0x%08x"),
- NGTCP2_LOG_TP_HD_FIELDS, i >> 2, version);
+ ngtcp2_log_infof_raw(
+ log, NGTCP2_LOG_EVENT_CRY,
+ NGTCP2_LOG_TP " version_information.available_versions[%zu]=0x%08x",
+ i >> 2, version);
}
}
}
return;
}
- ngtcp2_log_info(log, NGTCP2_LOG_EVENT_LDC,
- "pkn=%" PRId64 " lost type=%s sent_ts=%" PRIu64, pkt_num,
- strpkttype_type_flags(type, flags), sent_ts);
+ ngtcp2_log_infof(log, NGTCP2_LOG_EVENT_LDC,
+ "pkn=%" PRId64 " lost type=%s sent_ts=%" PRIu64, pkt_num,
+ strpkttype_type_flags(type, flags), sent_ts);
}
static void log_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
}
if (hd->type == NGTCP2_PKT_1RTT) {
- ngtcp2_log_info(
+ ngtcp2_log_infof(
log, NGTCP2_LOG_EVENT_PKT, "%s pkn=%" PRId64 " dcid=0x%s type=%s k=%d",
dir, hd->pkt_num,
(const char *)ngtcp2_encode_hex(dcid, hd->dcid.data, hd->dcid.datalen),
strpkttype(hd), (hd->flags & NGTCP2_PKT_FLAG_KEY_PHASE) != 0);
} else {
- ngtcp2_log_info(
+ ngtcp2_log_infof(
log, NGTCP2_LOG_EVENT_PKT,
"%s pkn=%" PRId64 " dcid=0x%s scid=0x%s version=0x%08x type=%s len=%zu",
dir, hd->pkt_num,
log_pkt_hd(log, hd, "tx");
}
-void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt,
- ...) {
- va_list ap;
- int n;
- char buf[NGTCP2_LOG_BUFLEN];
-
- if (!log->log_printf || !(log->events & ev)) {
- return;
- }
-
- va_start(ap, fmt);
- n = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
-
- if (n < 0 || (size_t)n >= sizeof(buf)) {
- return;
- }
-
- log->log_printf(log->user_data, (NGTCP2_LOG_HD " %s"),
- timestamp_cast(log->last_ts - log->ts), log->scid,
- strevent(ev), buf);
+void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd) {
+ ngtcp2_log_infof(log, NGTCP2_LOG_EVENT_PKT,
+ "cancel tx pkn=%" PRId64 " type=%s", hd->pkt_num,
+ strpkttype(hd));
}
-void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd) {
- ngtcp2_log_info(log, NGTCP2_LOG_EVENT_PKT,
- "cancel tx pkn=%" PRId64 " type=%s", hd->pkt_num,
- strpkttype(hd));
+uint64_t ngtcp2_log_timestamp(const ngtcp2_log *log) {
+ return (log->last_ts - log->ts) / NGTCP2_MILLISECONDS;
}
void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
+#define NGTCP2_LOG_HD "I%08" PRIu64 " 0x%s %s"
+
+uint64_t ngtcp2_log_timestamp(const ngtcp2_log *log);
+
+static inline const char *ngtcp2_log_event_str(ngtcp2_log_event ev) {
+ switch (ev) {
+ case NGTCP2_LOG_EVENT_CON:
+ return "con";
+ case NGTCP2_LOG_EVENT_PKT:
+ return "pkt";
+ case NGTCP2_LOG_EVENT_FRM:
+ return "frm";
+ case NGTCP2_LOG_EVENT_LDC:
+ return "ldc";
+ case NGTCP2_LOG_EVENT_CRY:
+ return "cry";
+ case NGTCP2_LOG_EVENT_PTV:
+ return "ptv";
+ case NGTCP2_LOG_EVENT_CCA:
+ return "cca";
+ case NGTCP2_LOG_EVENT_NONE:
+ default:
+ return "non";
+ }
+}
+
+#define ngtcp2_log_infof_raw(LOG, EV, FMT, ...) \
+ (LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \
+ ngtcp2_log_timestamp(LOG), (LOG)->scid, \
+ ngtcp2_log_event_str(EV), __VA_ARGS__);
+
+/**
+ * @function
+ *
+ * `ngtcp2_log_infof` writes info level log with printf like
+ * formatting.
+ */
+#define ngtcp2_log_infof(LOG, EV, FMT, ...) \
+ do { \
+ if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \
+ break; \
+ } \
+ \
+ ngtcp2_log_infof_raw((LOG), (EV), FMT, __VA_ARGS__); \
+ } while (0)
+
+#define ngtcp2_log_info_raw(LOG, EV, FMT) \
+ (LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \
+ ngtcp2_log_timestamp(LOG), (LOG)->scid, \
+ ngtcp2_log_event_str(EV))
+
/**
* @function
*
- * `ngtcp2_log_info` writes info level log.
+ * `ngtcp2_log_info` writes info level log. FMT should not contain
+ * formatting directive. This function exists to workaround the issue
+ * that __VA_ARGS__ cannot be empty.
*/
-void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt,
- ...);
+#define ngtcp2_log_info(LOG, EV, FMT) \
+ do { \
+ if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \
+ break; \
+ } \
+ \
+ ngtcp2_log_info_raw((LOG), (EV), FMT); \
+ } while (0)
#endif /* !defined(NGTCP2_LOG_H) */
}
void ngtcp2_qlog_end(ngtcp2_qlog *qlog) {
- uint8_t buf[1] = {0};
-
if (!qlog->write) {
return;
}
- qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_FIN, &buf, 0);
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_FIN, "", 0);
}
static ngtcp2_vec vec_pkt_type_initial = ngtcp2_make_vec_lit("initial");
void ngtcp2_qlog_pkt_lost(ngtcp2_qlog *qlog, ngtcp2_rtb_entry *ent) {
uint8_t buf[256];
uint8_t *p = buf;
- ngtcp2_pkt_hd hd = {0};
if (!qlog->write) {
return;
p = write_verbatim(
p, ",\"name\":\"recovery:packet_lost\",\"data\":{\"header\":");
- hd.type = ent->hd.type;
- hd.flags = ent->hd.flags;
- hd.pkt_num = ent->hd.pkt_num;
-
- p = write_pkt_hd(p, &hd);
+ p = write_pkt_hd(p, &(ngtcp2_pkt_hd){
+ .pkt_num = ent->hd.pkt_num,
+ .type = ent->hd.type,
+ .flags = ent->hd.flags,
+ });
p = write_verbatim(p, "}}\n");
qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
ngtcp2_qlog *qlog, const ngtcp2_pkt_stateless_reset *sr) {
uint8_t buf[256];
uint8_t *p = buf;
- ngtcp2_pkt_hd hd = {0};
if (!qlog->write) {
return;
}
- hd.type = NGTCP2_PKT_STATELESS_RESET;
-
*p++ = '\x1e';
*p++ = '{';
p = qlog_write_time(qlog, p);
p = write_verbatim(
p, ",\"name\":\"transport:packet_received\",\"data\":{\"header\":");
- p = write_pkt_hd(p, &hd);
+ p = write_pkt_hd(p, &(ngtcp2_pkt_hd){
+ .type = NGTCP2_PKT_STATELESS_RESET,
+ });
*p++ = ',';
p = write_pair_hex(p, "stateless_reset_token", sr->stateless_reset_token,
NGTCP2_STATELESS_RESET_TOKENLEN);
ngtcp2_range ngtcp2_range_intersect(const ngtcp2_range *a,
const ngtcp2_range *b) {
- ngtcp2_range r = {0};
+ ngtcp2_range r;
uint64_t begin = ngtcp2_max_uint64(a->begin, b->begin);
uint64_t end = ngtcp2_min_uint64(a->end, b->end);
if (begin < end) {
ngtcp2_range_init(&r, begin, end);
+ } else {
+ r = (ngtcp2_range){0};
}
return r;
/* ratelim_update updates rlim->tokens with the current |ts|. */
static void ratelim_update(ngtcp2_ratelim *rlim, ngtcp2_tstamp ts) {
- uint64_t d, gain;
+ uint64_t d, gain, gps;
assert(ts >= rlim->ts);
d = ts - rlim->ts;
rlim->ts = ts;
- gain = rlim->rate * d + rlim->carry;
+ if (rlim->rate > (UINT64_MAX - rlim->carry) / d) {
+ gain = UINT64_MAX;
+ } else {
+ gain = rlim->rate * d + rlim->carry;
+ }
- rlim->tokens += gain / NGTCP2_SECONDS;
+ gps = gain / NGTCP2_SECONDS;
- if (rlim->tokens < rlim->burst) {
+ if (gps < rlim->burst && rlim->tokens < rlim->burst - gps) {
+ rlim->tokens += gps;
rlim->carry = gain % NGTCP2_SECONDS;
- } else {
- rlim->tokens = rlim->burst;
- rlim->carry = 0;
+
+ return;
}
+
+ rlim->tokens = rlim->burst;
+ rlim->carry = 0;
}
int ngtcp2_ratelim_drain(ngtcp2_ratelim *rlim, uint64_t n, ngtcp2_tstamp ts) {
#ifdef HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* defined(HAVE_CONFIG_H) */
#include <ngtcp2/ngtcp2.h>
if (ent->flags &
(NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE | NGTCP2_RTB_ENTRY_FLAG_SKIP)) {
++rtb->num_lost_ignore_pkts;
- } else if (ent->hd.pkt_num >= rtb->cc_pkt_num) {
- rtb->rst->lost += ent->pktlen;
-
- if (rtb->cc->on_pkt_lost) {
- cc->on_pkt_lost(cc, cstat,
- ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
- pktns->id, ent->ts, ent->rst.lost,
- ent->rst.tx_in_flight,
- ent->rst.is_app_limited),
- ts);
+ } else {
+ ++cstat->pkt_lost;
+ cstat->bytes_lost += ent->pktlen;
+
+ if (ent->hd.pkt_num >= rtb->cc_pkt_num) {
+ rtb->rst->lost += ent->pktlen;
+
+ if (rtb->cc->on_pkt_lost) {
+ cc->on_pkt_lost(cc, cstat,
+ ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
+ pktns->id, ent->ts, ent->rst.lost,
+ ent->rst.tx_in_flight,
+ ent->rst.is_app_limited),
+ ts);
+ }
}
}
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED) {
- ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
- "pkn=%" PRId64 " has already been reclaimed on PTO",
- ent->hd.pkt_num);
+ ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
+ "pkn=%" PRId64 " has already been reclaimed on PTO",
+ ent->hd.pkt_num);
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED));
assert(UINT64_MAX == ent->lost_ts);
} else {
int ack_eliciting_pkt_acked = 0;
size_t ecn_acked = 0;
int verify_ecn = 0;
- ngtcp2_cc_ack cc_ack = {0};
+ ngtcp2_cc_ack cc_ack = {
+ .prior_bytes_in_flight = cstat->bytes_in_flight,
+ .rtt = UINT64_MAX,
+ };
size_t num_lost_pkts = rtb->num_lost_pkts - rtb->num_lost_ignore_pkts;
- cc_ack.prior_bytes_in_flight = cstat->bytes_in_flight;
- cc_ack.rtt = UINT64_MAX;
-
if (conn && (conn->flags & NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED) &&
(conn->flags & NGTCP2_CONN_FLAG_KEY_UPDATE_INITIATOR) &&
largest_ack >= conn->pktns.crypto.tx.ckm->pkt_num) {
*/
if (pktns->id == NGTCP2_PKTNS_ID_APPLICATION && loss_window &&
loss_window >= congestion_period) {
- ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
- "persistent congestion loss_window=%" PRIu64
- " congestion_period=%" PRIu64,
- loss_window, congestion_period);
+ ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
+ "persistent congestion loss_window=%" PRIu64
+ " congestion_period=%" PRIu64,
+ loss_window, congestion_period);
/* Reset min_rtt, srtt, and rttvar here. Next new RTT
sample will be used to recalculate these values. */
assert(ent->flags & NGTCP2_RTB_ENTRY_FLAG_LOST_RETRANSMITTED);
- ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
- "removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
+ ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
+ "removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
--rtb->num_lost_pkts;
return;
}
- ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
- "removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
+ ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
+ "removing stale lost pkn=%" PRId64, ent->hd.pkt_num);
--rtb->num_lost_pkts;
assert(!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE));
if (ent->flags & NGTCP2_RTB_ENTRY_FLAG_PTO_RECLAIMED) {
- ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_LDC,
- "pkn=%" PRId64 " has already been reclaimed on PTO",
- ent->hd.pkt_num);
+ ngtcp2_log_infof(rtb->log, NGTCP2_LOG_EVENT_LDC,
+ "pkn=%" PRId64 " has already been reclaimed on PTO",
+ ent->hd.pkt_num);
continue;
}
} ngtcp2_transport_params;
#define NGTCP2_CONN_INFO_V1 1
-#define NGTCP2_CONN_INFO_VERSION NGTCP2_CONN_INFO_V1
+#define NGTCP2_CONN_INFO_V2 2
+#define NGTCP2_CONN_INFO_VERSION NGTCP2_CONN_INFO_V2
/**
* @struct
* packets which have not been acknowledged.
*/
uint64_t bytes_in_flight;
+ /* The following fields have been added since NGTCP2_CONN_INFO_V2. */
+ /**
+ * :member:`pkt_sent` is the number of QUIC packets sent. This
+ * field has been available since v1.16.0.
+ */
+ uint64_t pkt_sent;
+ /**
+ * :member:`bytes_sent` is the number of bytes (the sum of QUIC
+ * packet length) sent. This field has been available since
+ * v1.16.0.
+ */
+ uint64_t bytes_sent;
+ /**
+ * :member:`pkt_recv` is the number of QUIC packets received,
+ * excluding discarded ones. This field has been available since
+ * v1.16.0.
+ */
+ uint64_t pkt_recv;
+ /**
+ * :member:`bytes_recv` is the number of bytes (the sum of QUIC
+ * packet length) received, excluding discarded ones. This field
+ * has been available since v1.16.0.
+ */
+ uint64_t bytes_recv;
+ /**
+ * :member:`pkt_lost` is the number of QUIC packets that are
+ * considered lost, excluding PMTUD packets. This field has been
+ * available since v1.16.0.
+ */
+ uint64_t pkt_lost;
+ /**
+ * :member:`bytes_lost` is the number of bytes (the sum of QUIC
+ * packet length) lost, excluding PMTUD packets. This field has
+ * been available since v1.16.0.
+ */
+ uint64_t bytes_lost;
+ /**
+ * :member:`ping_recv` is the number of PING frames received. This
+ * field has been available since v1.16.0.
+ */
+ uint64_t ping_recv;
+ /**
+ * :member:`pkt_discarded` is the number of QUIC packets discarded.
+ * This field has been available since v1.16.0.
+ */
+ uint64_t pkt_discarded;
} ngtcp2_conn_info;
/**
ngtcp2_pkt_info *pi, uint8_t *buf, size_t buflen, size_t *pgsolen,
ngtcp2_write_pkt write_pkt, ngtcp2_tstamp ts);
+/**
+ * @function
+ *
+ * `ngtcp2_conn_get_timestamp` returns the latest timestamp that is
+ * known to |conn|.
+ *
+ * This function has been available since v1.16.0.
+ */
+NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_get_timestamp(const ngtcp2_conn *conn);
+
/**
* @function
*
*
* Version number of the ngtcp2 library release.
*/
-#define NGTCP2_VERSION "1.15.0"
+#define NGTCP2_VERSION "1.16.0"
/**
* @macro
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
-#define NGTCP2_VERSION_NUM 0x010f00
+#define NGTCP2_VERSION_NUM 0x011000
#endif /* !defined(NGTCP2_VERSION_H) */