1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00
libwebsockets/lib/core-net
Andy Green 2cfa260e62 sspc: refactor to allow different transports
This is a NOP for existing usecases.

At the moment the only implemented transport for serialized SS is wsi, it's
typically used with Unix Domain Sockets, but it also works over tcp the
same.

It generalizes the interface between serialized chunks and the
transport, separately for client and proxy.  The wsi transport is migrated
to use the new transport ops structs.

It will then be possible to "bring your own transport", so long as it is
reliable, and in-order, both for proxy and client / sspc.

We also adapt minimal-secure-streams-binance to build the -client variant
via SS proxy as well.

LWS_ONLY_SSPC is added so libwebsockets can be produced with just sspc
client support even for tiny targets.

A new embedded minimal example for rpi pico is also provided that
demonstrates using Serialized SS over a UART to an SS proxy, to implement
the SS Binance example on the pico, even though it has no networking itself.
2021-10-08 09:48:41 +01:00
..
client sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
adopt.c fi: wsi: fault to fake peer hangup after a delay range 2021-07-04 10:29:54 +01:00
close.c sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
CMakeLists.txt sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
dummy-callback.c server: http-proxy: fix POST 2021-08-19 05:31:15 +01:00
lws-dsh.c dsh-empty 2021-10-08 09:48:41 +01:00
network.c iface: score binds 2021-07-20 10:33:56 +01:00
output.c logs: more internal conversion to log_cx 2021-07-01 05:20:53 +01:00
pollfd.c evlib: remove PREPARE_DELETION as cruft 2021-08-21 17:44:34 +01:00
private-lib-core-net.h tls: evolve handshake serialization into simultaneous_ssl_handshake_restriction 2021-10-05 07:40:17 +01:00
README.md minimal-http-client-multi: add POST 2020-02-21 17:32:41 +00:00
route.c cmake: unbreak LWS_WITH_SYS_STATE disabled build 2021-10-05 07:40:17 +01:00
sequencer.c type comparisons: fixes 2021-01-05 10:56:38 +00:00
service.c tls: handle WANT_WRITE via POLLOUT to POLLIN 2021-09-02 16:43:18 +01:00
socks5-client.c socks5: cast for mingw3 nonposix recv args 2021-07-08 15:24:15 +01:00
sorted-usec-list.c logs: more internal conversion to log_cx 2021-07-01 05:20:53 +01:00
state.c logs: log contexts 2021-07-01 05:20:53 +01:00
transport-mux-client.c sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
transport-mux-common.c sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
transport-mux-proxy.c sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
vhost.c sspc: refactor to allow different transports 2021-10-08 09:48:41 +01:00
wsi-timeout.c validity: take context and pt lock before close 2021-08-31 05:45:40 +01:00
wsi.c h2: make has_buffered_out check nwsi 2021-09-13 15:15:31 +01:00

Implementation background

Client connection Queueing

By default lws treats each client connection as completely separate, and each is made from scratch with its own network connection independently.

If the user code sets the LCCSCF_PIPELINE bit on info.ssl_connection when creating the client connection though, lws attempts to optimize multiple client connections to the same place by sharing any existing connection and its tls tunnel where possible.

There are two basic approaches, for h1 additional connections of the same type and endpoint basically queue on a leader and happen sequentially.

For muxed protocols like h2, they may also queue if the initial connection is not up yet, but subsequently the will all join the existing connection simultaneously "broadside".

h1 queueing

The initial wsi to start the network connection becomes the "leader" that subsequent connection attempts will queue against. Each vhost has a dll2_owner wsi->dll_cli_active_conns_owner that "leaders" who are actually making network connections themselves can register on as "active client connections".

Other client wsi being created who find there is already a leader on the active client connection list for the vhost, can join their dll2 wsi->dll2_cli_txn_queue to the leader's wsi->dll2_cli_txn_queue_owner to "queue" on the leader.

The user code does not know which wsi was first or is queued, it just waits for stuff to happen the same either way.

When the "leader" wsi connects, it performs its client transaction as normal, and at the end arrives at lws_http_transaction_completed_client(). Here, it calls through to the lws_mux _lws_generic_transaction_completed_active_conn() helper. This helper sees if anything else is queued, and if so, migrates assets like the SSL *, the socket fd, and any remaining queue from the original leader to the head of the list, which replaces the old leader as the "active client connection" any subsequent connects would queue on.

It has to be done this way so that user code which may know each client wsi by its wsi, or have marked it with an opaque_user_data pointer, is getting its specific request handled by the wsi it expects it to be handled by.

A side effect of this, and in order to be able to handle POSTs cleanly, lws does not attempt to send the headers for the next queued child before the previous child has finished.

The process of moving the SSL context and fd etc between the queued wsi continues until the queue is all handled.

muxed protocol queueing and stream binding

h2 connections act the same as h1 before the initial connection has been made, but once it is made all the queued connections join the network connection as child mux streams immediately, "broadside", binding the stream to the existing network connection.