Rename padding related names

This commit is contained in:
Tatsuhiro Tsujikawa 2014-02-09 21:46:15 +09:00
parent ce53d7bd9e
commit 68b5ffc1dc
10 changed files with 47 additions and 46 deletions

View File

@ -151,9 +151,9 @@ typedef struct {
* @macro * @macro
* *
* The default value of DATA padding alignment. See * The default value of DATA padding alignment. See
* :member:`NGHTTP2_OPT_PAD_ALIGNMENT`. * :member:`NGHTTP2_OPT_PADDING_BOUNDARY`.
*/ */
#define NGHTTP2_PAD_ALIGNMENT 16 #define NGHTTP2_PADDING_BOUNDARY 64
/** /**
* @enum * @enum
@ -1341,7 +1341,7 @@ typedef enum {
* to this alignment. The option value must be greater than or equal * to this alignment. The option value must be greater than or equal
* to 8. * to 8.
*/ */
NGHTTP2_OPT_PAD_ALIGNMENT = 1 << 3 NGHTTP2_OPT_PADDING_BOUNDARY = 1 << 3
} nghttp2_opt; } nghttp2_opt;
/** /**
@ -1363,9 +1363,9 @@ typedef struct {
*/ */
uint8_t no_auto_connection_window_update; uint8_t no_auto_connection_window_update;
/** /**
* :enum:`NGHTTP2_OPT_PAD_ALIGNMENT` * :enum:`NGHTTP2_OPT_PADDING_BOUNDARY`
*/ */
uint16_t pad_alignment; uint16_t padding_boundary;
} nghttp2_opt_set; } nghttp2_opt_set;
/** /**

View File

@ -228,7 +228,7 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
size_t *bufoff_ptr, size_t *bufoff_ptr,
nghttp2_headers *frame, nghttp2_headers *frame,
nghttp2_hd_deflater *deflater, nghttp2_hd_deflater *deflater,
size_t align) size_t boundary)
{ {
size_t payloadoff = NGHTTP2_FRAME_HEAD_LENGTH + 2; size_t payloadoff = NGHTTP2_FRAME_HEAD_LENGTH + 2;
size_t nv_offset = size_t nv_offset =
@ -244,13 +244,13 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
payloadlen = nghttp2_frame_headers_payload_nv_offset(frame) + rv; payloadlen = nghttp2_frame_headers_payload_nv_offset(frame) + rv;
if(align > 0) { if(boundary > 0) {
ssize_t padlen; ssize_t padlen;
padlen = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr, padlen = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr,
&frame->hd.flags, &frame->hd.flags,
payloadlen, payloadlen,
payloadlen + align, payloadlen + boundary,
align); boundary);
if(padlen < 0) { if(padlen < 0) {
return padlen; return padlen;
} }
@ -665,11 +665,12 @@ ssize_t nghttp2_frame_add_pad(uint8_t **buf_ptr, size_t *buflen_ptr,
uint8_t *flags_ptr, uint8_t *flags_ptr,
size_t payloadlen, size_t payloadlen,
size_t payloadmax, size_t payloadmax,
size_t align) size_t boundary)
{ {
int rv; int rv;
size_t nextlen = nghttp2_min((payloadlen + align - 1) / align * align, size_t nextlen =
payloadmax); nghttp2_min((payloadlen + boundary - 1) / boundary * boundary,
payloadmax);
size_t padlen = nextlen - payloadlen; size_t padlen = nextlen - payloadlen;
size_t trail_padlen = 0; size_t trail_padlen = 0;
/* extra 2 bytes for PAD_HIGH and PAD_LOW. */ /* extra 2 bytes for PAD_HIGH and PAD_LOW. */

View File

@ -107,8 +107,8 @@ size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
* The first byte the frame is serialized is returned in the * The first byte the frame is serialized is returned in the
* |*bufoff_ptr|. * |*bufoff_ptr|.
* *
* The |align| is used as padding alignment. If the |align| is zero, * The |boundary| is used as padding boundary. If the |boundary| is
* no padding is added. * zero, no padding is added.
* *
* frame->hd.length is assigned after length is determined during * frame->hd.length is assigned after length is determined during
* packing process. If payload length is strictly larger than * packing process. If payload length is strictly larger than
@ -132,7 +132,7 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
size_t *bufoff_ptr, size_t *bufoff_ptr,
nghttp2_headers *frame, nghttp2_headers *frame,
nghttp2_hd_deflater *deflater, nghttp2_hd_deflater *deflater,
size_t align); size_t boundary);
/* /*
* Unpacks HEADERS frame byte sequence into |frame|. This function * Unpacks HEADERS frame byte sequence into |frame|. This function
@ -508,8 +508,8 @@ int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
* payload must start at offset NGHTTP2_FRAME_HEAD_LENGTH + 2 from * payload must start at offset NGHTTP2_FRAME_HEAD_LENGTH + 2 from
* |*buf_ptr| to account for PAD_HIGH and PAD_LOW. The maximum payload * |*buf_ptr| to account for PAD_HIGH and PAD_LOW. The maximum payload
* allowed is given in the |payloadmax|. The padding will not be made * allowed is given in the |payloadmax|. The padding will not be made
* more than |payloadmax|. The padding alignment is given in the * more than |payloadmax|. The padding boundary is given in the
* |align|. * |boundary|.
* *
* The |*flags_ptr| is updated to include NGHTTP2_FLAG_PAD_LOW and * The |*flags_ptr| is updated to include NGHTTP2_FLAG_PAD_LOW and
* NGHTTP2_FLAG_PAD_HIGH based on the padding length. The * NGHTTP2_FLAG_PAD_HIGH based on the padding length. The
@ -582,6 +582,6 @@ ssize_t nghttp2_frame_add_pad(uint8_t **buf_ptr, size_t *buflen_ptr,
uint8_t *flags_ptr, uint8_t *flags_ptr,
size_t payloadlen, size_t payloadlen,
size_t payloadmax, size_t payloadmax,
size_t align); size_t boundary);
#endif /* NGHTTP2_FRAME_H */ #endif /* NGHTTP2_FRAME_H */

View File

@ -224,11 +224,11 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
(*session_ptr)->opt_flags |= (*session_ptr)->opt_flags |=
NGHTTP2_OPTMASK_NO_AUTO_CONNECTION_WINDOW_UPDATE; NGHTTP2_OPTMASK_NO_AUTO_CONNECTION_WINDOW_UPDATE;
} }
if((opt_set_mask & NGHTTP2_OPT_PAD_ALIGNMENT) && if((opt_set_mask & NGHTTP2_OPT_PADDING_BOUNDARY) &&
opt_set->pad_alignment >= 8) { opt_set->padding_boundary >= 8) {
(*session_ptr)->pad_alignment = opt_set->pad_alignment; (*session_ptr)->padding_boundary = opt_set->padding_boundary;
} else { } else {
(*session_ptr)->pad_alignment = NGHTTP2_PAD_ALIGNMENT; (*session_ptr)->padding_boundary = NGHTTP2_PADDING_BOUNDARY;
} }
(*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE; (*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE;
@ -1123,7 +1123,7 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
&session->aob.framebufoff, &session->aob.framebufoff,
&frame->headers, &frame->headers,
&session->hd_deflater, &session->hd_deflater,
session->pad_alignment); session->padding_boundary);
if(framebuflen < 0) { if(framebuflen < 0) {
return framebuflen; return framebuflen;
} }
@ -4227,11 +4227,11 @@ ssize_t nghttp2_session_pack_data(nghttp2_session *session,
frame->hd.flags &= ~(NGHTTP2_FLAG_PAD_HIGH | NGHTTP2_FLAG_PAD_LOW); frame->hd.flags &= ~(NGHTTP2_FLAG_PAD_HIGH | NGHTTP2_FLAG_PAD_LOW);
flags = 0; flags = 0;
if(session->pad_alignment && if(session->padding_boundary &&
payloadlen > 0 && (size_t)payloadlen < datamax) { payloadlen > 0 && (size_t)payloadlen < datamax) {
rv = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr, rv = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr,
&flags, payloadlen, datamax, &flags, payloadlen, datamax,
session->pad_alignment); session->padding_boundary);
if(rv < 0) { if(rv < 0) {
return rv; return rv;
} }

View File

@ -153,8 +153,8 @@ struct nghttp2_session {
size_t num_incoming_streams; size_t num_incoming_streams;
/* The number of bytes allocated for nvbuf */ /* The number of bytes allocated for nvbuf */
size_t nvbuflen; size_t nvbuflen;
/* padding alignemnt. See NGHTTP2_OPT_PAD_ALIGNMENT. */ /* padding alignemnt. See NGHTTP2_OPT_PADDING_BOUNDARY. */
size_t pad_alignment; size_t padding_boundary;
/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */
uint32_t next_stream_id; uint32_t next_stream_id;
/* The largest stream ID received so far */ /* The largest stream ID received so far */

View File

@ -66,7 +66,7 @@ const std::string NGHTTPD_SERVER = "nghttpd nghttp2/" NGHTTP2_VERSION;
Config::Config() Config::Config()
: data_ptr(nullptr), : data_ptr(nullptr),
output_upper_thres(1024*1024), output_upper_thres(1024*1024),
pad_alignment(NGHTTP2_PAD_ALIGNMENT), padding_boundary(NGHTTP2_PADDING_BOUNDARY),
header_table_size(-1), header_table_size(-1),
port(0), port(0),
verbose(false), verbose(false),
@ -365,11 +365,11 @@ int Http2Handler::on_connect()
nghttp2_opt_set opt_set; nghttp2_opt_set opt_set;
memset(&opt_set, 0, sizeof(opt_set)); memset(&opt_set, 0, sizeof(opt_set));
opt_set.pad_alignment = sessions_->get_config()->pad_alignment; opt_set.padding_boundary = sessions_->get_config()->padding_boundary;
fill_callback(callbacks, sessions_->get_config()); fill_callback(callbacks, sessions_->get_config());
r = nghttp2_session_server_new2(&session_, &callbacks, this, r = nghttp2_session_server_new2(&session_, &callbacks, this,
NGHTTP2_OPT_PAD_ALIGNMENT, &opt_set); NGHTTP2_OPT_PADDING_BOUNDARY, &opt_set);
if(r != 0) { if(r != 0) {
return r; return r;
} }

View File

@ -56,7 +56,7 @@ struct Config {
std::string cert_file; std::string cert_file;
void *data_ptr; void *data_ptr;
size_t output_upper_thres; size_t output_upper_thres;
size_t pad_alignment; size_t padding_boundary;
ssize_t header_table_size; ssize_t header_table_size;
uint16_t port; uint16_t port;
bool verbose; bool verbose;

View File

@ -82,7 +82,7 @@ struct Config {
std::string keyfile; std::string keyfile;
std::string datafile; std::string datafile;
size_t output_upper_thres; size_t output_upper_thres;
size_t pad_alignment; size_t padding_boundary;
ssize_t peer_max_concurrent_streams; ssize_t peer_max_concurrent_streams;
ssize_t header_table_size; ssize_t header_table_size;
int32_t pri; int32_t pri;
@ -100,7 +100,7 @@ struct Config {
bool continuation; bool continuation;
Config() Config()
: output_upper_thres(1024*1024), : output_upper_thres(1024*1024),
pad_alignment(NGHTTP2_PAD_ALIGNMENT), padding_boundary(NGHTTP2_PADDING_BOUNDARY),
peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS), peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS),
header_table_size(-1), header_table_size(-1),
pri(NGHTTP2_PRI_DEFAULT), pri(NGHTTP2_PRI_DEFAULT),
@ -716,10 +716,10 @@ struct HttpClient {
} }
nghttp2_opt_set opt_set; nghttp2_opt_set opt_set;
opt_set.peer_max_concurrent_streams = config.peer_max_concurrent_streams; opt_set.peer_max_concurrent_streams = config.peer_max_concurrent_streams;
opt_set.pad_alignment = config.pad_alignment; opt_set.padding_boundary = config.padding_boundary;
rv = nghttp2_session_client_new2(&session, callbacks, this, rv = nghttp2_session_client_new2(&session, callbacks, this,
NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS | NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS |
NGHTTP2_OPT_PAD_ALIGNMENT, NGHTTP2_OPT_PADDING_BOUNDARY,
&opt_set); &opt_set);
if(rv != 0) { if(rv != 0) {
return -1; return -1;
@ -1710,8 +1710,8 @@ void print_help(std::ostream& out)
<< " is large enough as it is seen as unlimited.\n" << " is large enough as it is seen as unlimited.\n"
<< " -c, --header-table-size=<N>\n" << " -c, --header-table-size=<N>\n"
<< " Specify decoder header table size.\n" << " Specify decoder header table size.\n"
<< " -b, --pad=<ALIGNMENT>\n" << " -b, --padding=<BOUNDARY>\n"
<< " Alignment of frame payload padding.\n" << " Padding boundary for frame payload.\n"
<< " --color Force colored log output.\n" << " --color Force colored log output.\n"
<< " --continuation Send large header to test CONTINUATION.\n" << " --continuation Send large header to test CONTINUATION.\n"
<< std::endl; << std::endl;
@ -1740,7 +1740,7 @@ int main(int argc, char **argv)
{"pri", required_argument, nullptr, 'p'}, {"pri", required_argument, nullptr, 'p'},
{"peer-max-concurrent-streams", required_argument, nullptr, 'M'}, {"peer-max-concurrent-streams", required_argument, nullptr, 'M'},
{"header-table-size", required_argument, nullptr, 'c'}, {"header-table-size", required_argument, nullptr, 'c'},
{"data-pad", required_argument, nullptr, 'b'}, {"padding", required_argument, nullptr, 'b'},
{"cert", required_argument, &flag, 1}, {"cert", required_argument, &flag, 1},
{"key", required_argument, &flag, 2}, {"key", required_argument, &flag, 2},
{"color", no_argument, &flag, 3}, {"color", no_argument, &flag, 3},
@ -1766,7 +1766,7 @@ int main(int argc, char **argv)
print_help(std::cout); print_help(std::cout);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'b': case 'b':
config.pad_alignment = strtol(optarg, nullptr, 10); config.padding_boundary = strtol(optarg, nullptr, 10);
break; break;
case 'n': case 'n':
config.null_out = true; config.null_out = true;

View File

@ -115,8 +115,8 @@ void print_help(std::ostream& out)
<< " -p/=/foo.png -p/doc=/bar.css\n" << " -p/=/foo.png -p/doc=/bar.css\n"
<< " PATH and PUSH_PATHs are relative to document\n" << " PATH and PUSH_PATHs are relative to document\n"
<< " root. See --htdocs option.\n" << " root. See --htdocs option.\n"
<< " -b, --pad=<ALIGNMENT>\n" << " -b, --padding=<BOUNDARY>\n"
<< " Alignment of frame payload padding.\n" << " Padding boundary for frame payload.\n"
<< " -h, --help Print this help.\n" << " -h, --help Print this help.\n"
<< std::endl; << std::endl;
} }
@ -136,7 +136,7 @@ int main(int argc, char **argv)
{"verify-client", no_argument, nullptr, 'V'}, {"verify-client", no_argument, nullptr, 'V'},
{"header-table-size", required_argument, nullptr, 'c'}, {"header-table-size", required_argument, nullptr, 'c'},
{"push", required_argument, nullptr, 'p'}, {"push", required_argument, nullptr, 'p'},
{"data-pad", required_argument, nullptr, 'b'}, {"padding", required_argument, nullptr, 'b'},
{"no-tls", no_argument, &flag, 1}, {"no-tls", no_argument, &flag, 1},
{"color", no_argument, &flag, 2}, {"color", no_argument, &flag, 2},
{nullptr, 0, nullptr, 0} {nullptr, 0, nullptr, 0}
@ -155,7 +155,7 @@ int main(int argc, char **argv)
config.verify_client = true; config.verify_client = true;
break; break;
case 'b': case 'b':
config.pad_alignment = strtol(optarg, nullptr, 10); config.padding_boundary = strtol(optarg, nullptr, 10);
break; break;
case 'd': case 'd':
config.htdocs = optarg; config.htdocs = optarg;

View File

@ -3870,7 +3870,7 @@ void test_nghttp2_session_pack_data_with_padding(void)
data_prd.read_callback = fixed_length_data_source_read_callback; data_prd.read_callback = fixed_length_data_source_read_callback;
nghttp2_session_client_new(&session, &callbacks, &ud); nghttp2_session_client_new(&session, &callbacks, &ud);
session->pad_alignment = 512; session->padding_boundary = 512;
nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, &data_prd, nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, &data_prd,
NULL); NULL);
@ -3881,7 +3881,7 @@ void test_nghttp2_session_pack_data_with_padding(void)
CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type);
frame = OB_DATA(session->aob.item); frame = OB_DATA(session->aob.item);
CU_ASSERT(session->pad_alignment - datalen == frame->padlen); CU_ASSERT(session->padding_boundary - datalen == frame->padlen);
CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW);
CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH);
@ -3905,7 +3905,7 @@ void test_nghttp2_session_pack_data_with_padding(void)
CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type);
frame = OB_DATA(session->aob.item); frame = OB_DATA(session->aob.item);
CU_ASSERT((frame->padlen + datalen) % session->pad_alignment == 0); CU_ASSERT((frame->padlen + datalen) % session->padding_boundary == 0);
CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW);
CU_ASSERT(0 == (frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH)); CU_ASSERT(0 == (frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH));