Commit graph

5103 commits

Author SHA1 Message Date
Jan Holesovsky
205a1453d3 nb: Moved the WebSocketHandler to an own header & cpp.
The cpp is there to keep the header free from the POCO dependency.

Change-Id: I2202c4ed403084ec1ed40001e10b1ec4fc226f7b
2017-03-10 10:47:39 +01:00
Jan Holesovsky
a2d457d778 nb: Abstract WebSocketHandler.
We don't need a special "WebSocket" class, as websocket itself is just an
upgrade of an existing socket / connection, and trying to come up with a
concept where a Socket class magically upgrades to a WebSocket class would be
messy.

So let's have just a WebSocketHandler, that communicates over a StreamSocket
or SslStreamSocket, and be done with that :-)

Change-Id: I449e4d662fbe2c5b1789e308053e4a71376fe481
2017-03-10 10:47:39 +01:00
Jan Holesovsky
18876119ad nb: SimpleResponseClient is a client, not a socket I guess.
Introduce the appropriate interface instead of the template, so that we can
de-couple the ResponseClient from the Socket itself.

Change-Id: I21892bbce5d83a18ca580a25cfc2efbb05b08705
2017-03-10 10:47:39 +01:00
Jan Holesovsky
72666d5625 nb: Let's avoid too much abstraction.
Change-Id: If349e6273580b09386ad0a89467a99c6c2c0d4ec
2017-03-10 10:47:39 +01:00
Ashod Nakashian
69e4123173 nb: de-templatize ServerSocket
Change-Id: I5680bbf24ade807e34f67f7fce4698ffe5364cb2
2017-03-10 10:47:39 +01:00
Ashod Nakashian
9c595755ff nb: move SslStreamSocket to own file
Change-Id: I4b6f2b0b4be3fc595dfeafc8e2b6d3e73694bd49
2017-03-10 10:47:39 +01:00
Ashod Nakashian
18b131f30d nb: more consistent filenames
Change-Id: I2f1ff0b18080d469dc68b75ea0d7b9ddf5ea7d57
2017-03-10 10:47:39 +01:00
Ashod Nakashian
393071573b nb: write while output buffer not empty
Change-Id: I257b72365b4711fd7ffc8bbda5a21d501828575b
2017-03-10 10:47:39 +01:00
Ashod Nakashian
cff706861f nb: failing to drain the wakeup pipe is no error
Change-Id: Ie7a75f96b655cb7861d1bae539d78cbf702cf334
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fafd8a370e nb: throw when we run out of resources
Change-Id: I12fd236bffd50dbf7a1bb9eb4c665ea9d9d545e4
2017-03-10 10:47:38 +01:00
Ashod Nakashian
ab82db72ee nb: read to the end of the full buffer
Change-Id: I94264f748ac974f636ab6d21a5ccbb77532136f6
2017-03-10 10:47:38 +01:00
Ashod Nakashian
c37079fcee nb: assert on trying to write empty data
Change-Id: Ie18b5d00acf769a112b47d45f8c7783fb5746acf
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b72dd13cb0 nb: fixme for HTTP handling
Change-Id: I4364e2e4cd3233134c026890ce690abaf46b961d
2017-03-10 10:47:38 +01:00
Ashod Nakashian
28bfb5547b nb: comment to replace ConsoleCertificateHandler
ConsoleCertificateHandler will block on stdin
when a certificate error occures. This is hardly
helpful to users. Although in a server environment
this is likely to go to the journal, we should
properly log it and shutdown, rather than hang
waiting for the unlikely console input.

Change-Id: I54bb38ec60f443c579ef20dbb759941fae182e5b
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fa97687485 nb: safer endianness conversion
Change-Id: I63977e6e99119fef2a61911d07d645a606d4c443
2017-03-10 10:47:38 +01:00
Michael Meeks
86185a2544 Restore plain HTTP, and add 'ssl' parameter to loolnb. 2017-03-10 10:47:38 +01:00
Ashod Nakashian
bb5f3b5c98 nb: properly shutdown and cleanup SSL
Change-Id: Idd39851775e16c62d6192e08c9058cd9fb40104f
Reviewed-on: https://gerrit.libreoffice.org/34454
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
a8f5923214 nb: cleanup some logging
Change-Id: I28e211e5a727ea308824651f417a91d7b388a30d
Reviewed-on: https://gerrit.libreoffice.org/34452
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
031ee124da nb: use 16kb socket read buffer to match SSL
SSL's decryption frame is 16kb, so it
makes sense to read by that multiple
for efficiency reasons.

Change-Id: Ib5d7b5bfc18fa1b27bcbc9aac93350c4e1292874
Reviewed-on: https://gerrit.libreoffice.org/34451
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
1db8884f60 nb: support websocket payloads larger than 64kb
Change-Id: Ic21e11a70dae74b80ce3b1b604159ec14851972c
Reviewed-on: https://gerrit.libreoffice.org/34450
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
7a904d44bc nb: http request is consumed completely
Change-Id: I3525840deaf3ec95b8e74634ac36f22072bdf476
Reviewed-on: https://gerrit.libreoffice.org/34449
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
7f41627d52 nb: improved poll handler
We now always read new data, because
SSL might need to process internal buffers,
and call the app message handler as long
as it keeps consuming data.

Finally, we write when we have data
to flush, even if we didn't get POLLOUT
event, because SSL might need to do
handshake, which is handled by the write
handler.

Change-Id: I909333c3a0492b0830044d51ae478ac5981b1d90
Reviewed-on: https://gerrit.libreoffice.org/34448
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
a0df079c9b nb: flush all write data as long as we make progress
Change-Id: I138c54258eb54570e7a583bb62b1f4d26ef70ef1
Reviewed-on: https://gerrit.libreoffice.org/34447
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
11c7a213d6 nb: retry reading only when the buffer is full
We expect to have more data if the buffer was
filled completely. Otherwise, there is no
reason to suspect there is more data, unless
we hope to have received time in that short
interval, which is not very likely.

Change-Id: I9a3dcb6378e8dcfa0d49b6c7ea92d7cec6690787
Reviewed-on: https://gerrit.libreoffice.org/34446
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
eb76fc2d4f nb: the last item in the read buffer is sentinel
Change-Id: I13d80a8d436c188dbfa558ddf8fbc7c1a3a6567e
Reviewed-on: https://gerrit.libreoffice.org/34444
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
6a46571455 nb: handle as many incoming messages as ready
Change-Id: I082f4a8b86b1f1827e4fba6927248bc6bd2cb1fa
Reviewed-on: https://gerrit.libreoffice.org/34443
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b6943b9c2a nb: server socket should accept only on POLLIN
Change-Id: I50e9a7f78e51bbf7e42e3eafde6e32d6538f5657
Reviewed-on: https://gerrit.libreoffice.org/34442
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fe5545d591 nb: websocket echo test
The new test sends data of of 1 byte to
N bytes and expects the exact same data
returned in response.

This tests both buffering sizes and
websocket frames.

Change-Id: Ic6232b4e899d82d90a0ee7c96e4852ffaaf8e958
Reviewed-on: https://gerrit.libreoffice.org/34441
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
f8efd03d99 nb: allow moving write buffer
SSL expects the write buffer to be the same on
retry. This requirement cannot be guaranteed
when using standard containers as the internal
memory might be re-allocated between calls.

Luckily SSL can relax this requirement when asked.

Change-Id: I26771609a8cc0f9de0e554f9fa255d998f6c7b14
Reviewed-on: https://gerrit.libreoffice.org/34440
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b4ab8f2014 nb: unmask only to the payload end
Change-Id: I511db5fea51ff8c623ca894f9d512749ef9f5a1b
Reviewed-on: https://gerrit.libreoffice.org/34424
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
9d95eec642 nb: support 64kb websocket messages
Change-Id: Id42efabb67137c737899adbe544cb0d2de08422a
Reviewed-on: https://gerrit.libreoffice.org/34423
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
e2d5d446b1 nb: refactor and reuse ssl handshake handler
Change-Id: Ie65b7d1bac8391ccb2905fa8376a26ee4c3d4e30
Reviewed-on: https://gerrit.libreoffice.org/34416
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
25e00d8d75 nb: reuse buffered reading and writing in SSL too
Change-Id: I3f835bc9ae4ed6c093b87ac5a45c9dd6b41780f9
Reviewed-on: https://gerrit.libreoffice.org/34415
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
336c3340f4 nb: move more into BufferingSocket
Reduces code duplication and makes
buffer management easier.

Change-Id: I4f3bcf02b273d7ae23f4fd7600e66644ccec0d2a
Reviewed-on: https://gerrit.libreoffice.org/34414
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
22f365abbe nb: move handleIncomingMessage to BufferingSocket
Change-Id: Iddcac9a9ca51f060e32b8f2600518e4a7cea98d2
Reviewed-on: https://gerrit.libreoffice.org/34413
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
bb2be404d2 nb: refactor getResponse into raw string and int versions
Change-Id: I77d8085cc811c7caf4434af823e62fd1333090f1
Reviewed-on: https://gerrit.libreoffice.org/34412
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
31dd434136 nb: drain the read buffer before dispatching
Draining the buffer is the correct appraoch
to avoid accumulating data in the kernel
unnecessarily. But it also reduces the overhead
of reparsing the incoming data for message
boundaries.

The client that is to parse the data should
parse as many messages as possible and remove
them from the socket buffer.

Finally, we probably need to cap the maximum
buffer size to avoid bloating. However this
heavily depends on the application's max
message size, assuming there is no separate
buffer beyond that of the socket to accumulate
the messages in.

Change-Id: I49c4eccebd474cd07ca84f3f4eae33bc717ed1f2
Reviewed-on: https://gerrit.libreoffice.org/34411
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
d9f4903ec3 nb: cosmetics
Change-Id: I3a9f95c0b8edacff69b3c3733e833e3a82c545a9
Reviewed-on: https://gerrit.libreoffice.org/34410
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Michael Meeks
783cd72f1b SSL - accept self-signed certificates for tests. 2017-03-10 10:47:37 +01:00
Michael Meeks
1f79a93476 Socket - set nodelay. 2017-03-10 10:47:37 +01:00
Ashod Nakashian
4fbc754b4e nb: enable HTTPS in server
Change-Id: Ib0a4cb29f239bafe477ffab4194d3c91a588c384
2017-03-10 10:47:37 +01:00
Ashod Nakashian
9f0c1a4ec3 nb: support ssl handshake
Change-Id: I9974b1228cdc35a22ee784b734811720ddd2a311
2017-03-10 10:47:37 +01:00
Ashod Nakashian
e30998e47e nb: support ssl in all client tests
Change-Id: Ie077212426a07817914abe796c1280ef2afe89be
2017-03-10 10:47:37 +01:00
Michael Meeks
bc8fca1ec0 WS: cleanup calculation, masking, short reads and other bits. 2017-03-10 10:47:37 +01:00
Ashod Nakashian
936b3e5736 nb: basic SSL socket implementation
Change-Id: Iaa2da47df17f14dfded44a8cf805020e8ef6b1ff
Reviewed-on: https://gerrit.libreoffice.org/34395
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
b439490a11 nb: support SSL in clientnb
Change-Id: Ia895558c7115a39824474ba7acff060102192c10
Reviewed-on: https://gerrit.libreoffice.org/34394
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
de10d8054c nb: SimpleResponseClient can now be an SSL or plain socket
Depending on the base class, which is passed as
template parameter, SimpleResponseClient can
abstract away the underlying socket type.

Change-Id: I59a403357512f329aa2565c1ef55094704e3b4ad
Reviewed-on: https://gerrit.libreoffice.org/34393
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
ff75e8fda2 nb: server can create any socket type on accept
Change-Id: I1a786421628500844277e6a2f1d2fd7b0ac0c3e4
Reviewed-on: https://gerrit.libreoffice.org/34392
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
477be66577 nb: support http and https in parallel
Change-Id: I35f55abc853e8797625bef1b0f60eeda127681b4
Reviewed-on: https://gerrit.libreoffice.org/34391
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
d39f86c73b nb: Enable partial writes and no retry
Change-Id: I75567754b81cc43190087bae4f848a0742201fe0
Reviewed-on: https://gerrit.libreoffice.org/34390
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00