11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * nghttp3
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Copyright (c) 2019 nghttp3 contributors
51cb0ef41Sopenharmony_ci *
61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the
81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
121cb0ef41Sopenharmony_ci * the following conditions:
131cb0ef41Sopenharmony_ci *
141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be
151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software.
161cb0ef41Sopenharmony_ci *
171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
241cb0ef41Sopenharmony_ci */
251cb0ef41Sopenharmony_ci#ifndef NGHTTP3_TNODE_H
261cb0ef41Sopenharmony_ci#define NGHTTP3_TNODE_H
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci#ifdef HAVE_CONFIG_H
291cb0ef41Sopenharmony_ci#  include <config.h>
301cb0ef41Sopenharmony_ci#endif /* HAVE_CONFIG_H */
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci#include <nghttp3/nghttp3.h>
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci#include "nghttp3_pq.h"
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1llu << 24)
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_citypedef enum nghttp3_node_id_type {
391cb0ef41Sopenharmony_ci  NGHTTP3_NODE_ID_TYPE_STREAM = 0x00,
401cb0ef41Sopenharmony_ci  NGHTTP3_NODE_ID_TYPE_PUSH = 0x01,
411cb0ef41Sopenharmony_ci} nghttp3_node_id_type;
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_citypedef struct nghttp3_node_id {
441cb0ef41Sopenharmony_ci  nghttp3_node_id_type type;
451cb0ef41Sopenharmony_ci  int64_t id;
461cb0ef41Sopenharmony_ci} nghttp3_node_id;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_cinghttp3_node_id *nghttp3_node_id_init(nghttp3_node_id *nid,
491cb0ef41Sopenharmony_ci                                      nghttp3_node_id_type type, int64_t id);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ciint nghttp3_node_id_eq(const nghttp3_node_id *a, const nghttp3_node_id *b);
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_citypedef struct nghttp3_tnode {
541cb0ef41Sopenharmony_ci  nghttp3_pq_entry pe;
551cb0ef41Sopenharmony_ci  size_t num_children;
561cb0ef41Sopenharmony_ci  nghttp3_node_id nid;
571cb0ef41Sopenharmony_ci  uint64_t seq;
581cb0ef41Sopenharmony_ci  uint64_t cycle;
591cb0ef41Sopenharmony_ci  /* pri is a stream priority produced by nghttp3_pri_to_uint8. */
601cb0ef41Sopenharmony_ci  uint8_t pri;
611cb0ef41Sopenharmony_ci} nghttp3_tnode;
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_civoid nghttp3_tnode_init(nghttp3_tnode *tnode, const nghttp3_node_id *nid,
641cb0ef41Sopenharmony_ci                        uint64_t seq, uint8_t pri);
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_civoid nghttp3_tnode_free(nghttp3_tnode *tnode);
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_civoid nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci/*
711cb0ef41Sopenharmony_ci * nghttp3_tnode_schedule schedules |tnode| using |nwrite| as penalty.
721cb0ef41Sopenharmony_ci * If |tnode| has already been scheduled, it is rescheduled by the
731cb0ef41Sopenharmony_ci * amount of |nwrite|.
741cb0ef41Sopenharmony_ci */
751cb0ef41Sopenharmony_ciint nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
761cb0ef41Sopenharmony_ci                           uint64_t nwrite);
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci/*
791cb0ef41Sopenharmony_ci * nghttp3_tnode_is_scheduled returns nonzero if |tnode| is scheduled.
801cb0ef41Sopenharmony_ci */
811cb0ef41Sopenharmony_ciint nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode);
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci#endif /* NGHTTP3_TNODE_H */
84