Commit graph

1582 commits

Author SHA1 Message Date
Kim Alvefur
52178d7430 net.server_epoll: Make running out of buffer space a fatal error
Prevent Bad Things from happening when the buffer gets full.
This of course opens up the possibility of intentionally killing
connections by sending much stuff, which need to be mitigated with rate
limits elsewhere.
2024-11-09 15:42:31 +01:00
Kim Alvefur
693079c619 net.server_epoll: Improve efficiency of sending much buffered data
Problem: The string slice operations when a lot of data gets buffered
ends up being expensive and memory-consuming. We have util.dbuffer for
precisely this kind of thing.

I want to keep the behavior of writebuffer being upgraded from nil to a
string to full buffer since the last step involves three table
allocations, where the previous buffer method only used one. Avoiding
those allocations for simple writes like white space keep alive feels
like it would keep memory churn down.

This work was started in 2020
2024-11-09 00:37:15 +01:00
Kim Alvefur
73b512d3a6 util.error: Use is_error() instead of is_err() everywhere
Continuation of 4b39691a274e
2024-10-29 14:10:02 +01:00
Kim Alvefur
9327c4342a Merge 0.12->trunk 2024-08-16 17:06:41 +02:00
Kim Alvefur
4f7c829b1e net.http: Throw error if missing TLS context for HTTPS request
Prevents the mistake of creating a http context without any TLS context
and then trying to use HTTPS, which doesn't work right.

Thanks nils
2024-08-08 19:18:22 +02:00
Kim Alvefur
dd657746b4 util.sslconfig: Support DH parameters as literal string
Simplifies shipping well-known DH parameters in the config
2024-07-12 15:21:08 +02:00
Kim Alvefur
b522fd0e05 Merge 0.12->trunk 2024-07-07 18:40:25 +02:00
Kim Alvefur
ca417ab776 net.server_event: Add 'wrapserver' API
This enables accepting admin stream socket (UNIX) connections trough the
same procedures as any other (TCP) socket, which avoids problems caused
by using the wrapclient API, which ends up discarding early data due to
only expecting early connection failure.

Fixes #1867
2024-07-07 18:28:17 +02:00
Kim Alvefur
2647c56106 net.server_epoll: Add support for systemd socket activation
Allows creating listening sockets and accepting client connections
before Prosody starts.
This is unlike normal Prosody dynamic resource management, where ports
may added and removed at any time, and the ports defined by the config.

Weird things happen if these are closed (e.g. due to reload) so here we
prevent closing and ensure sockets are reused when opened again.
2024-05-14 17:07:47 +02:00
Kim Alvefur
f29bc1c119 net.unbound: Show canonical name in textual format (e.g. in shell)
libunbound does not tell us the whole chain of CNAMEs, only the final
canonical name.

This is to aid in debugging since it will only be shown in the shell.
2024-04-14 14:06:57 +02:00
Kim Alvefur
1d5021a663 net.server: Restore epoll signalfd handling
Reverts 4a9a69659727
2024-03-02 13:40:37 +01:00
Kim Alvefur
ed0188ce81 net.server: Disable epoll signalfd handling by default until problems resolved 2024-03-01 19:22:49 +01:00
Kim Alvefur
865df3d373 net.server_epoll: Log creation of signalfd handles at noise level
To aid in tracking down signalfd-related problems
2024-03-01 19:20:45 +01:00
Kim Alvefur
f1e07782ed net.server_epoll: Log failure to hook signals
To make any such failures noticeable
2024-02-28 22:24:09 +01:00
Kim Alvefur
3d2bad3d4b Merge 0.12->trunk 2024-02-27 17:15:36 +01:00
Kim Alvefur
f7b35d516f net.http.files: Validate argument to setup function
Fixes error in #1765 by throwing an error earlier
2024-02-27 17:14:16 +01:00
Kim Alvefur
761643abcc util.signal: Wrap signalfd in an userdatum for gc handling etc 2024-02-24 01:00:44 +01:00
Kim Alvefur
49c296360d net.server_epoll: Support hooking signals via signalfd
Handling signal events the same way as all other events makes sense and
seems safer than the signal handling just jumping around in C and
messing with Lua states.
2024-02-24 00:20:35 +01:00
Kim Alvefur
5764e73a65 net.server_epoll: Prevent traceback when checking TLS after connection gone
Unclear why this would be done, but an error is not great.
2024-01-21 22:59:50 +01:00
Kim Alvefur
674b91b82b net.http.parser: Reject overlarge header section earlier
This case would eventually be rejected by the buffer size limit.
2023-08-23 12:18:34 +02:00
Matthew Wild
87ee5a2300 net.http.parser: Fix off-by-one error in chunk parser 2023-02-17 17:01:19 +00:00
Matthew Wild
bc1e51eb83 net.http.server: Add new API to get HTTP request from a connection
This information is sometimes necessary in the context where we have a
connection that we know (or believe to be) associated with an incoming HTTP
request.

For example, it can be used to retrieve the IP address of a request (which may
differ from the IP address of the connection, due to X-Forwarded-For and co).

Thanks to the Jitsi team for highlighting this gap in the API.
2023-02-16 15:59:26 +00:00
Matthew Wild
0fd88a07a4 net.http.parser: Improve handling of responses without content-length
This ensures that we support responses without a content-length header, and
allow streaming them through the streaming handler interface. An example of
such a response would be Server-Sent Events streams.
2023-02-09 22:57:32 +00:00
Matthew Wild
28e3b19ca1 net.http: Add missing log parameter 2023-02-09 22:37:54 +00:00
Kim Alvefur
fe97c773a6 net.http.server: Fix #1789
Unregistering the response before sending the trailer of the chunked
transfer encoding prevents opportunistic writes from being invoked and
running this code again when, which may cause an error when closing the
file handle a second time.

Normally the file size is known, so no chuck headers are sent.
2023-01-08 13:35:04 +01:00
Kim Alvefur
4f3ba05b4d net.unbound: Merge luaunbound and prosody defaults in absence of user config (fixes #1763) (thanks rgd)
add_defaults() is supposed to merge 3 tables, the defaults in
luaunbound, the defaults from prosody and any config from the prosody
config file.  In the case where no `unbound={}` has been in the config,
it skips over the merge and returns only the prosody built-in defaults.

This results in libunbound skipping reading resolv.conf and uses its
default behavior of full recursive resolution.

Prior to #1737 there were only two tables, the luaunbound defaults and
the prosody config, where bypassing the merge and returning the former
did the right thing.
2022-06-19 19:49:32 +02:00
Kim Alvefur
24288146ae net.unbound: Adjust log level of error to error to error
This error is an error, therefore it should be at the error level
2022-05-16 14:51:01 +02:00
Kim Alvefur
5e95ed633a net.unbound: Disable use of hosts file by default (fixes #1737)
This mirrors the behaviour with net.dns and avoids the initialization
issue in #1737
2022-05-16 12:45:51 +02:00
Kim Alvefur
43351d2b54 Spelling: Fix various spelling mistakes (thanks timeless)
Words, sometimes I wonder how they even work

Maybe I missed something.
2022-03-07 00:13:56 +01:00
Kim Alvefur
ece896d253 net.websocket.frames: Replace bit fiddling code with util.struct
Fallback code for not having either the string.pack and string.unpack
functions available in Lua 5.4 or the struct lib is no longer needed
since the struct lib was imported as util.struct in 3ce3633527af
2022-03-06 15:13:50 +01:00
Matthew Wild
fa68985f24 net.stun: Support for xor-relayed-address attribute 2022-03-05 11:30:55 +00:00
Matthew Wild
d405c11918 net.stun: Add xor-peer-address helper 2022-03-05 11:04:25 +00:00
Matthew Wild
ac06bd8c97 net.stun: Factor out address unpack, an operation common to multiple attributes 2022-03-05 11:03:44 +00:00
Matthew Wild
6e9d71259c net.stun: Name some more attributes from TURN 2022-03-05 11:00:08 +00:00
Matthew Wild
ab77f7fcdb net.stun: Add lookup table generation helper, reduces code duplication 2022-03-05 10:59:19 +00:00
Matthew Wild
572bff0087 net.stun: Hyphenate method names for consistency 2022-03-05 10:57:47 +00:00
Kim Alvefur
7579bee6bb net.stun: Use util.bitcompat to deal with bit module variances across Lua versions 2022-03-04 16:58:28 +01:00
Kim Alvefur
1f257ecbb4 net.stun: Use util.strbitop
Improves performance since the whole procedure is done in C
2022-03-04 16:55:32 +01:00
Kim Alvefur
a26b39e1b7 net.http.server: Fix whitespace-ignoring syntax 2023-12-01 22:00:18 +01:00
Kim Alvefur
6187c44ca9 Merge 0.12->trunk 2023-12-01 17:11:19 +01:00
Matthew Wild
5cfe0d220d net.stun: New library that implements STUN/TURN parsing/serialization 2022-03-04 15:23:32 +00:00
Kim Alvefur
9fbf5bf7ad net.server_epoll: Disable verbose mode by default 2022-02-12 18:47:22 +01:00
Kim Alvefur
c41d63004a net.http.server: Complete async waiter for non-persistent connections
Otherwise requests with Connection: close would be stuck in the async
wait that starts after the handle_request() call.

Together with the new async debugging, this makes the async thread stay
in the set of waiting runners forever, where previously it would simply
be garbage collected.
2023-11-24 00:31:08 +01:00
Kim Alvefur
07d2f9f2e8 net.server_epoll: Avoid call to update socket watch flags when nothing changed
Should skip a syscall for each write when using epoll.
2023-11-21 22:06:28 +01:00
Kim Alvefur
019549e738 net.http: Set Connection header based on connection pool usage
Connection: keep-alive is implicit in HTTP/1.1 but explicit > implicit
2023-11-11 23:48:45 +01:00
Kim Alvefur
8e2ecac95b net.http: Add simple connection pooling
This should speed up repeated requests to the same site by keeping their
connections around and sending more requests on them.

Sending multiple requests at the same time is not supported, instead a
request started while another to the same authority is in progress would
open a new one and the first one to complete would go back in the pool.
This could be investigated in the future.

Some http servers limit the number of requests per connection and this
is not tested and could cause one request to fail, but hopefully it will
close the connection and prevent it from being reused.
2023-11-11 23:08:34 +01:00
Kim Alvefur
adfd306e6e net.http.server: Fix typo in previous commit 2023-09-23 15:48:21 +02:00
Kim Alvefur
e1128dbdbc net.http.server: Support setting Content-Type of uncaught HTTP errors
mod_http_errors normally sets the Content-Type header via the response
object, which isn't available when handling these uncaught errors.

Without a Content-Type header the browser is forced to guess, which may
or may not result in something sensible.
2023-09-22 01:47:21 +02:00
Kim Alvefur
6ac58a4d1c net.websocket.frames: Remove completed TODO
The XOR is done in C since 4e5a2af9dd19
2023-07-29 01:42:19 +02:00
Kim Alvefur
c468bd12c9 net.server: Handle loading from outside Prosody (e.g. Verse)
server_select only depending on LuaSocket generally makes it more
portable, so fall back to that if util.poll can't be found.
2023-05-20 20:44:20 +02:00