mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
minimal: minimal-ws-client-spam
This commit is contained in:
parent
129d080a8a
commit
0a0b88174d
9 changed files with 522 additions and 4 deletions
|
@ -268,7 +268,7 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len)
|
|||
LWS_ERRNO == LWS_EINTR)
|
||||
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
||||
|
||||
lwsl_notice("error on reading from skt : %d\n", LWS_ERRNO);
|
||||
lwsl_info("error on reading from skt : %d\n", LWS_ERRNO);
|
||||
return LWS_SSL_CAPABLE_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|name|demonstrates|
|
||||
---|---
|
||||
minimal-ws-client-echo|Simple client that connects to a ws server and echos anything the server sends
|
||||
minimal-ws-client-ping|Ws ping test client
|
||||
minimal-ws-client-pmd-bulk|Client that sends bulk multifragment data to the minimal-ws-server-pmd-bulk example
|
||||
minimal-ws-client-rx|Connects to the dumb-increment-protocol wss server at https://libwebsockets.org and demonstrates receiving ws data
|
||||
minimal-ws-client-spam|Spams ws connections in parallel to a server for stability testing
|
||||
minimal-ws-client-tx|Connects to the minimal-ws-broker example as a publisher, demonstrating sending ws data
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
set(SAMP lws-minimal-ws-client-spam)
|
||||
set(SRCS minimal-ws-client-spam.c)
|
||||
|
||||
MACRO(require_pthreads result)
|
||||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
endif()
|
||||
ENDMACRO()
|
||||
# If we are being built as part of lws, confirm current build config supports
|
||||
# reqconfig, else skip building ourselves.
|
||||
#
|
||||
# If we are being built externally, confirm installed lws was configured to
|
||||
# support reqconfig, else error out with a helpful message about the problem.
|
||||
#
|
||||
MACRO(require_lws_config reqconfig _val result)
|
||||
|
||||
if (DEFINED ${reqconfig})
|
||||
if (${reqconfig})
|
||||
set (rq 1)
|
||||
else()
|
||||
set (rq 0)
|
||||
endif()
|
||||
else()
|
||||
set(rq 0)
|
||||
endif()
|
||||
|
||||
if (${_val} EQUAL ${rq})
|
||||
set(SAME 1)
|
||||
else()
|
||||
set(SAME 0)
|
||||
endif()
|
||||
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME})
|
||||
if (${_val})
|
||||
message("${SAMP}: skipping as lws being built without ${reqconfig}")
|
||||
else()
|
||||
message("${SAMP}: skipping as lws built with ${reqconfig}")
|
||||
endif()
|
||||
set(${result} 0)
|
||||
else()
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(MET ${SAME})
|
||||
else()
|
||||
CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig})
|
||||
if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig})
|
||||
set(HAS_${reqconfig} 0)
|
||||
else()
|
||||
set(HAS_${reqconfig} 1)
|
||||
endif()
|
||||
if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val}))
|
||||
set(MET 1)
|
||||
else()
|
||||
set(MET 0)
|
||||
endif()
|
||||
endif()
|
||||
if (NOT MET)
|
||||
if (${_val})
|
||||
message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}")
|
||||
else()
|
||||
message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
set(requirements 1)
|
||||
require_pthreads(requirements)
|
||||
require_lws_config(LWS_ROLE_WS 1 requirements)
|
||||
require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
|
||||
|
||||
if (requirements)
|
||||
add_executable(${SAMP} ${SRCS})
|
||||
|
||||
if (websockets_shared)
|
||||
target_link_libraries(${SAMP} websockets_shared pthread)
|
||||
add_dependencies(${SAMP} websockets_shared pthread)
|
||||
else()
|
||||
target_link_libraries(${SAMP} websockets pthread)
|
||||
endif()
|
||||
endif()
|
53
minimal-examples/ws-client/minimal-ws-client-spam/README.md
Normal file
53
minimal-examples/ws-client/minimal-ws-client-spam/README.md
Normal file
|
@ -0,0 +1,53 @@
|
|||
# lws minimal ws client SPAM
|
||||
|
||||
This connects to libwebsockets.org using the lws-mirror-protocol.
|
||||
|
||||
By default is has 10 concurrent connections and connects 100 times.
|
||||
|
||||
## build
|
||||
|
||||
```
|
||||
$ cmake . && make
|
||||
```
|
||||
|
||||
## Commandline Options
|
||||
|
||||
Option|Meaning
|
||||
---|---
|
||||
-d|Set logging verbosity
|
||||
--server|Use a specific server instead of libwebsockets.org, eg `--server localhost`. Implies LCCSCF_ALLOW_SELFSIGNED
|
||||
--port|Use a specific port instead of 443, eg `--port 7681`
|
||||
-c|Amount of concurrent connections
|
||||
-l|Test limit (total number of connections to make)
|
||||
|
||||
## usage
|
||||
|
||||
Just run it, it will repeatedly connect and reconnect to libwebsockets.org
|
||||
until it hits the test limit.
|
||||
|
||||
You can also direct it to use the lws test server in tls mode by running that
|
||||
with `libwebsockets-test-server -s` and running this using, eg
|
||||
|
||||
```
|
||||
$ ./lws-minimal-ws-client-spam -c 20 -l 200 --server localhost --port 7681
|
||||
```
|
||||
|
||||
```
|
||||
$ ./lws-minimal-ws-client-spam
|
||||
[2018/11/15 09:53:19:9639] USER: LWS minimal ws client SPAM
|
||||
[2018/11/15 09:53:19:9647] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
|
||||
[2018/11/15 09:53:19:9695] NOTICE: created client ssl context for default
|
||||
[2018/11/15 09:53:21:0976] USER: callback_minimal_spam: established (try 10, est 0, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1041] USER: callback_minimal_spam: established (try 10, est 1, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1089] USER: callback_minimal_spam: established (try 10, est 2, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1132] USER: callback_minimal_spam: established (try 10, est 3, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1166] USER: callback_minimal_spam: established (try 10, est 4, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1531] USER: callback_minimal_spam: established (try 10, est 5, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1563] USER: callback_minimal_spam: established (try 10, est 6, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1589] USER: callback_minimal_spam: established (try 10, est 7, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1616] USER: callback_minimal_spam: established (try 10, est 8, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:1671] USER: callback_minimal_spam: established (try 10, est 9, closed 0, err 0)
|
||||
[2018/11/15 09:53:21:3778] USER: callback_minimal_spam: reopening (try 11, est 10, closed 1, err 0)
|
||||
...
|
||||
```
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIGCDCCA/CgAwIBAgIQKy5u6tl1NmwUim7bo3yMBzANBgkqhkiG9w0BAQwFADCB
|
||||
hTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
|
||||
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNV
|
||||
BAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQwMjEy
|
||||
MDAwMDAwWhcNMjkwMjExMjM1OTU5WjCBkDELMAkGA1UEBhMCR0IxGzAZBgNVBAgT
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
||||
YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
|
||||
6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
|
||||
Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
|
||||
c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
|
||||
mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,255 @@
|
|||
/*
|
||||
* lws-minimal-ws-client-spam
|
||||
*
|
||||
* Copyright (C) 2018 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* This file is made available under the Creative Commons CC0 1.0
|
||||
* Universal Public Domain Dedication.
|
||||
*
|
||||
* This demonstrates a ws client that makes continuous mass ws connections
|
||||
* asynchronously
|
||||
*/
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
enum {
|
||||
CLIENT_IDLE,
|
||||
CLIENT_CONNECTING,
|
||||
CLIENT_AWAITING_SEND,
|
||||
};
|
||||
|
||||
struct client {
|
||||
struct lws *wsi;
|
||||
int index;
|
||||
int state;
|
||||
};
|
||||
|
||||
static struct lws_context *context;
|
||||
static struct client clients[200];
|
||||
static int interrupted, port = 443, ssl_connection = LCCSCF_USE_SSL;
|
||||
static const char *server_address = "libwebsockets.org",
|
||||
*pro = "lws-mirror-protocol";
|
||||
static int concurrent = 10, conn, tries, est, errors, closed, limit = 100;
|
||||
|
||||
struct pss {
|
||||
int conn;
|
||||
};
|
||||
|
||||
static int
|
||||
connect_client(int idx)
|
||||
{
|
||||
struct lws_client_connect_info i;
|
||||
|
||||
if (tries == limit) {
|
||||
lwsl_user("Reached limit... finishing\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&i, 0, sizeof(i));
|
||||
|
||||
i.context = context;
|
||||
i.port = port;
|
||||
i.address = server_address;
|
||||
i.path = "/";
|
||||
i.host = i.address;
|
||||
i.origin = i.address;
|
||||
i.ssl_connection = ssl_connection;
|
||||
i.protocol = pro;
|
||||
i.local_protocol_name = pro;
|
||||
i.pwsi = &clients[idx].wsi;
|
||||
|
||||
clients[idx].state = CLIENT_CONNECTING;
|
||||
tries++;
|
||||
|
||||
if (!lws_client_connect_via_info(&i)) {
|
||||
clients[idx].wsi = NULL;
|
||||
clients[idx].state = CLIENT_IDLE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
callback_minimal_spam(struct lws *wsi, enum lws_callback_reasons reason,
|
||||
void *user, void *in, size_t len)
|
||||
{
|
||||
struct pss *pss = (struct pss *)user;
|
||||
uint8_t ping[LWS_PRE + 125];
|
||||
int n, m;
|
||||
|
||||
switch (reason) {
|
||||
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
for (n = 0; n < concurrent; n++) {
|
||||
clients[n].index = n;
|
||||
connect_client(n);
|
||||
}
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
errors++;
|
||||
lwsl_err("CLIENT_CONNECTION_ERROR: %s (try %d, est %d, closed %d, err %d)\n",
|
||||
in ? (char *)in : "(null)", tries, est, closed, errors);
|
||||
for (n = 0; n < concurrent; n++) {
|
||||
if (clients[n].wsi == wsi) {
|
||||
clients[n].wsi = NULL;
|
||||
clients[n].state = CLIENT_IDLE;
|
||||
connect_client(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tries == closed + errors)
|
||||
interrupted = 1;
|
||||
break;
|
||||
|
||||
/* --- client callbacks --- */
|
||||
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
lwsl_user("%s: established (try %d, est %d, closed %d, err %d)\n",
|
||||
__func__, tries, est, closed, errors);
|
||||
est++;
|
||||
pss->conn = conn++;
|
||||
lws_callback_on_writable(wsi);
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
closed++;
|
||||
if (tries == closed + errors)
|
||||
interrupted = 1;
|
||||
if (tries == limit) {
|
||||
lwsl_user("%s: leaving CLOSED (try %d, est %d, closed %d, err %d)\n",
|
||||
__func__, tries, est, closed, errors);
|
||||
break;
|
||||
}
|
||||
|
||||
for (n = 0; n < concurrent; n++) {
|
||||
if (clients[n].wsi == wsi) {
|
||||
connect_client(n);
|
||||
lwsl_user("%s: reopening (try %d, est %d, closed %d, err %d)\n",
|
||||
__func__, tries, est, closed, errors);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n == concurrent)
|
||||
lwsl_user("CLOSED: can't find client wsi\n");
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||
n = lws_snprintf((char *)ping, sizeof(ping) - LWS_PRE,
|
||||
"hello %d", pss->conn);
|
||||
|
||||
m = lws_write(wsi, ping + LWS_PRE, n, LWS_WRITE_TEXT);
|
||||
if (m < n) {
|
||||
lwsl_err("sending ping failed: %d\n", m);
|
||||
|
||||
return -1;
|
||||
}
|
||||
lws_set_timeout(wsi, 1, LWS_TO_KILL_ASYNC);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return lws_callback_http_dummy(wsi, reason, user, in, len);
|
||||
}
|
||||
|
||||
static const struct lws_protocols protocols[] = {
|
||||
{
|
||||
"lws-spam-test",
|
||||
callback_minimal_spam,
|
||||
sizeof(struct pss),
|
||||
0,
|
||||
},
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
static void
|
||||
sigint_handler(int sig)
|
||||
{
|
||||
interrupted = 1;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
struct lws_context_creation_info info;
|
||||
const char *p;
|
||||
int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE
|
||||
/* for LLL_ verbosity above NOTICE to be built into lws,
|
||||
* lws must have been configured and built with
|
||||
* -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */
|
||||
/* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */
|
||||
/* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */
|
||||
/* | LLL_DEBUG */;
|
||||
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "-d")))
|
||||
logs = atoi(p);
|
||||
|
||||
lws_set_log_level(logs, NULL);
|
||||
lwsl_user("LWS minimal ws client SPAM\n");
|
||||
|
||||
memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
|
||||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */
|
||||
info.protocols = protocols;
|
||||
#if defined(LWS_WITH_MBEDTLS)
|
||||
/*
|
||||
* OpenSSL uses the system trust store. mbedTLS has to be told which
|
||||
* CA to trust explicitly.
|
||||
*/
|
||||
info.client_ssl_ca_filepath = "./libwebsockets.org.cer";
|
||||
#endif
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "--server"))) {
|
||||
server_address = p;
|
||||
ssl_connection |= LCCSCF_ALLOW_SELFSIGNED;
|
||||
}
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "--port")))
|
||||
port = atoi(p);
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "-l")))
|
||||
limit = atoi(p);
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "-c")))
|
||||
concurrent = atoi(p);
|
||||
|
||||
if (lws_cmdline_option(argc, argv, "-n")) {
|
||||
ssl_connection = 0;
|
||||
info.options = 0;
|
||||
}
|
||||
|
||||
if (concurrent > (int)LWS_ARRAY_SIZE(clients)) {
|
||||
lwsl_err("%s: -c %d larger than max concurrency %d\n", __func__,
|
||||
concurrent, (int)LWS_ARRAY_SIZE(clients));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
context = lws_create_context(&info);
|
||||
if (!context) {
|
||||
lwsl_err("lws init failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (n >= 0 && !interrupted)
|
||||
n = lws_service(context, 1000);
|
||||
|
||||
lws_context_destroy(context);
|
||||
|
||||
if (tries == limit && closed == tries) {
|
||||
lwsl_user("Completed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lwsl_err("Failed\n");
|
||||
|
||||
return 1;
|
||||
}
|
26
minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh
Executable file
26
minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# $1: path to minimal example binaries...
|
||||
# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1
|
||||
# that will be ./bin from your build dir
|
||||
#
|
||||
# $2: path for logs and results. The results will go
|
||||
# in a subdir named after the directory this script
|
||||
# is in
|
||||
#
|
||||
# $3: offset for test index count
|
||||
#
|
||||
# $4: total test count
|
||||
#
|
||||
# $5: path to ./minimal-examples dir in lws
|
||||
#
|
||||
# Test return code 0: OK, 254: timed out, other: error indication
|
||||
|
||||
. $5/selftests-library.sh
|
||||
|
||||
COUNT_TESTS=1
|
||||
|
||||
dotest $1 $2 warmcat
|
||||
|
||||
exit $FAILS
|
||||
|
|
@ -218,7 +218,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
if (strchr(name, '='))
|
||||
pn = strchr(name, '=') + 1;
|
||||
|
||||
lwsl_notice("%s: mirror name '%s'\n", __func__, pn);
|
||||
//lwsl_notice("%s: mirror name '%s'\n", __func__, pn);
|
||||
|
||||
/* is there already a mirror instance of this name? */
|
||||
|
||||
|
@ -229,7 +229,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
count_mi++;
|
||||
if (!strcmp(pn, mi1->name)) {
|
||||
/* yes... we will join it */
|
||||
lwsl_notice("Joining existing mi %p '%s'\n", mi1, pn);
|
||||
// lwsl_notice("Joining existing mi %p '%s'\n", mi1, pn);
|
||||
mi = mi1;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -529,7 +529,7 @@ int main(int argc, char **argv)
|
|||
"!AES256-SHA256";
|
||||
info.mounts = &mount;
|
||||
info.ip_limit_ah = 24; /* for testing */
|
||||
info.ip_limit_wsi = 105; /* for testing */
|
||||
info.ip_limit_wsi = 400; /* for testing */
|
||||
|
||||
if (use_ssl)
|
||||
/* redirect guys coming on http */
|
||||
|
|
Loading…
Add table
Reference in a new issue