Skip to content

Commit

Permalink
hotplace rev.624 study RFC 9204 QPACK
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Oct 12, 2024
1 parent 93112a2 commit 5ebf330
Show file tree
Hide file tree
Showing 17 changed files with 587 additions and 150 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# history

* Revision 624
* [changed] QPACK duplicate

* Revision 623
* [tested] HPACK eviction

Expand Down Expand Up @@ -332,9 +335,6 @@
* Revision 433
* [changed] COSE untagged message

* Revision 433
* [changed] COSE untagged message

* Revision 431
* [added] variant

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* JOSE ![implemented](https://img.shields.io/badge/implemented-green)
* CBOR ![implemented](https://img.shields.io/badge/implemented-green)
* COSE ![implemented](https://img.shields.io/badge/implemented-green)
* HTTP/1.1,2,3 ![studying](https://img.shields.io/badge/studying-magenta)
* HTTP/1.1,2 ![implemented](https://img.shields.io/badge/implemented-green)
* HTTP/3 ![studying](https://img.shields.io/badge/studying-magenta)
* ASN.1 ![studying](https://img.shields.io/badge/studying-magenta)
* link
* [changelog](CHANGELOG.md)
Expand Down
7 changes: 4 additions & 3 deletions sdk/io/system/windows/multiplexer_iocp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ return_t multiplexer_iocp::event_loop_run(multiplexer_context_t* handle, handle_
break;
}

// GetQueuedCompletionStatus
// GetQueuedCompletionStatusEx : retrieves multiple completion port entries simultaneously
// GetQueuedCompletionStatus | Windows XP | Windows Server 2003
// GetQueuedCompletionStatusEx | Windows Vista | Windows Server 2008
// retrieves multiple completion port entries simultaneously
DWORD size_transfered = 0;
ULONG_PTR completion_key = 0;
LPOVERLAPPED overlapped = nullptr;
Expand All @@ -172,7 +173,7 @@ return_t multiplexer_iocp::event_loop_run(multiplexer_context_t* handle, handle_
} else if (errorcode_t::success == ret) { /* mingw environments */
continue;
} else {
break; // GLE - Windows 2003 returns 87, Windows 7 returns 735
break; // GLE - Windows 2003 returns 87, Windows 7 returns 735(ERROR_ABANDONED_WAIT_0)
}
}
if (0 == completion_key) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/net/http/http2/hpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ class hpack_encoder : public http_header_compression {
class hpack_session : public http_header_compression_session {
public:
hpack_session();
/**
* @brief duplicate
* @param const std::string& name [in]
* @param const std::string& value [in]
*/
virtual return_t duplicate(const std::string& name, const std::string& value);
/**
* @brief HPACK query function
* @param int cmd [in] see header_compression_cmd_t
Expand Down
5 changes: 5 additions & 0 deletions sdk/net/http/http2/hpack_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace net {

hpack_session::hpack_session() : http_header_compression_session() {}

return_t hpack_session::duplicate(const std::string& name, const std::string& value) {
return_t ret = errorcode_t::success;
return ret;
}

return_t hpack_session::query(int cmd, void* req, size_t reqsize, void* resp, size_t& respsize) {
return_t ret = errorcode_t::success;
__try2 {
Expand Down
9 changes: 8 additions & 1 deletion sdk/net/http/http2/http_header_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ return_t http_header_compression::decode_string(const byte_t* p, size_t& pos, ui
return ret;
}

return_t http_header_compression::set_dynamic_table_size(binary_t& target, uint8 maxsize) {
return_t http_header_compression::set_dynamic_table_size(http_header_compression_session* session, binary_t& target, uint8 maxsize) {
// RFC 7541 Figure 12: Maximum Dynamic Table Size Change
// 0 1 2 3 4 5 6 7
// +---+---+---+---+---+---+---+---+
Expand All @@ -209,6 +209,13 @@ return_t http_header_compression::set_dynamic_table_size(binary_t& target, uint8
// | 0 | 0 | 1 | Capacity (5+) |
// +---+---+---+-------------------+

if (session) {
// RFC 7541 4.2. Maximum Table Size
// RFC 7541 6.3. Dynamic Table Size Update
// SETTINGS_HEADER_TABLE_SIZE
session->set_capacity(maxsize);
}

return encode_int(target, 0x20, 5, maxsize);
}

Expand Down
97 changes: 37 additions & 60 deletions sdk/net/http/http2/http_header_compression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#ifndef __HOTPLACE_SDK_NET_HTTP_HEADER_COMPRESSION__
#define __HOTPLACE_SDK_NET_HTTP_HEADER_COMPRESSION__

#include <math.h>

#include <sdk/base/basic/huffman_coding.hpp>

namespace hotplace {
Expand Down Expand Up @@ -149,13 +147,14 @@ class http_header_compression {

/**
* @brief dynamic table size
* @param http_header_compression_session* session [in]
* @param binary_t& target
* @param uint8 maxsize
* @remarks
* RFC 7541 6.3. Dynamic Table Size Update
* RFC 9204 4.3.1. Set Dynamic Table Capacity
*/
return_t set_dynamic_table_size(binary_t& target, uint8 maxsize);
return_t set_dynamic_table_size(http_header_compression_session* session, binary_t& target, uint8 maxsize);
/**
* @brief size of entry
* @param const std::string& name [in]
Expand Down Expand Up @@ -223,59 +222,27 @@ enum header_compression_cmd_t {
qpack_cmd_capacity = 4,
};

struct qpack_section_prefix_t {
size_t capacity;
size_t ric;
size_t base;
size_t eic;
size_t delta;

qpack_section_prefix_t(size_t c) : capacity(c), ric(0), base(0), eic(0), delta(0) {}
qpack_section_prefix_t(size_t c, size_t r, size_t b) : capacity(c), ric(r), base(b), eic(0), delta(0) { calc(); }
qpack_section_prefix_t(const qpack_section_prefix_t& rhs) : capacity(rhs.capacity), ric(rhs.ric), base(rhs.base), eic(rhs.eic), delta(rhs.delta) { calc(); }
qpack_section_prefix_t(qpack_section_prefix_t* rhs) {
copyfrom(rhs);
calc();
}
void copyfrom(qpack_section_prefix_t* rhs) {
if (rhs) {
capacity = rhs->capacity;
ric = rhs->ric;
base = rhs->base;
eic = rhs->eic;
delta = rhs->delta;
}
}
void calc() {
if ((0 == eic) && (0 == delta)) {
/* RFC 9204 4.5.1.1. Required Insert Count
* if (ReqInsertCount) EncInsertCount = (ReqInsertCount mod (2 * MaxEntries)) + 1
* else EncInsertCount = 0;
*/
if (0 == ric) {
eic = ric;
} else {
size_t maxentries = ::floor(capacity / 32);
eic = (ric % (2 * maxentries)) + 1;
}
/* RFC 9204 4.5.1.2. Base
* A Sign bit of 1 indicates that the Base is less than the Required Insert Count
*
* if (0 == Sign) Base = DeltaBase + ReqInsertCount
* else Base = ReqInsertCount - DeltaBase - 1
*
* if (0 == Sign) DeltaBase = Base - ReqInsertCount
* else DeltaBase = ReqInsertCount - Base - 1
*/
if (sign()) {
delta = ric - base - 1;
} else {
delta = ric - base;
}
}
}
bool sign() { return ric > base; }
};
/**
* @brief Field Section Prefix
* @param size_t capacity [in]
* @param size_t ric [in]
* @param size_t base [in]
* @param size_t& eic [out]
* @param bool& sign [out]
* @param size_t& deltabase [out]
*/
return_t qpack_ric2eic(size_t capacity, size_t ric, size_t base, size_t& eic, bool& sign, size_t& deltabase);
/**
* @brief Field Section Prefix (reconstruct)
* @param size_t capacity [in]
* @param size_t tni [in] total number of inserts
* @param size_t eic [in]
* @param bool sign [in]
* @param size_t deltabase [in]
* @param size_t& ric [out]
* @param size_t& base [out]
*/
return_t qpack_eic2ric(size_t capacity, size_t tni, size_t eic, bool sign, size_t deltabase, size_t& ric, size_t& base);

/**
* @brief session
Expand All @@ -294,6 +261,10 @@ class http_header_compression_session {
*/
bool operator==(const http_header_compression_session& rhs);
bool operator!=(const http_header_compression_session& rhs);
/**
* @brief trace
*/
void trace(std::function<void(stream_t*)> f);
/**
* @brief match
* @param const std::string& name [in]
Expand All @@ -318,6 +289,12 @@ class http_header_compression_session {
* @brief evict
*/
virtual return_t evict();
/**
* @brief duplicate
* @param const std::string& name [in]
* @param const std::string& value [in]
*/
virtual return_t duplicate(const std::string& name, const std::string& value);
/**
* @brief capacity
*/
Expand All @@ -339,19 +316,19 @@ class http_header_compression_session {

protected:
typedef http_header_compression::table_entry_t table_entry_t;
typedef std::multimap<std::string, table_entry_t> dynamic_map_t;
typedef std::map<size_t, std::string> dynamic_reversemap_t;
typedef std::map<size_t, size_t> entry_size_t; // map<entry, size of entry>
typedef std::multimap<std::string, table_entry_t> dynamic_map_t; // table_entry_t(value, entry)
typedef std::map<size_t, table_entry_t> dynamic_reversemap_t; // table_entry_t(name, entry size)

dynamic_map_t _dynamic_map;
dynamic_reversemap_t _dynamic_reversemap;
entry_size_t _entry_size;

bool _separate; // false:HPACK, true:QPACK
uint32 _capacity;
size_t _tablesize;
size_t _inserted;
size_t _dropped;

std::function<void(stream_t*)> _df;
};

/*
Expand Down
Loading

0 comments on commit 5ebf330

Please sign in to comment.