Commit graph

706 commits

Author SHA1 Message Date
Luboš Luňák
897c5df270 make Socket use Buffer for input buffer too
SteamSocket::eraseFirstInputBytes() removes from the beginning
of std::vector, which is generally slow. If the buffer becomes
too big, which it may under a load, then the function will get
slow, which in turn will likely lead to the buffer getting even
bigger because of accumulated backlog.

The Buffer class is optimized for removal at the beginning,
so use it instead of std::vector, including some API additions
for it to be an in-place replacement where it's used.

Signed-off-by: Luboš Luňák <l.lunak@collabora.com>
Change-Id: I4cf7ec56c908c7d3df391dc3f8e230ad32abb162
2021-10-26 12:11:58 +02:00
Michael Meeks
72f8f5d30e stress: store and dump some statistics.
Change-Id: Ied5eb12888b1466c155ecfd291785a95ea897db9
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-10-02 21:24:15 +01:00
Ashod Nakashian
347fd43f7c wsd: chunked transfer and tests
Change-Id: I07f7f126891f4d6b5137b45bf91cbcaa11796cda
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 866cb8f2f25e958f834adc51e2191fb60e2e85b9)
2021-09-26 17:02:01 -04:00
Ashod Nakashian
9e5043db47 wsd: http: reason phrase is optional
Change-Id: I1bd402b26081a8ff35178c836a5eaa22fd47d033
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 0134e3329c8ea9cd6793fb125585e289b2082cf0)
2021-09-26 17:02:01 -04:00
Szymon Kłos
e457aa8b4e Don't try to set empty hostname for SNI
to reduce logging warnings

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I9e1dcb16489f4cec692028b86d377ae776ac44e4
2021-09-15 09:34:56 +02:00
Ashod Nakashian
24acdaf89b wsd: throw when an invalid URL is used to create an http session
Change-Id: I2d2eb90badf4f02ec4f2e4c4071fc76b23a92928
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit c16ad4447004a72226df7761fb377014c242ea4e)
2021-09-13 09:40:09 -04:00
Tor Lillqvist
ed5569da30 Handle poll results in SocketPoll in a round-robin order
We don't want to always start with the most recently added socket.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ic4b4bf6c19c5d119e6e6f9b398789a4c77b47a10
2021-08-21 15:30:18 +01:00
Michael Meeks
e0d7337877 Host: header don't append port for standard ports.
HA Proxy doesn't tolerate this very happily cf.

https: //serverfault.com/questions/502443/ignore-port-numbers-in-haproxy-host-header-matches/502630
Change-Id: Id285f8acd0e168a734cabd9eccc4a01fe323ab84
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-08-13 09:36:27 +05:30
Gleb Popov
20c2ab5663 Remove non-abstract unix socket files on shutdown.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I54773de6d4f777f9188921d5aa99c052f0f79b34
2021-07-31 07:43:45 +03:00
Gleb Popov
950a5c4d1a Use more sensible value for #ifdef when checking for abstract unix sockets.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Icfd849424659c8949f8f3554aa75a8a7ceaf7ac2
2021-07-31 07:43:45 +03:00
Gleb Popov
0dd30ba28f Remove unused private class member.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I38b29c06220d2493dc9d47a0ac9b077e3bafd512
2021-07-30 16:43:29 +03:00
Szymon Kłos
541f6a76d3 ssl: setup hostname for SNI
For some servers we receive failure with HTTP 403 Forbidden in WOPI::CheckFileInfo

"Reason: The client software did not provide a hostname using Server
Name Indication (SNI), which is required to access this server"

fixes #2771 : https://github.com/CollaboraOnline/online/issues/2771

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I761b179580481f8882a4526c1d8be4f1c14ad929
2021-07-22 12:40:05 +02:00
Gopi Krishna Menon
b3d5a2563c Add profilezone around kitPoll function and SocketPoll constructor
Add profile zone around kitPoll function and SocketPoll constructor to
improve trace event generation

Signed-off-by: Gopi Krishna Menon <krishnagopi487.github@outlook.com>
Change-Id: Ia46e9add59a57935997649fe39861a8d851e1ff0
2021-07-21 15:00:31 +03:00
Tor Lillqvist
8b6ee5b8bf No need for the template class MessageQueueBase
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ie007344f9a0ffe7fdf767cb9e9069db99aa224b9
2021-07-21 09:54:28 +03:00
Ashod Nakashian
4c87cc36ff wsd: Close socket hard when necessary
Also clear its input buffer explicitly.

Change-Id: I8badbb96d98eaf10433a65fcfd13b0d6d5893594
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>

Ignore input in a somewhat gentler way.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I758302dc3bb1aa87f9fbfa726f73f4b9339e08c2
2021-07-19 17:31:55 +01:00
Miklos Vajna
18d4c58442 http response: if the result doesn't fit, then consider that a fatal error
This is really a garbage in -> garbage out situation.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ic1c33f44081f259e5cf5994ad901e1593fe8dfcf
2021-07-19 13:38:00 +02:00
Miklos Vajna
32a654eecb http response: simplify the condition if the result would fit
Given that "digit" is always less than 16, we can avoid the "- digit"
in the condition (because the division turns that into 0 anyway), making
it effectively constexpr.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Iaf9e53d3543f2237c00768f214114a02a4746020
2021-07-19 12:42:38 +02:00
Ashod Nakashian
0d59630b48 wsd: killpoco: cert verification
Change-Id: Ie9bc96183d1e416ef4b9b455eefb1f9249b2f695
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f63d077916 wsd: ssl certificate verification requirements
Change-Id: I72ffa586310296f1986276c3007672c41146c92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f702c4efab wsd: support certificate verification
Change-Id: I912595f104e24dc66da9cf06bc211cb0c50c9ff0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
0690f23ee4 wsd: move isLocalhost to a common area
Change-Id: I2a7986863138a254a6d74644112f5cd60bb898cd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Miklos Vajna
57d3d0f391 http response: check if result would fit into chunkLen
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I6e3b73461653d2ab3cedaa3f6ca7fbfd2a826edb
2021-07-08 14:51:11 +02:00
Dennis Francis
7e9b038ded net: show call-site file/line for assertCorrect...
...Thread.

Conflicts:
	net/Socket.hpp
	net/SslSocket.hpp

Signed-off-by: Dennis Francis <dennis.francis@collabora.com>
Change-Id: I92b8f4b52e7bd60b69305c1916eed8a14a4c1560
2021-07-02 16:48:46 +05:30
Michael Meeks
e289597315 Add a processtoidle event implementation.
This can be used to accelerate unit tests by allowing us to ensure
that all pending work is done between a 'processtoidle' message being
sent and an 'idle' being returned. This can be much faster than waiting
a defined length of time.

Change-Id: I6d96de205d1fd34a22e0ddbd2709bf806a97b33c
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-29 17:12:01 +01:00
Ashod Nakashian
5a310a2232 wsd: separate client SSL context from the server
Change-Id: I4d86f733a16e6c76340b18ff836831ebe6acfd4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-23 23:39:34 -04:00
Ashod Nakashian
a9e650a8db wsd: separate the SSL locks from the context
Change-Id: I2b1742054d5cec16ae3cf90e2098de40eeade4a8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-23 23:39:34 -04:00
Ashod Nakashian
485a716268 wsd: http: handle invalid http versions
We currently only recognize HTTP/x.y. Anything
else is invalid.

Change-Id: I45fa7e33052e3847b8a2d9768b12d8eac43f6b0a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-19 17:44:59 -04:00
Ashod Nakashian
823f349383 wsd: http: break cyclic dependency
The Socket instance owns the protocol handler
by design. This implies that the Session,
which is also the protocol handler, cannot
itself own the Socket.

Here we change that ownership into a weak_ptr
and pass the exclusive ownership of the Socket
to SocketPoll. We track the connection state,
so we can create a new socket when we are
disconnected.

Change-Id: Id6bf6506b0c8e2e0564f91977e1e7189d934a68f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-14 23:02:39 -04:00
Ashod Nakashian
7b32b96a08 wsd: http: better logs
Change-Id: I790308c872ca9c20c4b29a04deae19059ca36818
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
3891f89bff wsd: http: better logging of errors
Change-Id: Ifbf199051eeec20f2d273d777df5befca131f433
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
7ef411b8f3 wsd: disable socket traffic logging
Change-Id: I9cfe758c9b74e534152c69fa5c0e612a068209f5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Ashod Nakashian
c5a4e106b1 wsd: http: do not set the state explicitly on parsing error
Setting the state to Error in the parser has the
unwanted side-effect of not triggering the proper
callbacks. The better design is to observe the API
and return error (-1) upon hitting parsing errors.
The caller will then invoke the finishing function
that sets the state and triggers the callbacks.

Change-Id: I4957b0fb431f477d71fb21a8dd601d132c3d6a21
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
74e575de4b wsd: http: always destroy the socket last
When the socket is destroyed, it may invoke
the onDisconnect handler, which updates
the Response instance. If the order of
destruction is incorrect, we may have
a null instance.

Also make the State atomic to make sure
its visibility is consistent across threads.
The shared_ptr instances will fence and will
always be consistently visible across threads,
but if the State isn't in sync, then we can
seem to have an inconsistent state. The State
instance will be set and accessed from different
threads in an async request.

Change-Id: Ia2a48285d140646f3640f59634e14a46e4a4d640
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
513e33582f wsd: http: an incomplete response is an error
If we haven't had a complete response or a timeout,
then we have an incomplete transmission, which is
an error.

Change-Id: I1b775760186021e0a704eba2c9f3647efa4f5ed0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
bbb4fe14ae wsd: http: sync requests accept external poller
Reusing a SocketPoll is encouraged rather than
creating throwaway instances. Session now supports
external SocketPoll instances for the sync members
as it does for the async (which is unavoidable).

Also, use TerminatingPoll to break the poll
when the terminating the process is flagged.

Change-Id: Ide6f674080ce20bb764c482871e48c94d83d4214
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
b8c3e97cc6 wsd: better handling of invalid port in URL
Detect invalid port values and error out.

Change-Id: If45bcacaf64f48356147aa5461bcd2e30b7c7ea1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Ashod Nakashian
dbf45e8641 wsd: http: performWrites can be called after destroying the socket
Change-Id: Ieb745a7706bf57c9bd16995e1f1336f7053ab30c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 12:10:24 -04:00
Michael Meeks
655493a7bc Transfer LOK callback processing into our main thread if necessary.
While we are processing data in the poll handler, we can have
another helpful thread from the core sending things to us:

loolforkit(Socket::assertCorrectThread(char const*, int))
loolforkit(WebSocketHandler::sendFrame(std::shared_ptr<StreamSocket> const&, char const*, unsigned long, unsigned char, bool) const)
loolforkit(WebSocketHandler::sendMessage(char const*, unsigned long, WSOpCode, bool) const)
loolforkit(Document::postMessage(char const*, int, WSOpCode) const)
loolforkit(Document::sendFrame(char const*, int, WSOpCode))
loolforkit(ChildSession::sendTextFrame(char const*, int))
loolforkit(ChildSession::loKitCallback(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))
loolforkit(Document::GlobalCallback(int, char const*, void*))
/core/instdir/program/libsofficeapp.so()
/core/instdir/program/../program/libfwklo.so()
/core/instdir/program/libscfiltlo.so()
/core/instdir/program/libexpwraplo.so()
/core/instdir/program/libooxlo.so(oox::core::FastParser::parseStream(com::sun::xml::sax::InputSource const&, bool))
/core/instdir/program/libooxlo.so(oox::core::FastParser::parseStream(com::sun::uno::Reference<com::sun::io::XInputStream> const&, rtl::OUString const&))
/core/instdir/program/libooxlo.so(oox::core::XmlFilterBase::importFragment(rtl::Reference<oox::core::FragmentHandler> const&, oox::core::FastParser&))
/core/instdir/program/libscfiltlo.so()
/core/instdir/program/libcomphelper.so(comphelper::ThreadTask::exec())
/core/instdir/program/libcomphelper.so()
/core/instdir/program/libuno_salhelpergcc3.so.3(salhelper::Thread::run())
/core/instdir/program/libuno_salhelpergcc3.so.3()
/core/instdir/program/libuno_sal.so.3()
/lib/x86_64-linux-gnu/libpthread.so.0()
/lib/x86_64-linux-gnu/libc.so.6(clone)

This is most likely from eg. threaded parsing of various file formats,
or progress messages while loading / saving, sent while the SolarMutex
is locked.

We assume that:
  + there will only ever be one thread running inside kitPoll
    this is enforced by vcl/headless.
  + and so, we can safely mutate SocketPoll and Socket buffer
    state from this thread.
  + there are only two entry points for callbacks from threads
    in core - which are both instrumented, and if necessary
    their work is shifted to this thread.

Memory corruptions matching the above trace, suggesting that
multiple writes have collided between kitPoll and an event
callback have been seen in the wild.

Change-Id: I5b084cbfec1ea326b6e17c9e5590a8c8e35b3854
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-11 14:19:55 +01:00
Tor Lillqvist
10b9766e03 Add commented-out TraceEvent::emitInstantEvent
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id573e8ff93f3a5914fef91b01802047881990dbf
2021-06-07 14:34:37 +03:00
Andras Timar
086b4f4fc0 Extend debug only if OpenSSL version > 1.1.0
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I6ba025786cd92388da1e16ddc0bb8c9a5ad56b21
2021-06-04 14:58:36 +01:00
Michael Meeks
b4f3adb8cd Extend debug.
Change-Id: I57bf42a0241d773041f792a2489011f90677254e
2021-06-04 14:58:36 +01:00
Michael Meeks
7ed4b4f7e7 Use larger write buffer size for UDS from kit -> wsd.
We send lots of large tile data this way, this should help
accelerate tile data transfer marginally.

Change-Id: I1deab7845c09dc65b1f44e9f9fc762f70ce94cc3
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-04 14:58:36 +01:00
Ashod Nakashian
aea70a563c wsd: http: disconnect if the server closed the socket
Change-Id: If00566939708d71482a8aac8e97cc371a4a381fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0696403a9 wsd: http: complete the http response only once
Change-Id: I2c015f004883272bb6efe4ffc5a14e3cc101f60f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Tor Lillqvist
739dfce08a There is no isManualDefrag parameter
Change-Id: I1a662dbdb2e43335f8739852e7797012de7be34a
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-05 15:22:00 +03:00
Tor Lillqvist
686f1ba1cb Make WebSocketHandler::_isClient const and drop default values for bool parms
Avoiding default values for parameters makes the code easier to read.
Especially true for bool parameters. But sure, just a question of
taste.

Change-Id: I473f70bdfafe3a9ccfb325def8760d78fee7e9a6
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-05 09:03:29 +03:00
merttumer
5742acd87c android: Fix build fail and crash on doc load
Signed-off-by: merttumer <mert.tumer@collabora.com>
Change-Id: Id998e2bdf7051d54784543015c7d34c0bdd64543
2021-05-02 21:47:37 -07:00
Ashod Nakashian
a0549fd7cc wsd: http: simplify http::get
Change-Id: Id94d2e7340b393bd4a42f5108621f16b46a0ee9b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
117db770cd wsd: http: add isConnected getter to http::Session
Change-Id: Iad12f00f9ced434d4e1493aba03be98a3cd7f2ab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
ea12aa7635 wsd: http: braces always on new line
Seems like this was a bug in clang-format
that is fixed in clang-12.

Change-Id: I8144179d2b290f5d875af41dbd44dedcf4152639
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00