Refuse incoming SYN_STREAM with SPDYLAY_REFUSED_STREAM if max-concurrent-streams number is reached.
This commit is contained in:
parent
fa312caa06
commit
34f0f6be1b
|
@ -32,6 +32,17 @@
|
|||
|
||||
#include "spdylay_helper.h"
|
||||
|
||||
/*
|
||||
* Returns non-zero if the number of opened streams is larger than or
|
||||
* equal to SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS value.
|
||||
*/
|
||||
static int spdylay_session_get_max_concurrent_streams_reached
|
||||
(spdylay_session *session)
|
||||
{
|
||||
return session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
<= spdylay_map_size(&session->streams);
|
||||
}
|
||||
|
||||
int spdylay_session_is_my_stream_id(spdylay_session *session,
|
||||
int32_t stream_id)
|
||||
{
|
||||
|
@ -566,11 +577,10 @@ spdylay_outbound_item* spdylay_session_get_next_ob_item
|
|||
} else {
|
||||
/* Return item only when concurrent connection limit is not
|
||||
reached */
|
||||
if(session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
> spdylay_map_size(&session->streams)) {
|
||||
return spdylay_pq_top(&session->ob_ss_pq);
|
||||
} else {
|
||||
if(spdylay_session_get_max_concurrent_streams_reached(session)) {
|
||||
return NULL;
|
||||
} else {
|
||||
return spdylay_pq_top(&session->ob_ss_pq);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -580,8 +590,7 @@ spdylay_outbound_item* spdylay_session_get_next_ob_item
|
|||
spdylay_outbound_item *item, *syn_stream_item;
|
||||
item = spdylay_pq_top(&session->ob_pq);
|
||||
syn_stream_item = spdylay_pq_top(&session->ob_ss_pq);
|
||||
if(session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
<= spdylay_map_size(&session->streams) ||
|
||||
if(spdylay_session_get_max_concurrent_streams_reached(session) ||
|
||||
item->pri < syn_stream_item->pri ||
|
||||
(item->pri == syn_stream_item->pri &&
|
||||
item->seq < syn_stream_item->seq)) {
|
||||
|
@ -602,14 +611,13 @@ spdylay_outbound_item* spdylay_session_pop_next_ob_item
|
|||
} else {
|
||||
/* Pop item only when concurrent connection limit is not
|
||||
reached */
|
||||
if(session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
> spdylay_map_size(&session->streams)) {
|
||||
if(spdylay_session_get_max_concurrent_streams_reached(session)) {
|
||||
return NULL;
|
||||
} else {
|
||||
spdylay_outbound_item *item;
|
||||
item = spdylay_pq_top(&session->ob_ss_pq);
|
||||
spdylay_pq_pop(&session->ob_ss_pq);
|
||||
return item;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -622,8 +630,7 @@ spdylay_outbound_item* spdylay_session_pop_next_ob_item
|
|||
spdylay_outbound_item *item, *syn_stream_item;
|
||||
item = spdylay_pq_top(&session->ob_pq);
|
||||
syn_stream_item = spdylay_pq_top(&session->ob_ss_pq);
|
||||
if(session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
<= spdylay_map_size(&session->streams) ||
|
||||
if(spdylay_session_get_max_concurrent_streams_reached(session) ||
|
||||
item->pri < syn_stream_item->pri ||
|
||||
(item->pri == syn_stream_item->pri &&
|
||||
item->seq < syn_stream_item->seq)) {
|
||||
|
@ -962,6 +969,13 @@ static int spdylay_session_validate_syn_stream(spdylay_session *session,
|
|||
return SPDYLAY_PROTOCOL_ERROR;
|
||||
}
|
||||
}
|
||||
if(spdylay_session_get_max_concurrent_streams_reached(session)) {
|
||||
/* spdy/2 spec does not clearly say what to do when max concurrent
|
||||
streams number is reached. The mod_spdy sends
|
||||
SPDYLAY_REFUSED_STREAM and we think it is reasonable. So we
|
||||
follow it. */
|
||||
return SPDYLAY_REFUSED_STREAM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1454,8 +1468,7 @@ int spdylay_session_want_write(spdylay_session *session)
|
|||
*/
|
||||
return (session->aob.item != NULL || !spdylay_pq_empty(&session->ob_pq) ||
|
||||
(!spdylay_pq_empty(&session->ob_ss_pq) &&
|
||||
session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]
|
||||
> spdylay_map_size(&session->streams))) &&
|
||||
!spdylay_session_get_max_concurrent_streams_reached(session))) &&
|
||||
(!session->goaway_flags || spdylay_map_size(&session->streams) > 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,8 @@ int main(int argc, char* argv[])
|
|||
test_spdylay_session_on_request_recv_callback) ||
|
||||
!CU_add_test(pSuite, "session_on_stream_close",
|
||||
test_spdylay_session_on_stream_close) ||
|
||||
!CU_add_test(pSuite, "session_max_concurrent_streams",
|
||||
test_spdylay_session_max_concurrent_streams) ||
|
||||
!CU_add_test(pSuite, "frame_unpack_nv", test_spdylay_frame_unpack_nv) ||
|
||||
!CU_add_test(pSuite, "frame_count_nv_space",
|
||||
test_spdylay_frame_count_nv_space) ||
|
||||
|
|
|
@ -977,3 +977,30 @@ void test_spdylay_session_on_stream_close()
|
|||
CU_ASSERT(user_data.stream_close_cb_called == 1);
|
||||
spdylay_session_del(session);
|
||||
}
|
||||
|
||||
void test_spdylay_session_max_concurrent_streams()
|
||||
{
|
||||
spdylay_session *session;
|
||||
spdylay_session_callbacks callbacks;
|
||||
spdylay_frame frame;
|
||||
const char *nv[] = { NULL };
|
||||
spdylay_outbound_item *item;
|
||||
|
||||
memset(&callbacks, 0, sizeof(spdylay_session_callbacks));
|
||||
spdylay_session_server_new(&session, &callbacks, NULL);
|
||||
spdylay_session_open_stream(session, 1, SPDYLAY_FLAG_NONE, 3,
|
||||
SPDYLAY_STREAM_OPENED, NULL);
|
||||
spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_FLAG_NONE,
|
||||
3, 0, 3, dup_nv(nv));
|
||||
session->settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 1;
|
||||
|
||||
CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame));
|
||||
|
||||
item = spdylay_session_get_ob_pq_top(session);
|
||||
CU_ASSERT(SPDYLAY_RST_STREAM == item->frame_type);
|
||||
CU_ASSERT(SPDYLAY_REFUSED_STREAM == item->frame->rst_stream.status_code)
|
||||
|
||||
spdylay_frame_syn_stream_free(&frame.syn_stream);
|
||||
|
||||
spdylay_session_del(session);
|
||||
}
|
||||
|
|
|
@ -47,5 +47,6 @@ void test_spdylay_session_get_next_ob_item();
|
|||
void test_spdylay_session_pop_next_ob_item();
|
||||
void test_spdylay_session_on_request_recv_callback();
|
||||
void test_spdylay_session_on_stream_close();
|
||||
void test_spdylay_session_max_concurrent_streams();
|
||||
|
||||
#endif // SPDYLAY_SESSION_TEST_H
|
||||
|
|
Loading…
Reference in New Issue