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

106 commits

Author SHA1 Message Date
Andy Green
2ea2c37f9d h2: data: frame header already parsed out 2021-08-13 05:45:51 +01:00
Andy Green
edcf346f9f h2: migration: migrate for_ss
The attribute indicating that a wsi belongs to an SS object also must be
migrated when we split out the original transaction wsi into a new nwsi, if we're
not going to lose track of its affiliation.

Likewise if the affiliated SS object points to the original wsi, we have to
migrate his pointer when we migrate the wsi.

Taking care of this book-keeping is necessary to get correct behaviours at
close-time.
2021-05-20 14:07:01 +01:00
Andy Green
354b29c747 http: redirect: dont try from h2 at the moment
h1->h1, h1->h2 are OK, but h2->anything needs more work.
Just fail it early at the moment.
2021-04-10 09:20:33 +01:00
Andy Green
7d8f742594 smp: more lock assertions 2021-04-05 10:55:04 +01:00
Andy Green
51490ae6e6 Fault injection
add lws_xos: xoshiro256 PRNG
2021-04-05 10:55:04 +01:00
Andy Green
ffb49e2612 http: post: defer body pending end until no more buffered out 2021-03-25 08:40:52 +00:00
Andy Green
06509e287d lws_conmon: connection monitoring and stats generation
This provides a build option LWS_WITH_CONMON that lets user code recover
detailed connection stats on client connections with the LCCSCF_CONMON
flag.

In addition to latencies for dns, socket connection, tls and first protocol
response where possible, it also provides the user code an unfiltered list
of DNS responses that the client received, and the peer it actually
succeded to connect to.
2021-03-17 07:31:49 +00:00
Andy Green
3f4623bb36 lws_metrics
There are a few build options that are trying to keep and report
various statistics

 - DETAILED_LATENCY
 - SERVER_STATUS
 - WITH_STATS

remove all those and establish a generic rplacement, lws_metrics.

lws_metrics makes its stats available via an lws_system ops function
pointer that the user code can set.

Openmetrics export is supported, for, eg, prometheus scraping.
2021-03-08 21:47:28 +00:00
Andy Green
ede7f8b0f3 ss: support huge urls 2021-03-05 14:13:26 +00:00
Andy Green
09b9ac6e33 minimal-http-client: set option to fix broken server window update 2021-02-28 12:10:26 +00:00
Andy Green
f42c97baa9 route: on change also check source address still extant 2021-02-17 11:39:12 +00:00
Yichen Gu
403a6591e1 h2: client: handle END_STREAM and END_HEADERS togther on all paths 2021-01-29 21:22:35 +00:00
Andy Green
1236114303 h2: client: action END_STREAM and END_HEADERS immediately 2021-01-23 20:58:39 +00:00
Andy Green
95a545b741 evlib: count extant evlib handles instead of wsi 2021-01-19 17:07:33 +00:00
Andy Green
e5b191be35 h2: post buflist: track rx_content_length
On h2 server POST, there's a race to see if the POST body is going to be
received coalesced with the headers.

The problem is on h2, we can't action the stream http request or body until
the stream is writeable, since we may start issuing the response right away;
there's already DEFERRING_ACTION state to manage this.  And indeed, the
coalesced, not-immediately-actionable POST body is buflisted properly.

However when we come to action the POST using buflisted data, we don't follow
the same pattern as dealing with the incoming data immediately.

This patch aligns the pattern dumping the buflist content to track
expected rx_content_length and handle BODY_COMPLETION if we got to
the end of it, along with removal from the pt list of wsi with pending
buflists if we used it up.
2021-01-18 19:49:02 +00:00
Andy Green
9be508bdd7 h2: make sure we see END_STREAM with END_HEADERS on client 2021-01-15 19:54:14 +00:00
Andy Green
abc60c755a smd: add more scenarios to tests
Let's have 4 x forked clients all intercommunicate via the SS proxy,
and add it to ctest.
2021-01-05 10:56:38 +00:00
Andy Green
c9731c5f17 type comparisons: fixes
This is a huge patch that should be a global NOP.

For unix type platforms it enables -Wconversion to issue warnings (-> error)
for all automatic casts that seem less than ideal but are normally concealed
by the toolchain.

This is things like passing an int to a size_t argument.  Once enabled, I
went through all args on my default build (which build most things) and
tried to make the removed default cast explicit.

With that approach it neither change nor bloat the code, since it compiles
to whatever it was doing before, just with the casts made explicit... in a
few cases I changed some length args from int to size_t but largely left
the causes alone.

From now on, new code that is relying on less than ideal casting
will complain and nudge me to improve it by warnings.
2021-01-05 10:56:38 +00:00
Andy Green
0ceba15d9c lws_lifecycle
This adds some new objects and helpers for keeping and logging
info on grouped allocations, a group is, eg, SS handles or client
wsis.

Allocated objects get a context-unique "tag" string intended to replace
%p / wsi pointers etc.  Pointers quickly become confusing when
allocations are freed and reused, the tag string won't repeat
until you produce 2^64 objects in a context.

In addition the tag string documents the object group, with prefixes
like "wsi-" or "vh-" and contain object-specific additional
information like the vhost name, address / port  or the role of the wsi.
At creation time the lws code can use a format string and args
to add whatever group-specific info makes sense, eg, a wsi bound
to a secure stream can also append the guid of the secure stream,
it's copied into the new object tag and so is still available
cleanly after the stream is destroyed if the wsi outlives it.
2021-01-04 05:26:50 +00:00
Andy Green
eb5f437578 h2: post: add states to wait for body 2020-12-24 16:14:36 +00:00
Andy Green
677b6e370c h2: remove length tracking just use pointer arithmetic 2020-12-24 16:14:36 +00:00
Andy Green
e560d2c049 h2: stay a client if a client 2020-12-24 16:14:36 +00:00
Andy Green
587f24f71d clean: remove h2 debug spew 2020-12-06 19:06:05 +00:00
Andy Green
7d355912c3 h2: fix ignoring unknown frame payloads 2020-12-01 15:38:09 +00:00
Andy Green
10714c58e9 h2: ignore unknown frame types a bit earlier
Chrome has started being able to issue frame type 0x42, we drop the connection
before we realize we wanted to ignore it.

This explicitly ignores it a bit earlier.
2020-11-28 10:58:38 +00:00
Andy Green
2bcae2b3b6 context: refactor destroy flow 2020-11-28 10:58:38 +00:00
Andy Green
44e860642b docs: switch to use main 2020-10-19 16:35:03 +01:00
Andy Green
c54a35e1a9 h2: allow empty SETTINGS
https://libwebsockets.org/pipermail/libwebsockets/2020-August/008676.html
2020-08-31 16:51:37 +01:00
Andy Green
d69b91d2d9 coverity: 62123: explicitly check things to guide coverity
Coverity sees we sometimes check if header length is 0 and extrapolates
from that not checking header length return is a violation.  But often
we are OK if the header length is 0 and there is no error return to
check from that.

It also doesn't understand that if we saw a nonzero length for a header,
then we are going to get a non-null simple_ptr() return for sure.  Just
give up and explicitly, unneccessarily check everything so coverity can
stop telling us about it.
2020-08-19 07:11:59 +01:00
Andy Green
d5497d5f55 coverity: 62535: another simple_ptr NULL check after confirmed by other means 2020-08-18 14:00:54 +01:00
Andy Green
4a28bc8c87 coverity: 231739: clear false positive by needless checks
Client connection api must provide host
2020-08-14 07:27:08 +01:00
Andy Green
1f0cd18dd6 ss: server: check more carefully if built but not used on a wsi 2020-08-10 15:04:10 +01:00
Andy Green
9a7ce85001 h2: defend against no NUL possible in log 2020-08-10 15:04:10 +01:00
Andy Green
7eb36102a9 ss: server: h1, h2, ws basic support
Add initial support for defining servers using Secure Streams
policy and api semantics.

Serving h1, h2 and ws should be functional, the new minimal
example shows a combined http + SS server with an incrementing
ws message shown in the browser over tls, in around 200 lines
of user code.

NOP out anything to do with plugins, they're not currently used.

Update the docs correspondingly.
2020-07-27 12:05:24 +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
Kyle Greenwell
bebd3f71a6 h2: add prior knowledge support 2020-05-08 18:56:17 +01:00
Andy Green
401d6951da h2: client: do not apply host header if h2 negotiated by alpn
If client negotiated over alpn, it will have done SNI.  Some
peers like youtube.com reject with 400 if you sent a host: as
well.
2020-05-05 12:25:51 +01:00
Andy Green
2d3e62b112 h2: client sid: must be allocated at header send
There is no way to allocate a client wsi mux sid before the headers are
send, because we don't know the order in which new wsi headers will be sent
and so seen by the peer.

The peer inisists that sid indexes only increase... we cannot allocat sids
monotonically at the client and then send them disordered...
2020-05-05 06:34:48 +01:00
Andy Green
d339505f51 h2: cmake: build with NO_SERVER 2020-04-16 06:59:45 +01:00
Andy Green
5e99b9f3ee h2: take care to retain initial sid 2020-04-06 13:22:01 +01: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
Andy Green
9a1f184915 rtos diet: http: remove headers at buildtime according to config
Headers related to ws or h2 are now elided if the ws or h2 role
is not enabled for build.  In addition, a new build-time option
LWS_WITH_HTTP_UNCOMMON_HEADERS on by default allows removal of
less-common http headers to shrink the parser footprint.

Minilex is adapted to produce 8 different versions of the lex
table, chosen at build-time according to which headers are
included in the build.

If you don't need the unusual headers, or aren't using h2 or ws,
this chops down the size of the ah and the rodata needed to hold
the parsing table from 87 strings / pointers to 49, and the
parsing table from 1177 to 696 bytes.
2020-03-04 11:00:04 +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
774240f73b linkit: support build using public sdk
This provides support to build lws using the linkit 7697 public SDK
from here https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/downloads

This toolchain has some challenges, its int32_t / uint32_t are long,
so assumptions about format strings for those being %u / %d / %x all
break.  This fixes all the cases for the features enabled by the
default cmake settings.
2020-01-17 07:45:34 +00:00
Andy Green
0bfd39135e cleaning 2020-01-05 22:17:58 +00:00
Andy Green
9cb4f25476 h2: LCCSCF_H2_MANUAL_RXFLOW and refactor txcr
This changes the approach of tx credit management to set the
initial stream tx credit window to zero.  This is the only way
with RFC7540 to gain the ability to selectively precisely rx
flow control incoming streams.

At the time the headers are sent, a WINDOW_UPDATE is sent with
the initial tx credit towards us for that specific stream.  By
default, this acts as before with a 256KB window added for both
the stream and the nwsi, and additional window management sent
as stuff is received.

It's now also possible to set a member in the client info
struct and a new option LCCSCF_H2_MANUAL_RXFLOW to precisely
manage both the initial tx credit for a specific stream and
the ongoing rate limit by meting out further tx credit
manually.

Add another minimal example http-client-h2-rxflow demonstrating how
to force a connection's peer's initial budget to transmit to us
and control it during the connection lifetime to restrict the amount
of incoming data we have to buffer.
2020-01-02 08:31:02 +00:00
Andy Green
7221bc57b5 mux children: generalize helpers out of h2 implementation
This should be a NOP for h2 support and only affects internal
apis.  But it lets us reuse the working and reliable h2 mux
arrangements directly in other protocols later, and share code
so building for h2 + new protocols can take advantage of common
mux child handling struct and code.

Break out common mux handling struct into its own type.

Convert all uses of members that used to be in wsi->h2 to wsi->mux

Audit all references to the members and break out generic helpers
for anything that is useful for other mux-capable protocols to
reuse wsi->mux related features.
2019-12-29 19:59:16 +00:00
Andy Green
724f4e9f22 http: chunked client 2019-11-16 09:00:15 +00:00
Andy Green
c8de9bbc2d ah: drop on LONG_POLL and allow dropping client ah early 2019-11-06 21:34:14 +00:00
Andy Green
37c198d40b format strings: fixes for when toolchain has uint32_t as unsigned long 2019-11-05 21:00:45 +00:00