Skip to content

Commit

Permalink
Avoid dynamic table field creation in degraded mode
Browse files Browse the repository at this point in the history
Also avoid copy of sentinel values to be able to use them in event callback.
  • Loading branch information
dguerizec committed Jul 29, 2020
1 parent 720ad9d commit 05a7ae6
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions lib/hpack_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ static const struct hpt_field hpt_static[] = {
const char *hpack_unknown_name = "unknown_name";
const char *hpack_unknown_value = "unknown_value";

static size_t HPT_index_silent(HPACK_CTX);

static struct hpt_entry *
hpt_dynamic(struct hpack *hp, size_t idx)
{
Expand All @@ -77,7 +75,9 @@ hpt_dynamic(struct hpack *hp, size_t idx)
off = 0;

assert(idx > 0);
assert(idx <= hp->cnt);
if(idx > hp->cnt) {
return NULL;
}

while (1) {
(void)memcpy(&tmp, he, HPT_HEADERSZ);
Expand Down Expand Up @@ -109,18 +109,16 @@ HPT_field(HPACK_CTX, size_t idx, struct hpt_field *hf)
ctx->fld.val = hpack_unknown_value;
ctx->fld.nam_sz = strlen(ctx->fld.nam);
ctx->fld.val_sz = strlen(ctx->fld.val);
while(idx > ctx->hp->cnt) {
HPT_index_silent(ctx);
}
while(idx >= ctx->hp->cnt) {
HPT_index(ctx);
}
if(ctx->hp->flags & HPACK_CFG_SEND_ERR)
HPC_notify(ctx, HPACK_EVT_RECERR, ctx->ptr.blk, idx);
} else {
EXPECT(ctx, IDX, idx <= ctx->hp->cnt);
}
EXPECT(ctx, IDX, idx <= ctx->hp->cnt);

he = hpt_dynamic(ctx->hp, idx);
if(HPC_DEGRADED() && he == NULL) {
return (0);
}
assert(he != NULL);
assert(hf != NULL);
(void)memcpy(&tmp, he, HPT_HEADERSZ);
Expand Down Expand Up @@ -385,8 +383,8 @@ hpt_move_evicted(HPACK_CTX, const char *nam, size_t nam_sz, size_t len)
(void)memmove(MOVE(tbl_ptr, len), tbl_ptr, hp->sz.len);
}

static size_t
HPT_index_silent(HPACK_CTX)
void
HPT_index(HPACK_CTX)
{
struct hpack *hp;
void *nam_ptr, *val_ptr;
Expand All @@ -410,7 +408,7 @@ HPT_index_silent(HPACK_CTX)

len = HPACK_OVERHEAD + nam_sz + val_sz;
if (!hpt_fit(ctx, len))
return 0;
return;

nam_ptr = JUMP(hp->tbl, 0);
val_ptr = JUMP(hp->tbl, nam_sz + 1);
Expand All @@ -431,18 +429,11 @@ HPT_index_silent(HPACK_CTX)
hp->tbl->val_sz = (uint16_t)val_sz;
hp->sz.len += len;
hp->cnt++;
return len;
}

void
HPT_index(HPACK_CTX)
{
size_t len = HPT_index_silent(ctx);
if(len > 0) {
if(len > 0)
HPC_notify(ctx, HPACK_EVT_INDEX, NULL, len);
}
}


/**********************************************************************
* Decode
*/
Expand All @@ -455,17 +446,24 @@ HPT_decode(HPACK_CTX, size_t idx)
EXPECT(ctx, IDX, idx > 0);
(void)memset(&hf, 0, sizeof hf);
CALL(HPT_field, ctx, idx, &hf);
assert(hf.nam != NULL);
assert(hf.val != NULL);
assert(hf.nam_sz > 0);

ctx->fld.nam = ctx->buf;
ctx->fld.nam_sz = hf.nam_sz;
CALL(HPD_puts, ctx, hf.nam, hf.nam_sz);

ctx->fld.val = ctx->buf;
ctx->fld.val_sz = hf.val_sz;
CALL(HPD_puts, ctx, hf.val, hf.val_sz);
if(HPC_DEGRADED() && hf.nam == NULL) {
ctx->fld.nam = hpack_unknown_name;
ctx->fld.nam_sz = strlen(hpack_unknown_name);
ctx->fld.val = hpack_unknown_value;
ctx->fld.val_sz = strlen(hpack_unknown_value);
} else {
assert(hf.nam != NULL);
assert(hf.val != NULL);
assert(hf.nam_sz > 0);

ctx->fld.nam = ctx->buf;
ctx->fld.nam_sz = hf.nam_sz;
CALL(HPD_puts, ctx, hf.nam, hf.nam_sz);

ctx->fld.val = ctx->buf;
ctx->fld.val_sz = hf.val_sz;
CALL(HPD_puts, ctx, hf.val, hf.val_sz);
}

HPD_notify(ctx);
return (0);
Expand All @@ -480,6 +478,9 @@ HPT_decode_name(HPACK_CTX)
assert(ctx->hp->state.idx != 0);
(void)memset(&hf, 0, sizeof hf);
CALL(HPT_field, ctx, ctx->hp->state.idx, &hf);
if(HPC_DEGRADED() && hf.nam == NULL) {
return (0);
}
assert(hf.nam != NULL);
assert(hf.nam_sz > 0);

Expand Down

0 comments on commit 05a7ae6

Please sign in to comment.