aboutsummaryrefslogtreecommitdiffstats
path: root/net
Commit message (Collapse)AuthorAgeFilesLines
...
* | net.server_epoll: Try to make port number related methods saneKim Alvefur2021-09-121-7/+11
| | | | | | | | | | | | | | | | | | Previously it was unclear whether "client port" was the port that the client connected to, or from. I hereby declare that the client port is the source port and the server port is the destination port. Incoming and outgoing connections can be distinguished by looking at the_server reference, which only incoming connections have.
* | net.server_select: Deprecate and warn about itKim Alvefur2021-09-031-0/+2
| | | | | | | | | | | | | | | | | | To be removed in the future, but not right now. Give the log warning a chance to prod anyone who might have network_backend="select" in their config first. There's also things built on Verse which uses server_select.lua, which will need to be updated somehow.
* | net.server: Pikc server_epoll as unconditional defaultKim Alvefur2021-09-031-2/+1
| | | | | | | | | | | | | | Previously it would have gone for server_select if util.poll was for some reason not available, which should be never these days. And even if it was, best to flush it out by throwing loud errors so users notice. Then they can work around it by using select until we delete that one.
* | net.server: Fall back to default backend from libevent instead of always selectKim Alvefur2021-09-031-2/+2
| | | | | | | | | | | | | | | | Fixes that selecting libevent when unavaibalbe would fall back to select instead of epoll, even if that's available. This way, we only have to update it in once place when choosing a new default.
* | net.server_epoll: Prevent removed timers from being readdedKim Alvefur2021-08-311-2/+12
| | | | | | | | | | | | | | | | | | In a case like this the timer would not be readded: addtimer(1, function(t, id) stop(id) return 1 end);
* | Merge 0.11->trunkKim Alvefur2021-08-311-29/+29
|\|
| * net.server_epoll: Fix to preserve ids of readded timersKim Alvefur2021-08-311-2/+2
| | | | | | | | | | | | | | Likely affected rescheduling but have no reports of this. After readding a timer, it would have been issued a new id. Rescheduling would use the previous id, thus not working.
* | net.http: fail open if surrounding code does not configure TLSJonas Schäfer2021-08-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | Previously, if surrounding code was not configuring the TLS context used default in net.http, it would not validate certificates at all. This is not a security issue with prosody, because prosody updates the context with `verify = "peer"` as well as paths to CA certificates in util.startup.init_http_client. Nevertheless... Let's not leave this pitfall out there in the open.
* | net.server_epoll: Split, attempt to clarify dirty noise messageKim Alvefur2021-08-161-1/+2
| | | | | | | | | | | | Only relevant because a "dirty" connection (with incoming data in LuaSocket's buffer) does not count as "readable" according to epoll, so special care needs to be taken to keep on processing it.
* | net.server: Add a predrain callaback just before writesKim Alvefur2021-08-163-0/+11
| | | | | | | | | | | | | | | | | | | | Allows sneaking in things in the write buffer just before it's sent to the network stack. For example ack requests, compression flushes or other things that make sense to send after stanzas or other things. This ensures any additional trailing data sent is included in the same write, and possibly the same TCP packet. Other methods used such as timers or nextTick might not have the same effect as it depends on scheduling.
* | net.server_epoll: Improve efficiency of opportunistic writesKim Alvefur2021-08-141-1/+3
| | | | | | | | | | | | | | | | | | Should prevent further opportunistic write attempts after the kernel buffers are full and stops accepting writes. When combined with `keep_buffers = false` it should stop it from repeatedly recreating the buffer table and concatenating it back into a string when there's a lot to write.
* | Fix various spelling errors (thanks codespell)Kim Alvefur2021-07-271-1/+1
| | | | | | | | | | Also special thanks to timeless, for wordlessly reminding me to check for typos.
* | net.resolvers.service: Only do DANE with secure SRV recordsKim Alvefur2021-07-181-0/+4
| | | | | | | | | | | | If this seems backwards, that' because it is but the API isn't really designed to easily pass along details from each resolution step onto the next.
* | Revert 926d53af9a7a: Restore DANE supportKim Alvefur2021-07-181-4/+5
| | | | | | | | | | Previous commit adds a workaround, so this doesn't mutate global state anymore, only per-connection 'extra' state as originally intended.
* | net.server_epoll: Fix traceback-causing typoKim Alvefur2021-07-181-1/+1
| | | | | | | | | | | | | | Caused "attempt to index a string value (local 'data')", but only if keep_buffers is set to false, which is not the default. Introduced in 917eca7be82b
* | net.server_epoll: Ensure timeouts match epoll flagsKim Alvefur2021-07-171-0/+6
| | | | | | | | | | Read and write timeouts should usually match whether we want to read or write.
* | net.server_epoll: Skip reset of read timeout when not readingKim Alvefur2021-07-171-1/+2
| | | | | | | | Should avoid rare but needless timer interactions
* | net.server_epoll: Reduce timer churn during TLS handshakeKim Alvefur2021-07-171-1/+1
| | | | | | | | | | Instead of removing and readding the timer, keep it and adjust it instead. Should reduce garbage production a bit.
* | net.server_epoll: Use only fatal "write" timeout during TLS negotiationKim Alvefur2021-07-161-3/+3
| | | | | | | | | | | | | | Only real difference between the read and write timeouts is that the former has a callback that allows the higher levels to keep the connection alive, while hitting the later is immediately fatal. We want the later behavior for TLS negotiation.
* | net.server_epoll: Optimize concatenation of exactly 2 buffer chunksKim Alvefur2021-07-161-1/+3
| | | | | | | | | | | | Saves a function call. I forget if I measured this kind of thing but IIRC infix concatenation is faster than a function call up to some number of items, but let's stop at 2 here.
* | net.server_epoll: Avoid allocating a buffer table for single writesKim Alvefur2021-07-161-11/+20
| | | | | | | | | | | | | | writebuffer is now string | { string } Saves the allocation of a buffer table until the second write, which could be rare, especially with opportunistic writes.
* | net.server_epoll: Optionally let go of buffersKim Alvefur2021-07-161-5/+17
| | | | | | | | | | Reusing an already existing buffer table would reduce garbage, but keeping it while idle is a waste.
* | net.server_epoll: Propagate returns from opportunistic writesKim Alvefur2021-07-161-3/+4
| | | | | | | | | | So that if a write ends up writing directly to the socket, it gets the actual return value
* | net.server_epoll: Set minimum wait time to 1ms, matching epollKim Alvefur2021-07-151-1/+1
| | | | | | | | | | | | | | | | | | | | A timeout value less than 0.001 gets turned into zero on the C side, so epoll_wait() returns instantly and essentially busy-loops up to 1ms, e.g. when a timer event ends up scheduled (0, 0.001)ms into the future. Unsure if this has much effect in practice, but it may waste a small amount of CPU time. How much would depend on how often this ends up happening and how fast the CPU gets trough main loop iterations.
* | net.server_epoll: Add setting for disabling the Nagle algorithmKim Alvefur2021-07-141-0/+6
| | | | | | | | Nagle increases latency and is the bane of all networking!
* | net.server_epoll: Support setting keepalive idle timeKim Alvefur2021-07-141-0/+3
| | | | | | | | | | | | | | Activated by setting config.tcp_keepalive to a number, in seconds. Defaults to 2h. Depends on LuaSocket support for this option.
* | net.server_epoll: Add way to enable TCP keeplives on all connectionsKim Alvefur2021-07-141-1/+6
| | | | | | | | | | | | In case one wishes to enable this for all connections, not just c2s (not Direct TLS ones, because LuaSec) and s2s. Unclear what use these are, since they kick in after 2 hours of idle time.
* | net.server_epoll: Add an (empty) method for setting socket optionsKim Alvefur2021-07-141-0/+6
| |
* | net.server_epoll: Log failures to set socket optionsKim Alvefur2021-07-141-2/+8
| | | | | | | | | | | | | | | | | | Good to know if it fails, especially since the return value doesn't seem to be checked anywhere. Since LuaSec-wrapped sockets don't expose the setoption method, this will likely show when mod_c2s tries to enable keepalives on direct tls connections.
* | net.server_epoll: Call onconnect immediately after TLS handshake completionKim Alvefur2021-07-131-1/+2
| | | | | | | | | | | | Skips a roundtrip through the main loop in case client-first data is available already, if not then :onreadable() will set the appropriate timeout.
* | net.server_epoll: Refactor immediate TLS handshake startKim Alvefur2021-07-131-6/+5
| |
* | net.server_epoll: Keep socket registered in epoll trough TLS wrappingKim Alvefur2021-07-131-2/+1
| | | | | | | | | | There's the theory that the socket isn't the same before/after wrap(), but since epoll operates on FD numbers this shouldn't matter.
* | net.server_epoll: Use TLS handshake timeout after initiating handshakeKim Alvefur2021-07-131-1/+3
| | | | | | | | The :init() method sets a different timeout than the TLS related methods.
* | net.server_epoll: Start TLS handshake immediately on newly accepted connectionsKim Alvefur2021-07-131-0/+1
| | | | | | | | | | | | Since TLS is a client-first protocol there is a chance that the ClientHello message is available already. TLS Fast Open and/or the TCP_DEFER_ACCEPT socket option would increase that chance.
* | net.server_epoll: Factor out TLS initialization into a methodKim Alvefur2021-07-131-45/+51
| | | | | | | | | | | | | | | | | | | | | | So there's :startls(), :inittls() and :tlshandshake() :starttls() prepares for plain -> TLS upgrade and ensures that the (unencrypted) write buffer is drained before proceeding. :inittls() wraps the connection and does things like SNI, DANE etc. :tlshandshake() steps the TLS negotiation forward until it completes
* | net.server_epoll: Fix typoKim Alvefur2021-07-131-1/+1
| |
* | net.server_epoll: Prevent stack overflow of opportunistic writesKim Alvefur2021-07-111-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | net.http.files serving a big enough file on a fast enough connection with opportunistic_writes enabled could trigger a stack overflow through repeatedly serving more data that immediately gets sent, draining the buffer and triggering more data to be sent. This also blocked the server on a single task until completion or an error. This change prevents nested opportunistic writes, which should prevent the stack overflow, at the cost of reduced download speed, but this is unlikely to be noticeable outside of Gbit networks. Speed at the cost of blocking other processing is not worth it, especially with the risk of stack overflow.
* | net.http: Send entire HTTP request header as one writeKim Alvefur2021-07-081-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When opportunistic writes are enabled this reduces the number of syscalls and TCP packets sent on the wire. Experiments with TCP Fast Open made this even more obvious. That table trick probably wasn't as efficient. Lua generates bytecode for a table with zero array slots and space for two entries in the hash part, plus code to set [2] and [4]. I didn't verify but I suspect it would have had to resize the table when setting [1] and [3], although probably only once. Concatenating the strings directly in Lua is easier to read and involves no extra table or function call.
* | net.server_epoll: Immediately attempt to read from newly accepted connectionsKim Alvefur2021-07-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This may speed up client-first protocols (e.g. XMPP, HTTP and TLS) when the first client data already arrived by the time we accept() it. If LuaSocket supported TCP_DEFER_ACCEPT we could use that to further increase the chance that there's already data to handle. In case no data has arrived, no harm should be done, :onreadable would simply set the read timeout and we'll get back to it once there is something to handle.
* | net.server_epoll: Separate handling of new incoming and outgoing connectionsKim Alvefur2021-07-081-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | The :init method is more suited for new outgoing connections, which is why it uses the connect_timeout setting. Depending on whether a newly accepted connection is to a Direct TLS port or not, it should be handled differently, and was already. The :starttls method sets up timeouts on its own, so the one set in :init was not needed. Newly accepted plain TCP connections don't need a write timeout set, a read timeout is enough.
* | net.server_epoll: Ensure timeout after closingKim Alvefur2020-10-311-0/+1
| | | | | | | | | | | | This should make sure that if there's data left to be written when closing a connection, there's also a timeout so that it doesn't wait forever.
* | net.server_epoll: Add missing method for changing TLS contextKim Alvefur2021-06-101-0/+4
| | | | | | | | | | Supported by the other net.server implementations already, but not used anywhere in Prosody.
* | net.server_epoll: Fix reporting of socket connect timeoutKim Alvefur2021-06-071-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the underlying TCP connection times out before the write timeout kicks in, end up here with err="timeout", which the following code treats as a minor issue. Then, due to epoll apparently returning the EPOLLOUT (writable) event too, we go on and try to write to the socket (commonly stream headers). This fails because the socket is closed, which becomes the error returned up the stack to the rest of Prosody. This also trips the 'onconnect' signal, which has effects on various things, such as the net.connect state machine. Probably undesirable effects. With this, we instead return "connection timeout", like server_event, and destroy the connection handle properly. And then nothing else happens because the connection has been destroyed.
* | net.http.server: Split out method for sending only the headerKim Alvefur2021-04-241-2/+7
| | | | | | | | | | Makes it easier to reuse, e.g. for SSE or websockets or other custom responses.
* | net.server_epoll: Remove unnecessary luacheck annotationsKim Alvefur2021-04-011-3/+3
| | | | | | | | | | Not sure why these were here to begin with, since it does use the 'self' argument and did so since they were added.
* | net.resolvers.basic: Fix completion condition when IPv6 is disabledKim Alvefur2021-03-151-0/+2
| | | | | | | | | | | | | | | | | | | | Fixes mistake introduced in 5a71f14ab77c that made it so this ready() newer got called and thus it would be stuck waiting for it. Looks like the kind of thing that could have been introduced by a merge or rebase. Thanks MattJ
* | net.resolvers.basic: Disable DANE for now, completely brokenKim Alvefur2021-03-031-5/+4
| | | | | | | | | | Turns out 'extra' is, at least for mod_s2s, the same table for *all* connections.
* | net.resolvers.basic: Don't enable DANE with zero TLSA recordsKim Alvefur2021-03-031-1/+1
| | | | | | | | Turns out it doesn't work with zero.
* | net.connect: Add DANE supportKim Alvefur2021-03-021-1/+26
| | | | | | | | | | | | Disabled DANE by default, since it needs extra steps to be useful. The built-in DNS stub resolver does not support DNSSEC so having DANE enabled by default only leads to an extra wasted DNS request.
* | net.server_epoll: Support for passing DANE TLSA data to LuaSec (0.8 needed)Kim Alvefur2019-09-291-0/+14
| |