1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

tls restriction: account for pipelining and add test

This commit is contained in:
Andy Green 2020-02-18 10:30:12 +00:00
parent 40928ca7d6
commit 0dd23d7073
6 changed files with 38 additions and 18 deletions

View file

@ -50,10 +50,6 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
if (i->local_protocol_name)
local = i->local_protocol_name;
if ((i->ssl_connection & LCCSCF_USE_SSL) &&
lws_tls_restrict_borrow(i->context))
return NULL;
lws_stats_bump(&i->context->pt[tid], LWSSTATS_C_CONNS_CLIENT, 1);
/* PHASE 1: create a bare wsi */

View file

@ -251,13 +251,19 @@ start_ws_handshake:
#if defined(LWS_WITH_TLS)
/* we can retry this... just cook the SSL BIO the first time */
if ((wsi->tls.use_ssl & LCCSCF_USE_SSL) && !wsi->tls.ssl &&
lws_ssl_client_bio_create(wsi) < 0) {
cce = "bio_create failed";
goto bail3;
}
if (wsi->tls.use_ssl & LCCSCF_USE_SSL) {
if (!wsi->transaction_from_pipeline_queue &&
lws_tls_restrict_borrow(wsi->context)) {
cce = "tls restriction limit";
goto bail3;
}
if (!wsi->tls.ssl && lws_ssl_client_bio_create(wsi) < 0) {
cce = "bio_create failed";
goto bail3;
}
n = lws_ssl_client_connect1(wsi);
if (!n)
return 0;

View file

@ -245,8 +245,7 @@ lws_ssl_close(struct lws *wsi)
SSL_free(wsi->tls.ssl);
wsi->tls.ssl = NULL;
if (!lwsi_role_client(wsi))
lws_tls_restrict_return(wsi->context);
lws_tls_restrict_return(wsi->context);
return 1; /* handled */
}

View file

@ -61,17 +61,25 @@ lws_tls_restrict_borrow(struct lws_context *context)
/* that was the last allowed SSL connection */
lws_gate_accepts(context, 0);
lwsl_info("%s: %d -> %d\n", __func__,
context->simultaneous_ssl - 1,
context->simultaneous_ssl);
return 0;
}
void
lws_tls_restrict_return(struct lws_context *context)
{
if (context->simultaneous_ssl_restriction &&
context->simultaneous_ssl-- ==
context->simultaneous_ssl_restriction)
/* we made space and can do an accept */
lws_gate_accepts(context, 1);
if (context->simultaneous_ssl_restriction) {
if (context->simultaneous_ssl-- ==
context->simultaneous_ssl_restriction)
/* we made space and can do an accept */
lws_gate_accepts(context, 1);
lwsl_info("%s: %d -> %d\n", __func__,
context->simultaneous_ssl + 1,
context->simultaneous_ssl);
}
}
void

View file

@ -375,6 +375,9 @@ int main(int argc, const char **argv)
info.client_ssl_ca_filepath = "./warmcat.com.cer";
#endif
if ((p = lws_cmdline_option(argc, argv, "--limit")))
info.simultaneous_ssl_restriction = atoi(p);
#if defined(LWS_WITH_DETAILED_LATENCY)
info.detailed_latency_cb = lws_det_lat_plot_cb;
info.detailed_latency_filepath = "/tmp/lws-latency-results";

View file

@ -18,7 +18,7 @@
. $5/selftests-library.sh
COUNT_TESTS=22
COUNT_TESTS=30
dotest $1 $2 warmcat
dotest $1 $2 warmcat-pipe -p
@ -34,6 +34,14 @@ dotest $1 $2 warmcat-post-pipe-stag --post -p -s
dotest $1 $2 warmcat-h1-post --post --h1
dotest $1 $2 warmcat-h1-post-pipe --post --h1 -p
dotest $1 $2 warmcat-h1-post-pipe-stag --post --h1 -p -s
dotest $1 $2 warmcat-restrict-pipe --limit 1 -p
dotest $1 $2 warmcat-restrict-h1-pipe --limit 1 -p --h1
dotest $1 $2 warmcat-restrict-pipe-stag --limit 1 -p -s
dotest $1 $2 warmcat-restrict-h1-pipe-stag --limit 1 -p --h1 -s
dofailtest $1 $2 fail-warmcat-restrict --limit 1
dofailtest $1 $2 fail-warmcat-restrict-h1 --limit 1 --h1
dofailtest $1 $2 fail-warmcat-restrict-stag --limit 1 -s
dofailtest $1 $2 fail-warmcat-restrict-h1-stag --limit 1 --h1 -s
spawn "" $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls
dotest $1 $2 localhost -l