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

109 commits

Author SHA1 Message Date
Andy Green
2330f69082 add braces around possibly preprocesssor removed helper 2020-08-31 16:51:36 +01:00
Andy Green
944ef24e67 coverity: 10600: make sure vhosts get off the pending destruction list if on it 2020-08-19 06:52:47 +01:00
Andy Green
a743a2b234 coverity: 62207: we only need to compute the flag if LWS_WITH_SYS_ASYNC_DNS 2020-08-18 14:00:54 +01:00
Andy Green
1a93e73402 fakewsi: replace with smaller substructure
Currently we always reserve a fakewsi per pt so events that don't have a related actual
wsi, like vhost-protocol-init or vhost cert init via protocol callback can make callbacks
that look reasonable to user protocol handler code expecting a valid wsi every time.

This patch splits out stuff that user callbacks often unconditionally expect to be in
a wsi, like context pointer, vhost pointer etc into a substructure, which is composed
into struct lws at the top of it.  Internal references (struct lws is opaque, so there
are only internal references) are all updated to go via the substructre, the compiler
should make that a NOP.

Helpers are added when fakewsi is used and referenced.

If not PLAT_FREERTOS, we continue to provide a full fakewsi in the pt as before,
although the helpers improve consistency by zeroing down the substructure.  There is
a huge amount of user code out there over the last 10 years that did not always have
the minimal examples to follow, some of it does some unexpected things.

If it is PLAT_FREERTOS, that is a newer thing in lws and users have the benefit of
being able to follow the minimal examples' approach.  For PLAT_FREERTOS we don't
reserve the fakewsi in the pt any more, saving around 800 bytes.  The helpers then
create a struct lws_a (the substructure) on the stack, zero it down (but it is only
like 4 pointers) and prepare it with whatever we know like the context.

Then we cast it to a struct lws * and use it in the user protocol handler call.
In this case, the remainder of the struct lws is undefined.  However the amount of
old protocol handlers that might touch things outside of the substructure in
PLAT_FREERTOS is very limited compared to legacy lws user code and the saving is
significant on constrained devices.

User handlers should not be touching everything in a wsi every time anyway, there
are several cases where there is no valid wsi to do the call with.  Dereference of
things outside the substructure should only happen when the callback reason shows
there is a valid wsi bound to the activity (as in all the minimal examples).
2020-07-20 06:28:52 +01:00
Andy Green
4939b87e66 lws_netdev: use lws_settings
Perform the AP selection using lws_settings and a generic scan state machine
2020-07-07 15:23:19 +01:00
Andy Green
b72ab32c17 lws_netdev 2020-07-02 10:36:31 +01:00
Andy Green
286cf4357a sul: multiple timer domains
Adapt the pt sul owner list to be an array, and define two different lists,
one that acts like before and is the default for existing users, and another
that has the ability to cooperate with systemwide suspend to restrict the
interval spent suspended so that it will wake in time for the earliest
thing on this wake-suspend sul list.

Clean the api a bit and add lws_sul_cancel() that only needs the sul as the
argument.

Add a flag for client creation info to indicate that this client connection
is important enough that, eg, validity checking it to detect silently dead
connections should go on the wake-suspend sul list.  That flag is exposed in
secure streams policy so it can be added to a streamtype with
"swake_validity": true

Deprecate out the old vhost timer stuff that predates sul.  Add a flag
LWS_WITH_DEPRECATED_THINGS in cmake so users can get it back temporarily
before it will be removed in a v4.2.

Adapt all remaining in-tree users of it to use explicit suls.
2020-06-02 08:37:10 +01:00
Andy Green
36ec353dac client: allow setting overall connect timeout from vh init
Add a member to the vh init struct allowing control of the overall
connection wait introduced in an earlier patch.  Set it to 20s
by default.


The timeout_secs member controls the individual DNS result
connect timeout and is reduced to 5s by default.
2020-05-26 17:05:39 +01:00
Andy Green
a8eebc47a5 smp: helgrind and sai lock fixes 2020-04-15 20:57:56 +01:00
Andy Green
eca75ee14d http: pipelining: fixes from xenial sai 2020-04-15 20:35:13 +01:00
Jaco Kroon
33c9a6da4c vhost: Fix unused var warning with some SOCKS5
after 6bb116b8d8 the variable p could be
declared without being used.

https://bugs.gentoo.org/716386 refers.

This just fixes that.
2020-04-06 17:40:19 +01:00
Andy Green
e26f83bd83 ss: add support for raw-skt protocol 2020-03-28 16:20:50 +00:00
Andy Green
28ce32af64 client: secure streams
Secure Streams is an optional layer on top of lws that separates policy
like endpoint selection and tls cert validation into a device JSON
policy document.

Code that wants to open a client connection just specifies a streamtype name,
and no longer deals with details like the endpoint, the protocol (!) or anything
else other than payloads and optionally generic metadata; the JSON policy
contains all the details for each streamtype.  h1, h2, ws and mqtt client
connections are supported.

Logical secure streams outlive any particular connection and supports "nailed-up"
connectivity regardless of underlying connection stability.
2020-03-04 12:17:49 +00:00
Sakthi Kannan
9d099ba7be client: MQTT
Adds client support for MQTT QoS0 and QoS1, compatible with AWS IoT

Supports stream binding where independent client connections to the
same endpoint can mux on a single tcp + tls connection with topic
routing managed internally.
2020-03-04 12:17:49 +00:00
Andy Green
ed04a266ea rtos diet: make raw_file role optional 2020-03-04 11:00:04 +00:00
Andy Green
6bb116b8d8 socks5: cleanup and add test options
Refactor SOCKS5 client support to be gathered into
lib/core-net/socks5-client.c and make that build
contingent on LWS_WITH_SOCKS5.
2020-03-01 08:14:44 +00:00
Andy Green
ac1229f2f7 minimal-http-client-multi: add POST
This adds support for POST in both h1 and h2 queues / stream binding.

The previous queueing tried to keep the "leader" wsi who made the
actual connection around and have it act on the transaction queue
tail if it had done its own thing.

This refactors it so instead, who is the "leader" moves down the
queue and the queued guys inherit the fd, SSL * and queue from the
old leader as they take over.

This lets them operate in their own wsi identity directly and gets
rid of all the "effective wsi" checks, which was applied incompletely
and getting out of hand considering the separate lws_mux checks for
h2 and other muxed protocols alongside it.

This change also allows one wsi at a time to own the transaction for
POST.  --post is added as an option to lws-minimal-http-client-multi
and 6 extra selftests with POST on h1/h2, pipelined or not and
staggered or not are added to the CI.
2020-02-21 17:32:41 +00:00
Andy Green
fddca26be0 windows: handle pipe destroy when no fd associated with pipe wsi
https://github.com/warmcat/libwebsockets/issues/1839
2020-02-21 17:32:41 +00:00
Andy Green
271ca836c8 event lib: update http client multi to work with it and clean destroy flow
Add selectable event lib support to minimal-http-client-multi and
clean up context destroy flow so we can use lws_destroy_context() from
inside the callback to indicate we want to end the event loop, without
using the traditional "interrupted" flag and in a way that works no
matter which event loop backend is being used.
2020-02-04 14:16:18 +00:00
Andy Green
6f8b606811 h2: stream binding: do not try to join existing connection until migrated 2020-01-17 18:54:44 +00:00
Andy Green
09ba5c6789 freertos: lws_cancel_service udp as pipe
Freertos + lwip doesn't support pipe2() or pipe()... implement a "pipe"
based on two UDP sockets, one listening on 127.0.0.1:54321 and the other
doing a sendto() there of a single byte to interrupt the event loop wait.

Re-use the arrangements for actual pipe fds and pipe role to deliver
lws_cancel_service() functionality using this.
2020-01-15 19:52:41 +00:00
Andy Green
b0b8a684ed event-ops: rename accept member to sock_accept
Some toolchains have lwip accept() as a preprocessor define...
2020-01-15 12:20:50 +00:00
Andy Green
86fe71fdf3 lws_get_random: change length to size_t for coverity 2020-01-11 07:58:37 +00:00
Jaco Kroon
04ec3d6f73 build options: fix SOCKS5 and WITHOUT_CLIENT
Signed-off-by: Jaco Kroon <jaco@iewc.co.za>
2020-01-08 16:41:52 +00:00
Andy Green
0bfd39135e cleaning 2020-01-05 22:17:58 +00:00
Andy Green
1eb4d335d2 active_conns: move out dependency on ah 2019-12-23 09:25:56 +00:00
Andy Green
c327c7fdb7 vhost destruction: dont allow all wsi closures to kill vh we are already in process of destroying
Saw this on travis selftests during context destroy

==18895== Invalid read of size 8
==18895==    at 0x415909: __lws_vhost_destroy2 (vhost.c:1063)
==18895==    by 0x40E65B: lws_context_destroy2 (context.c:929)
==18895==    by 0x40EBE5: lws_context_destroy (context.c:1128)
==18895==    by 0x40CC41: main (minimal-http-client-post.c:267)
==18895==  Address 0x6168688 is 728 bytes inside a block of size 792 free'd
==18895==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18895==    by 0x45B29E: _realloc (alloc.c:120)
==18895==    by 0x45B2D6: lws_realloc (alloc.c:130)
==18895==    by 0x415ED7: __lws_vhost_destroy2 (vhost.c:1204)
==18895==    by 0x419164: lws_vhost_unbind_wsi (wsi.c:82)
==18895==    by 0x41236B: __lws_free_wsi (close.c:154)
==18895==    by 0x4134CF: __lws_close_free_wsi_final (close.c:650)
==18895==    by 0x4133BA: __lws_close_free_wsi (close.c:610)
==18895==    by 0x413528: lws_close_free_wsi (close.c:660)
==18895==    by 0x4158C7: __lws_vhost_destroy2 (vhost.c:1053)
==18895==    by 0x40E65B: lws_context_destroy2 (context.c:929)
==18895==    by 0x40EBE5: lws_context_destroy (context.c:1128)

Removing the last wsi from the vhost we started to destroy finalized the
vhost destruction, which is aimed at libuv async close cleanup.  But if
we already entered __lws_vhost_destroy2, we will definitely destroy the vhost
ourselves at the end of that function already.  So defeat the wsi close
triggering it.
2019-12-22 18:17:45 +00:00
Andy Green
ba8402b43f coverity: use function comments to clear false positives 2019-10-12 12:41:14 +01:00
Andy Green
fc295b7959 muxable client: make http support generic
h1 and h2 has a bunch of code supporting autobinding outgoing client connections
to be streams in, or queued as pipelined on, the same / existing single network
connection, if it's to the same endpoint.

Adapt this http-specific code and active connection tracking to be usable for
generic muxable protocols the same way.
2019-10-10 16:34:37 +01:00
Andy Green
04f99f1499 lws_retry: udp support 2019-10-10 16:34:37 +01:00
Andy Green
bce1f01370 lws_state and system state
Introduce a generic lws_state object with notification handlers
that may be registered in a chain.

Implement one of those in the context to manage the "system state".

Allow other pieces of lws and user code to register notification
handlers on a context list.  Handlers can object to or take over
responsibility to move forward and retry system state changes if
they know that some dependent action must succeed first.

For example if the system time is invalid, we cannot move on to
a state where anything can do tls until that has been corrected.
2019-09-22 09:35:07 -07:00
Andy Green
f9f6bb66fe lws_validity: unified connection validity tracking
Refactor everything around ping / pong handling in ws and h2, so there
is instead a protocol-independent validity lws_sul tracking how long it
has been since the last exchange that confirms the operation of the
network connection in both directions.

Clean out periodic role callback and replace the last two role users
with discrete lws_sul for each pt.
2019-09-22 09:35:07 -07:00
Andy Green
4e8497b28a context-vhost options: move to uint64_t 2019-09-22 03:08:36 -07:00
Andy Green
d808748cd6 detailed latency stats
Remove LWS_LATENCY.

Add the option LWS_WITH_DETAILED_LATENCY, allowing lws to collect very detailed
information on every read and write, and allow the user code to provide
a callback to process events.
2019-09-22 03:06:59 -07:00
Andy Green
c591e1adfc asynchronous dns for ipv4 and ipv6
This adds the option to have lws do its own dns resolution on
the event loop, without blocking.  Existing implementations get
the name resolution done by the libc, which is blocking.  In
the case you are opening client connections but need to carefully
manage latency, another connection opening and doing the name
resolution becomes a big problem.

Currently it supports

 - ipv4 / A records
 - ipv6 / AAAA records
 - ipv4-over-ipv6 ::ffff:1.2.3.4 A record promotion for ipv6
 - only one server supported over UDP :53
 - nameserver discovery on linux, windows, freertos

It also has some nice advantages

 - lws-style paranoid response parsing
 - random unique tid generation to increase difficulty of poisoning
 - it's really integrated with the lws event loop, it does not spawn
   threads or use the libc resolver, and of course no blocking at all
 - platform-specific server address capturing (from /etc/resolv.conf
   on linux, windows apis on windows)
 - it has LRU caching
 - piggybacking (multiple requests before the first completes go on
   a list on the first request, not spawn multiple requests)
 - observes TTL in cache
 - TTL and timeout use lws_sul timers on the event loop
 - ipv6 pieces only built if cmake LWS_IPV6 enabled
2019-09-19 06:54:53 +01:00
Andy Green
0fa5563d18 freertos: rename esp32 plat to freertos 2019-08-26 09:58:57 +01:00
Andy Green
ae69bfbd10 debloat: remove things from being built by default that should be conditional 2019-08-26 09:58:57 +01:00
Andy Green
c36a1e8ed0 clean: internally use LWS_WITH_CLIENT and _SERVER
Remove some more things in LWS_WITH_SERVER=0 case
2019-08-26 09:58:57 +01:00
Andy Green
f8afcd0e5c client: make external http proxying optional
Add LWS_CLIENT_HTTP_PROXYING on by default.  Removing it saves a few
hundred bytes of code and 128 bytes per vhost in heap.
2019-08-26 09:58:57 +01:00
Andy Green
d7f0521aeb private.h: rename to contain dir
Having unique private header names is a requirement of a particular
platform build system it's desirable to work with
2019-08-15 10:49:52 +01:00
Andy Green
26319663f7 license: switch LGPLv2.1+SLE parts to MIT 2019-08-14 10:44:38 +01:00
Andy Green
45ec3ce369 lws_dll: upgrade all instances to lws_dll2
lws_dll2 removes the downsides of lws_dll and adds new features like a
running member count and explicit owner type... it's cleaner and more
robust (eg, nodes know their owner, so they can casually switch between
list owners and remove themselves without the code knowing the owner).

This deprecates lws_dll, but since it's public it allows it to continue
to be built for 4.0 release if you give cmake LWS_WITH_DEPRECATED_LWS_DLL.

All remaining internal users of lws_dll are migrated to lws_dll2.
2019-08-08 16:58:55 +01:00
Andy Green
fa8356f882 vhost: lws_get_vhost_by_name 2019-07-30 06:02:23 +01:00
Andy Green
1929f3a6c0 COVA11597: buffer http_proxy env var before using 2019-07-13 13:28:54 -07:00
Andy Green
e4ec282987 coverity: 2019.03 fixes 2019-07-01 06:39:55 +01:00
Andy Green
a7e1bac4ac unit test sequencer 2019-06-29 21:08:36 +01:00
Andy Green
0ada40ce92 abstract: allow completely generic instantiation and destruction 2019-06-26 14:33:34 +01:00
Andy Green
b3d6e28bc7 lws_sequencer 2019-06-25 12:10:18 +01:00
Chen Xi
892cde2c71 rtos: add support for AMAZON_RTOS 2019-06-05 05:04:17 +01:00
Andy Green
8d473ad78c smtp: make abstract 2019-05-04 08:28:31 +01:00