Alien-nghttp3
view release on metacpan or search on metacpan
vendor/nghttp3-1.18.0/lib/nghttp3_qpack.c view on Meta::CPAN
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2013 nghttp2 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 "nghttp3_qpack.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "nghttp3_str.h"
#include "nghttp3_macro.h"
#include "nghttp3_debug.h"
#include "nghttp3_unreachable.h"
/* NGHTTP3_QPACK_MAX_QPACK_STREAMS is the maximum number of concurrent
nghttp3_qpack_stream object to handle a client which never cancel
or acknowledge header block. After this limit, encoder stops using
dynamic table. */
#define NGHTTP3_QPACK_MAX_QPACK_STREAMS 2000
/* Make scalar initialization form of nghttp3_qpack_static_entry */
#define MAKE_STATIC_ENT(I, T, H) \
{ \
.absidx = I, \
.token = T, \
.hash = H, \
}
/* Generated by mkstatichdtbl.py */
static nghttp3_qpack_static_entry token_stable[] = {
MAKE_STATIC_ENT(0, NGHTTP3_QPACK_TOKEN__AUTHORITY, 3153725150U),
MAKE_STATIC_ENT(15, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(16, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(17, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(18, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(19, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(20, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(21, NGHTTP3_QPACK_TOKEN__METHOD, 695666056U),
MAKE_STATIC_ENT(1, NGHTTP3_QPACK_TOKEN__PATH, 3292848686U),
MAKE_STATIC_ENT(22, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674U),
MAKE_STATIC_ENT(23, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674U),
MAKE_STATIC_ENT(24, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(25, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(26, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(27, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(28, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(63, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(64, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(65, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(66, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(67, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(68, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(69, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(70, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(71, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983U),
MAKE_STATIC_ENT(29, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321U),
MAKE_STATIC_ENT(30, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321U),
MAKE_STATIC_ENT(31, NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING, 3379649177U),
MAKE_STATIC_ENT(72, NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE, 1979086614U),
MAKE_STATIC_ENT(32, NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES, 1713753958U),
MAKE_STATIC_ENT(73, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS,
901040780U),
MAKE_STATIC_ENT(74, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS,
901040780U),
MAKE_STATIC_ENT(33, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232U),
MAKE_STATIC_ENT(34, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232U),
MAKE_STATIC_ENT(75, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS,
1524311232U),
MAKE_STATIC_ENT(76, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS,
2175229868U),
vendor/nghttp3-1.18.0/lib/nghttp3_qpack.c view on Meta::CPAN
return rv;
}
nghttp3_qpack_entry *
nghttp3_qpack_context_dtable_get(nghttp3_qpack_context *ctx, uint64_t absidx) {
size_t relidx;
assert(ctx->next_absidx > absidx);
assert(ctx->next_absidx - absidx - 1 < nghttp3_ringbuf_len(&ctx->dtable));
relidx = (size_t)(ctx->next_absidx - absidx - 1);
return *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, relidx);
}
nghttp3_qpack_entry *
nghttp3_qpack_context_dtable_top(nghttp3_qpack_context *ctx) {
assert(nghttp3_ringbuf_len(&ctx->dtable));
return *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, 0);
}
void nghttp3_qpack_entry_init(nghttp3_qpack_entry *ent, nghttp3_qpack_nv *qnv,
size_t sum, uint64_t absidx, uint32_t hash) {
ent->nv = *qnv;
ent->map_next = NULL;
ent->sum = sum;
ent->absidx = absidx;
ent->hash = hash;
nghttp3_rcbuf_incref(ent->nv.name);
nghttp3_rcbuf_incref(ent->nv.value);
}
void nghttp3_qpack_entry_free(nghttp3_qpack_entry *ent) {
nghttp3_rcbuf_decref(ent->nv.value);
nghttp3_rcbuf_decref(ent->nv.name);
}
int nghttp3_qpack_encoder_block_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream) {
nghttp3_blocked_streams_key bsk = {
.max_cnt = nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
.id = (uint64_t)stream->stream_id,
};
return nghttp3_ksl_insert(&encoder->blocked_streams, NULL, &bsk, stream);
}
void nghttp3_qpack_encoder_unblock_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream) {
nghttp3_blocked_streams_key bsk = {
.max_cnt = nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
.id = (uint64_t)stream->stream_id,
};
nghttp3_ksl_it it;
/* This is purely debugging purpose only */
it = nghttp3_ksl_lower_bound(&encoder->blocked_streams, &bsk);
assert(!nghttp3_ksl_it_end(&it));
assert(nghttp3_ksl_it_get(&it) == stream);
nghttp3_ksl_remove_hint(&encoder->blocked_streams, NULL, &it, &bsk);
}
void nghttp3_qpack_encoder_unblock(nghttp3_qpack_encoder *encoder,
uint64_t max_cnt) {
nghttp3_blocked_streams_key bsk = {
.max_cnt = max_cnt,
};
nghttp3_ksl_it it;
it = nghttp3_ksl_lower_bound(&encoder->blocked_streams, &bsk);
for (; !nghttp3_ksl_it_end(&it);) {
bsk = *(nghttp3_blocked_streams_key *)nghttp3_ksl_it_key(&it);
nghttp3_ksl_remove_hint(&encoder->blocked_streams, &it, &it, &bsk);
}
}
int nghttp3_qpack_encoder_ack_header(nghttp3_qpack_encoder *encoder,
int64_t stream_id) {
nghttp3_qpack_stream *stream =
nghttp3_qpack_encoder_find_stream(encoder, stream_id);
const nghttp3_mem *mem = encoder->ctx.mem;
nghttp3_qpack_header_block_ref *ref;
if (stream == NULL) {
return NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR;
}
assert(nghttp3_ringbuf_len(&stream->refs));
ref =
*(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0);
DEBUGF("qpack::encoder: Header acknowledgement stream=%ld ricnt=%" PRIu64
" krcnt=%" PRIu64 "\n",
stream_id, ref->max_cnt, encoder->krcnt);
if (encoder->krcnt < ref->max_cnt) {
encoder->krcnt = ref->max_cnt;
nghttp3_qpack_encoder_unblock(encoder, ref->max_cnt);
}
nghttp3_qpack_stream_pop_ref(stream);
assert(ref->min_cnts_pe.index != NGHTTP3_PQ_BAD_INDEX);
nghttp3_pq_remove(&encoder->min_cnts, &ref->min_cnts_pe);
nghttp3_qpack_header_block_ref_del(ref, mem);
if (nghttp3_ringbuf_len(&stream->refs)) {
return 0;
}
( run in 1.253 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )